Move vanilla trades to inner class to prevent initilizer order issues.
This commit is contained in:
parent
511c370193
commit
1f1166e722
1 changed files with 211 additions and 205 deletions
|
@ -198,9 +198,114 @@ public class VillagerRegistry
|
||||||
private boolean hasInit = false;
|
private boolean hasInit = false;
|
||||||
private List<VillagerProfession> professions = Lists.newArrayList();
|
private List<VillagerProfession> professions = Lists.newArrayList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
if (hasInit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VillagerProfession prof = new VillagerProfession("minecraft:farmer", "minecraft:textures/entity/villager/farmer.png");
|
||||||
|
{
|
||||||
|
register(prof);
|
||||||
|
(new VillagerCareer(prof, "farmer" )).init(VanillaTrades.trades[0][0]);
|
||||||
|
(new VillagerCareer(prof, "fisherman" )).init(VanillaTrades.trades[0][1]);
|
||||||
|
(new VillagerCareer(prof, "shepherd" )).init(VanillaTrades.trades[0][2]);
|
||||||
|
(new VillagerCareer(prof, "fletcher" )).init(VanillaTrades.trades[0][3]);
|
||||||
|
}
|
||||||
|
prof = new VillagerProfession("minecraft:librarian", "minecraft:textures/entity/villager/librarian.png");
|
||||||
|
{
|
||||||
|
register(prof);
|
||||||
|
(new VillagerCareer(prof, "librarian")).init(VanillaTrades.trades[1][0]);
|
||||||
|
}
|
||||||
|
prof = new VillagerProfession("minecraft:priest", "minecraft:textures/entity/villager/priest.png");
|
||||||
|
{
|
||||||
|
register(prof);
|
||||||
|
(new VillagerCareer(prof, "cleric")).init(VanillaTrades.trades[2][0]);
|
||||||
|
}
|
||||||
|
prof = new VillagerProfession("minecraft:smith", "minecraft:textures/entity/villager/smith.png");
|
||||||
|
{
|
||||||
|
register(prof);
|
||||||
|
(new VillagerCareer(prof, "armor" )).init(VanillaTrades.trades[3][0]);
|
||||||
|
(new VillagerCareer(prof, "weapon")).init(VanillaTrades.trades[3][1]);
|
||||||
|
(new VillagerCareer(prof, "tool" )).init(VanillaTrades.trades[3][2]);
|
||||||
|
}
|
||||||
|
prof = new VillagerProfession("minecraft:butcher", "minecraft:textures/entity/villager/butcher.png");
|
||||||
|
{
|
||||||
|
register(prof);
|
||||||
|
(new VillagerCareer(prof, "butcher")).init(VanillaTrades.trades[4][0]);
|
||||||
|
(new VillagerCareer(prof, "leather")).init(VanillaTrades.trades[4][1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VillagerProfession
|
||||||
|
{
|
||||||
|
private ResourceLocation name;
|
||||||
|
private ResourceLocation texture;
|
||||||
|
private List<VillagerCareer> careers = Lists.newArrayList();
|
||||||
|
|
||||||
|
public VillagerProfession(String name, String texture)
|
||||||
|
{
|
||||||
|
this.name = new ResourceLocation(name);
|
||||||
|
this.texture = new ResourceLocation(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void register(VillagerCareer career)
|
||||||
|
{
|
||||||
|
Validate.isTrue(!careers.contains(career), "Attempted to register career that is already registered.");
|
||||||
|
Validate.isTrue(career.profession == this, "Attempted to register career for the wrong profession.");
|
||||||
|
career.id = careers.size();
|
||||||
|
careers.add(career);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class VillagerCareer
|
||||||
|
{
|
||||||
|
private VillagerProfession profession;
|
||||||
|
private String name;
|
||||||
|
private int id;
|
||||||
|
public VillagerCareer(VillagerProfession parent, String name)
|
||||||
|
{
|
||||||
|
this.profession = parent;
|
||||||
|
this.name = name;
|
||||||
|
parent.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private VillagerCareer init(EntityVillager.ITradeList[][] traids)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (o == this) return true;
|
||||||
|
if (!(o instanceof VillagerCareer)) return false;
|
||||||
|
VillagerCareer oc = (VillagerCareer)o;
|
||||||
|
return name.equals(oc.name) && profession == oc.profession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook called when spawning a Villager, sets it's profession to a random registered profession.
|
||||||
|
*
|
||||||
|
* @param entity The new entity
|
||||||
|
* @param rand The world's RNG
|
||||||
|
*/
|
||||||
|
public static void setRandomProfession(EntityVillager entity, Random rand)
|
||||||
|
{
|
||||||
|
//TODO: Grab id range from internal registry
|
||||||
|
entity.setProfession(rand.nextInt(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Figure out a good generic system for this. Put on hold for Patches.
|
||||||
|
|
||||||
|
private static class VanillaTrades
|
||||||
|
{
|
||||||
//This field is moved from EntityVillager over to here.
|
//This field is moved from EntityVillager over to here.
|
||||||
|
//Moved to inner class to stop static initializer issues.
|
||||||
//It is nasty I know but it's vanilla.
|
//It is nasty I know but it's vanilla.
|
||||||
private static final ITradeList[][][][] vanillaTrades =
|
private static final ITradeList[][][][] trades =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -392,104 +497,5 @@ public class VillagerRegistry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void init()
|
|
||||||
{
|
|
||||||
if (hasInit)
|
|
||||||
return;
|
|
||||||
|
|
||||||
VillagerProfession prof = new VillagerProfession("minecraft:farmer", "minecraft:textures/entity/villager/farmer.png");
|
|
||||||
{
|
|
||||||
register(prof);
|
|
||||||
(new VillagerCareer(prof, "farmer" )).init(vanillaTrades[0][0]);
|
|
||||||
(new VillagerCareer(prof, "fisherman" )).init(vanillaTrades[0][1]);
|
|
||||||
(new VillagerCareer(prof, "shepherd" )).init(vanillaTrades[0][2]);
|
|
||||||
(new VillagerCareer(prof, "fletcher" )).init(vanillaTrades[0][3]);
|
|
||||||
}
|
|
||||||
prof = new VillagerProfession("minecraft:librarian", "minecraft:textures/entity/villager/librarian.png");
|
|
||||||
{
|
|
||||||
register(prof);
|
|
||||||
(new VillagerCareer(prof, "librarian")).init(vanillaTrades[1][0]);
|
|
||||||
}
|
|
||||||
prof = new VillagerProfession("minecraft:priest", "minecraft:textures/entity/villager/priest.png");
|
|
||||||
{
|
|
||||||
register(prof);
|
|
||||||
(new VillagerCareer(prof, "cleric")).init(vanillaTrades[2][0]);
|
|
||||||
}
|
|
||||||
prof = new VillagerProfession("minecraft:smith", "minecraft:textures/entity/villager/smith.png");
|
|
||||||
{
|
|
||||||
register(prof);
|
|
||||||
(new VillagerCareer(prof, "armor" )).init(vanillaTrades[3][0]);
|
|
||||||
(new VillagerCareer(prof, "weapon")).init(vanillaTrades[3][1]);
|
|
||||||
(new VillagerCareer(prof, "tool" )).init(vanillaTrades[3][2]);
|
|
||||||
}
|
|
||||||
prof = new VillagerProfession("minecraft:butcher", "minecraft:textures/entity/villager/butcher.png");
|
|
||||||
{
|
|
||||||
register(prof);
|
|
||||||
(new VillagerCareer(prof, "butcher")).init(vanillaTrades[4][0]);
|
|
||||||
(new VillagerCareer(prof, "leather")).init(vanillaTrades[4][1]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class VillagerProfession
|
|
||||||
{
|
|
||||||
private ResourceLocation name;
|
|
||||||
private ResourceLocation texture;
|
|
||||||
private List<VillagerCareer> careers = Lists.newArrayList();
|
|
||||||
|
|
||||||
public VillagerProfession(String name, String texture)
|
|
||||||
{
|
|
||||||
this.name = new ResourceLocation(name);
|
|
||||||
this.texture = new ResourceLocation(texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void register(VillagerCareer career)
|
|
||||||
{
|
|
||||||
Validate.isTrue(!careers.contains(career), "Attempted to register career that is already registered.");
|
|
||||||
Validate.isTrue(career.profession == this, "Attempted to register career for the wrong profession.");
|
|
||||||
career.id = careers.size();
|
|
||||||
careers.add(career);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class VillagerCareer
|
|
||||||
{
|
|
||||||
private VillagerProfession profession;
|
|
||||||
private String name;
|
|
||||||
private int id;
|
|
||||||
public VillagerCareer(VillagerProfession parent, String name)
|
|
||||||
{
|
|
||||||
this.profession = parent;
|
|
||||||
this.name = name;
|
|
||||||
parent.register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private VillagerCareer init(EntityVillager.ITradeList[][] traids)
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o)
|
|
||||||
{
|
|
||||||
if (o == this) return true;
|
|
||||||
if (!(o instanceof VillagerCareer)) return false;
|
|
||||||
VillagerCareer oc = (VillagerCareer)o;
|
|
||||||
return name.equals(oc.name) && profession == oc.profession;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook called when spawning a Villager, sets it's profession to a random registered profession.
|
|
||||||
*
|
|
||||||
* @param entity The new entity
|
|
||||||
* @param rand The world's RNG
|
|
||||||
*/
|
|
||||||
public static void setRandomProfession(EntityVillager entity, Random rand)
|
|
||||||
{
|
|
||||||
//TODO: Grab id range from internal registry
|
|
||||||
entity.setProfession(rand.nextInt(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Figure out a good generic system for this. Put on hold for Patches.
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue