Add modder facing API for Villager Career level trades. Ref: #2854

This commit is contained in:
LexManos 2016-05-14 20:11:55 -07:00
parent 5445f96327
commit d5b93bf262
2 changed files with 51 additions and 9 deletions

View file

@ -120,16 +120,24 @@
this.field_175562_bw = 1; this.field_175562_bw = 1;
} }
@@ -552,7 +596,7 @@ @@ -552,13 +596,11 @@
int i = this.field_175563_bv - 1; int i = this.field_175563_bv - 1;
int j = this.field_175562_bw - 1; int j = this.field_175562_bw - 1;
- EntityVillager.ITradeList[][] aentityvillager$itradelist1 = aentityvillager$itradelist[i]; - EntityVillager.ITradeList[][] aentityvillager$itradelist1 = aentityvillager$itradelist[i];
+ EntityVillager.ITradeList[][] aentityvillager$itradelist1 = this.getProfessionForge().getCareer(i).getTrades(); + java.util.List<EntityVillager.ITradeList> trades = this.getProfessionForge().getCareer(i).getTrades(j);
if (j >= 0 && j < aentityvillager$itradelist1.length) - if (j >= 0 && j < aentityvillager$itradelist1.length)
+ if (trades != null)
{ {
@@ -647,9 +691,14 @@ - EntityVillager.ITradeList[] aentityvillager$itradelist2 = aentityvillager$itradelist1[j];
-
- for (EntityVillager.ITradeList entityvillager$itradelist : aentityvillager$itradelist2)
+ for (EntityVillager.ITradeList entityvillager$itradelist : trades)
{
entityvillager$itradelist.func_179401_a(this.field_70963_i, this.field_70146_Z);
}
@@ -647,9 +689,14 @@
} }
} }
@ -145,7 +153,7 @@
textcomponenttranslation.func_150256_b().func_150209_a(this.func_174823_aP()); textcomponenttranslation.func_150256_b().func_150209_a(this.func_174823_aP());
textcomponenttranslation.func_150256_b().func_179989_a(this.func_110124_au().toString()); textcomponenttranslation.func_150256_b().func_179989_a(this.func_110124_au().toString());
@@ -708,7 +757,7 @@ @@ -708,7 +755,7 @@
public IEntityLivingData func_180482_a(DifficultyInstance p_180482_1_, IEntityLivingData p_180482_2_) public IEntityLivingData func_180482_a(DifficultyInstance p_180482_1_, IEntityLivingData p_180482_2_)
{ {
p_180482_2_ = super.func_180482_a(p_180482_1_, p_180482_2_); p_180482_2_ = super.func_180482_a(p_180482_1_, p_180482_2_);

View file

@ -12,11 +12,14 @@
package net.minecraftforge.fml.common.registry; package net.minecraftforge.fml.common.registry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -224,7 +227,8 @@ public class VillagerRegistry
private VillagerProfession profession; private VillagerProfession profession;
private String name; private String name;
private int id; private int id;
private ITradeList[][] trades; private List<List<ITradeList>> trades = Lists.newArrayList();
private List<List<ITradeList>> imm = Lists.newArrayList();
public VillagerCareer(VillagerProfession parent, String name) public VillagerCareer(VillagerProfession parent, String name)
{ {
@ -238,14 +242,44 @@ public class VillagerRegistry
return this.name; return this.name;
} }
public ITradeList[][] getTrades()
public VillagerCareer addTrade(int level, ITradeList... trades)
{ {
return this.trades; if (level <= 0)
throw new IllegalArgumentException("Levels start at 1");
List<ITradeList> levelTrades = level <= this.trades.size() ? this.trades.get(level - 1) : null;
if (levelTrades == null)
{
List<ITradeList> tmp = null;
while (this.trades.size() < level)
{
tmp = Lists.newArrayList();
this.trades.add(tmp);
this.imm.add(Collections.unmodifiableList(tmp));
}
levelTrades = tmp;
}
if (levelTrades == null) //Not sure how this could happen, but screw it
{
levelTrades = Lists.newArrayList();
this.trades.set(level - 1, levelTrades);
this.imm.set(level - 1, Collections.unmodifiableList(levelTrades));
}
for (ITradeList t : trades)
levelTrades.add(t);
return this;
} }
public List<ITradeList> getTrades(int level)
{
return level >= 0 && level < this.imm.size() ? this.imm.get(level) : null;
}
private VillagerCareer init(EntityVillager.ITradeList[][] trades) private VillagerCareer init(EntityVillager.ITradeList[][] trades)
{ {
this.trades = trades; for (int x = 0; x < trades.length; x++)
this.trades.add(Lists.newArrayList(trades[x]));
return this; return this;
} }