mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Update VillagerRegistry and use it. Should in theory make custom villagers work now. Using string version instead of int id for networking.
This commit is contained in:
1 parent
eb5e5b4b42
commit
d803f7db76
5 files changed
+134
-87
No files matched your search
@@ -5,7 +5,7 @@
|
||||
return field_110906_m;
|
||||
default:
|
||||
- return field_110903_f;
|
||||
+ return net.minecraftforge.fml.common.registry.VillagerRegistry.getVillagerSkin(p_110775_1_.func_70946_n(), field_110903_f);
|
||||
+ return p_110775_1_.getProfessionForge().getSkin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
--- ../src-base/minecraft/net/minecraft/entity/passive/EntityVillager.java
|
||||
+++ ../src-work/minecraft/net/minecraft/entity/passive/EntityVillager.java
|
||||
@@ -90,6 +90,7 @@
|
||||
@@ -74,6 +74,7 @@
|
||||
public class EntityVillager extends EntityAgeable implements IMerchant, INpc
|
||||
{
|
||||
private static final DataParameter<Integer> field_184752_bw = EntityDataManager.<Integer>func_187226_a(EntityVillager.class, DataSerializers.field_187192_b);
|
||||
+ private static final DataParameter<String> PROFESSION_STR = EntityDataManager.<String>func_187226_a(EntityVillager.class, DataSerializers.field_187194_d);
|
||||
private int field_70955_e;
|
||||
private boolean field_70952_f;
|
||||
private boolean field_70953_g;
|
||||
@@ -90,6 +91,7 @@
|
||||
private boolean field_82190_bM;
|
||||
private boolean field_175564_by;
|
||||
private InventoryBasic field_175560_bz;
|
||||
@@ -8,7 +16,7 @@
|
||||
private static final EntityVillager.ITradeList[][][][] field_175561_bA = new EntityVillager.ITradeList[][][][] {{{{new EntityVillager.EmeraldForItems(Items.field_151015_O, new EntityVillager.PriceInfo(18, 22)), new EntityVillager.EmeraldForItems(Items.field_151174_bG, new EntityVillager.PriceInfo(15, 19)), new EntityVillager.EmeraldForItems(Items.field_151172_bF, new EntityVillager.PriceInfo(15, 19)), new EntityVillager.ListItemForEmeralds(Items.field_151025_P, new EntityVillager.PriceInfo(-4, -2))}, {new EntityVillager.EmeraldForItems(Item.func_150898_a(Blocks.field_150423_aK), new EntityVillager.PriceInfo(8, 13)), new EntityVillager.ListItemForEmeralds(Items.field_151158_bO, new EntityVillager.PriceInfo(-3, -2))}, {new EntityVillager.EmeraldForItems(Item.func_150898_a(Blocks.field_150440_ba), new EntityVillager.PriceInfo(7, 12)), new EntityVillager.ListItemForEmeralds(Items.field_151034_e, new EntityVillager.PriceInfo(-5, -7))}, {new EntityVillager.ListItemForEmeralds(Items.field_151106_aX, new EntityVillager.PriceInfo(-6, -10)), new EntityVillager.ListItemForEmeralds(Items.field_151105_aU, new EntityVillager.PriceInfo(1, 1))}}, {{new EntityVillager.EmeraldForItems(Items.field_151007_F, new EntityVillager.PriceInfo(15, 20)), new EntityVillager.EmeraldForItems(Items.field_151044_h, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ItemAndEmeraldToItem(Items.field_151115_aP, new EntityVillager.PriceInfo(6, 6), Items.field_179566_aV, new EntityVillager.PriceInfo(6, 6))}, {new EntityVillager.ListEnchantedItemForEmeralds(Items.field_151112_aM, new EntityVillager.PriceInfo(7, 8))}}, {{new EntityVillager.EmeraldForItems(Item.func_150898_a(Blocks.field_150325_L), new EntityVillager.PriceInfo(16, 22)), new EntityVillager.ListItemForEmeralds(Items.field_151097_aZ, new EntityVillager.PriceInfo(3, 4))}, {new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L)), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 1), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 2), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 3), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 4), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 5), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 6), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 7), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 8), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 9), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 10), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 11), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 12), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 13), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 14), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.func_150898_a(Blocks.field_150325_L), 1, 15), new EntityVillager.PriceInfo(1, 2))}}, {{new EntityVillager.EmeraldForItems(Items.field_151007_F, new EntityVillager.PriceInfo(15, 20)), new EntityVillager.ListItemForEmeralds(Items.field_151032_g, new EntityVillager.PriceInfo(-12, -8))}, {new EntityVillager.ListItemForEmeralds(Items.field_151031_f, new EntityVillager.PriceInfo(2, 3)), new EntityVillager.ItemAndEmeraldToItem(Item.func_150898_a(Blocks.field_150351_n), new EntityVillager.PriceInfo(10, 10), Items.field_151145_ak, new EntityVillager.PriceInfo(6, 10))}}}, {{{new EntityVillager.EmeraldForItems(Items.field_151121_aF, new EntityVillager.PriceInfo(24, 36)), new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.EmeraldForItems(Items.field_151122_aG, new EntityVillager.PriceInfo(8, 10)), new EntityVillager.ListItemForEmeralds(Items.field_151111_aL, new EntityVillager.PriceInfo(10, 12)), new EntityVillager.ListItemForEmeralds(Item.func_150898_a(Blocks.field_150342_X), ne
Line truncated
|
||||
|
||||
public EntityVillager(World p_i1747_1_)
|
||||
@@ -221,7 +222,7 @@
|
||||
@@ -221,7 +223,7 @@
|
||||
{
|
||||
boolean flag = p_184645_3_ != null && p_184645_3_.func_77973_b() == Items.field_151063_bx;
|
||||
|
||||
@@ -17,23 +25,106 @@
|
||||
{
|
||||
if (!this.field_70170_p.field_72995_K && (this.field_70963_i == null || !this.field_70963_i.isEmpty()))
|
||||
{
|
||||
@@ -533,6 +534,7 @@
|
||||
@@ -242,12 +244,14 @@
|
||||
{
|
||||
super.func_70088_a();
|
||||
this.field_70180_af.func_187214_a(field_184752_bw, Integer.valueOf(0));
|
||||
+ this.field_70180_af.func_187214_a(PROFESSION_STR, "minecraft:farmer");
|
||||
}
|
||||
|
||||
public void func_70014_b(NBTTagCompound p_70014_1_)
|
||||
{
|
||||
super.func_70014_b(p_70014_1_);
|
||||
p_70014_1_.func_74768_a("Profession", this.func_70946_n());
|
||||
+ p_70014_1_.func_74778_a("ProfessionName", this.getProfessionForge().getRegistryName().toString());
|
||||
p_70014_1_.func_74768_a("Riches", this.field_70956_bz);
|
||||
p_70014_1_.func_74768_a("Career", this.field_175563_bv);
|
||||
p_70014_1_.func_74768_a("CareerLevel", this.field_175562_bw);
|
||||
@@ -277,6 +281,14 @@
|
||||
{
|
||||
super.func_70037_a(p_70037_1_);
|
||||
this.func_70938_b(p_70037_1_.func_74762_e("Profession"));
|
||||
+ if (p_70037_1_.func_74764_b("ProfessionName"))
|
||||
+ {
|
||||
+ net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession p =
|
||||
+ net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().get(new net.minecraft.util.ResourceLocation(p_70037_1_.func_74779_i("ProfessionName")));
|
||||
+ if (p == null)
|
||||
+ p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().get(new net.minecraft.util.ResourceLocation("minecraft:farmer"));
|
||||
+ this.setProfession(p);
|
||||
+ }
|
||||
this.field_70956_bz = p_70037_1_.func_74762_e("Riches");
|
||||
this.field_175563_bv = p_70037_1_.func_74762_e("Career");
|
||||
this.field_175562_bw = p_70037_1_.func_74762_e("CareerLevel");
|
||||
@@ -334,6 +346,26 @@
|
||||
return Math.max(((Integer)this.field_70180_af.func_187225_a(field_184752_bw)).intValue() % 5, 0);
|
||||
}
|
||||
|
||||
+ private net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof;
|
||||
+ public void setProfession(net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof)
|
||||
+ {
|
||||
+ this.field_70180_af.func_187227_b(PROFESSION_STR, prof.getRegistryName().toString());
|
||||
+ this.prof = prof;
|
||||
+ }
|
||||
+
|
||||
+ public net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession getProfessionForge()
|
||||
+ {
|
||||
+ if (this.prof == null)
|
||||
+ {
|
||||
+ String p = this.field_70180_af.func_187225_a(PROFESSION_STR);
|
||||
+ net.minecraft.util.ResourceLocation res = new net.minecraft.util.ResourceLocation(p == null ? "minecraft:farmer" : p);
|
||||
+ this.prof = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().get(res);
|
||||
+ if (this.prof == null)
|
||||
+ return net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().get(new net.minecraft.util.ResourceLocation("minecraft:farmer"));
|
||||
+ }
|
||||
+ return this.prof;
|
||||
+ }
|
||||
+
|
||||
public boolean func_70941_o()
|
||||
{
|
||||
return this.field_70952_f;
|
||||
@@ -533,15 +565,13 @@
|
||||
|
||||
private void func_175554_cu()
|
||||
{
|
||||
+ //TODO: Hook into VillagerRegistry
|
||||
EntityVillager.ITradeList[][][] aentityvillager$itradelist = field_175561_bA[this.func_70946_n()];
|
||||
|
||||
- EntityVillager.ITradeList[][][] aentityvillager$itradelist = field_175561_bA[this.func_70946_n()];
|
||||
-
|
||||
if (this.field_175563_bv != 0 && this.field_175562_bw != 0)
|
||||
@@ -647,6 +649,7 @@
|
||||
{
|
||||
++this.field_175562_bw;
|
||||
}
|
||||
else
|
||||
{
|
||||
- this.field_175563_bv = this.field_70146_Z.nextInt(aentityvillager$itradelist.length) + 1;
|
||||
+ this.field_175563_bv = this.getProfessionForge().getRandomCareer(this.field_70146_Z) + 1;
|
||||
this.field_175562_bw = 1;
|
||||
}
|
||||
|
||||
@@ -552,7 +582,7 @@
|
||||
|
||||
int i = this.field_175563_bv - 1;
|
||||
int j = this.field_175562_bw - 1;
|
||||
- EntityVillager.ITradeList[][] aentityvillager$itradelist1 = aentityvillager$itradelist[i];
|
||||
+ EntityVillager.ITradeList[][] aentityvillager$itradelist1 = this.getProfessionForge().getCareer(i).getTrades();
|
||||
|
||||
if (j >= 0 && j < aentityvillager$itradelist1.length)
|
||||
{
|
||||
@@ -647,9 +677,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ if (s1 == null)
|
||||
+ s1 = this.getProfessionForge().getCareer(this.field_175563_bv).getName();
|
||||
+ else
|
||||
+ s1 = "entity.Villager." + s1;
|
||||
+ //TODO: Hook into VillagerRegistry to get name
|
||||
if (s1 != null)
|
||||
{
|
||||
TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("entity.Villager." + s1, new Object[0]);
|
||||
@@ -708,7 +711,7 @@
|
||||
- TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("entity.Villager." + s1, new Object[0]);
|
||||
+ TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(s1, new Object[0]);
|
||||
textcomponenttranslation.func_150256_b().func_150209_a(this.func_174823_aP());
|
||||
textcomponenttranslation.func_150256_b().func_179989_a(this.func_110124_au().toString());
|
||||
|
||||
@@ -708,7 +743,7 @@
|
||||
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_);
|
||||
|
||||
+1
-3
@@ -19,11 +19,9 @@ import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.util.IntIdentityHashBiMap;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
@@ -465,7 +463,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
|
||||
addObjectRaw(idToUse, name, thing);
|
||||
if (isDelegated)
|
||||
{
|
||||
getExistingDelegate(thing).setResourceName(name);
|
||||
getExistingDelegate(thing).setName(name);
|
||||
}
|
||||
|
||||
if (this.dummiedLocations.remove(name) && DEBUG)
|
||||
|
||||
@@ -69,7 +69,7 @@ public interface RegistryDelegate<T> {
|
||||
this.referant = newTarget;
|
||||
}
|
||||
|
||||
void setResourceName(ResourceLocation name) { this.name = name; }
|
||||
void setName(ResourceLocation name) { this.name = name; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -42,10 +40,6 @@ import net.minecraft.world.gen.structure.StructureComponent;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces.Village;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Registry for villager trading control
|
||||
*
|
||||
@@ -57,9 +51,6 @@ public class VillagerRegistry
|
||||
private static final VillagerRegistry INSTANCE = new VillagerRegistry();
|
||||
|
||||
private Map<Class<?>, IVillageCreationHandler> villageCreationHandlers = Maps.newHashMap();
|
||||
private List<Integer> newVillagerIds = Lists.newArrayList();
|
||||
@SideOnly(Side.CLIENT)
|
||||
private Map<Integer, ResourceLocation> newVillagers;
|
||||
|
||||
private VillagerRegistry()
|
||||
{
|
||||
@@ -110,39 +101,6 @@ public class VillagerRegistry
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register your villager id
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Deprecated // Doesn't work at all.
|
||||
public void registerVillagerId(int id)
|
||||
{
|
||||
if (newVillagerIds.contains(id))
|
||||
{
|
||||
FMLLog.severe("Attempt to register duplicate villager id %d", id);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
newVillagerIds.add(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new skin for a villager type
|
||||
*
|
||||
* @param villagerId
|
||||
* @param villagerSkin
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Deprecated // Doesn't work at all.
|
||||
public void registerVillagerSkin(int villagerId, ResourceLocation villagerSkin)
|
||||
{
|
||||
if (newVillagers == null)
|
||||
{
|
||||
newVillagers = Maps.newHashMap();
|
||||
}
|
||||
newVillagers.put(villagerId, villagerSkin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new village creation handler
|
||||
*
|
||||
@@ -153,34 +111,6 @@ public class VillagerRegistry
|
||||
villageCreationHandlers.put(handler.getComponentClass(), handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to setup new villager types
|
||||
*
|
||||
* @param villagerType
|
||||
* @param defaultSkin
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Deprecated // Doesn't work at all.
|
||||
public static ResourceLocation getVillagerSkin(int villagerType, ResourceLocation defaultSkin)
|
||||
{
|
||||
if (instance().newVillagers != null && instance().newVillagers.containsKey(villagerType))
|
||||
{
|
||||
return instance().newVillagers.get(villagerType);
|
||||
}
|
||||
return defaultSkin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all added villager types
|
||||
*
|
||||
* @return newVillagerIds
|
||||
*/
|
||||
@Deprecated // Doesn't work at all.
|
||||
public static Collection<Integer> getRegisteredVillagers()
|
||||
{
|
||||
return Collections.unmodifiableCollection(instance().newVillagerIds);
|
||||
}
|
||||
|
||||
public static void addExtraVillageComponents(List<PieceWeight> list, Random random, int i)
|
||||
{
|
||||
List<StructureVillagePieces.PieceWeight> parts = list;
|
||||
@@ -208,6 +138,7 @@ public class VillagerRegistry
|
||||
|
||||
private boolean hasInit = false;
|
||||
private FMLControlledNamespacedRegistry<VillagerProfession> professions = PersistentRegistryManager.createRegistry(PROFESSIONS, VillagerProfession.class, null, 1024, 0, true, null);
|
||||
public IForgeRegistry<VillagerProfession> getRegistry() { return this.professions; }
|
||||
|
||||
|
||||
private void init()
|
||||
@@ -255,13 +186,12 @@ public class VillagerRegistry
|
||||
private ResourceLocation name;
|
||||
private ResourceLocation texture;
|
||||
private List<VillagerCareer> careers = Lists.newArrayList();
|
||||
public final RegistryDelegate<VillagerProfession> delegate = PersistentRegistryManager.makeDelegate(this, VillagerProfession.class);
|
||||
|
||||
public VillagerProfession(String name, String texture)
|
||||
{
|
||||
this.name = new ResourceLocation(name);
|
||||
this.texture = new ResourceLocation(texture);
|
||||
((RegistryDelegate.Delegate<VillagerProfession>)delegate).setResourceName(this.name);
|
||||
this.setRegistryName(this.name);
|
||||
}
|
||||
|
||||
private void register(VillagerCareer career)
|
||||
@@ -271,6 +201,22 @@ public class VillagerRegistry
|
||||
career.id = careers.size();
|
||||
careers.add(career);
|
||||
}
|
||||
|
||||
public ResourceLocation getSkin() { return this.texture; }
|
||||
public VillagerCareer getCareer(int id)
|
||||
{
|
||||
for (VillagerCareer car : this.careers)
|
||||
{
|
||||
if (car.id == id)
|
||||
return car;
|
||||
}
|
||||
return this.careers.get(0);
|
||||
}
|
||||
|
||||
public int getRandomCareer(Random rand)
|
||||
{
|
||||
return this.careers.get(rand.nextInt(this.careers.size())).id;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VillagerCareer
|
||||
@@ -278,6 +224,7 @@ public class VillagerRegistry
|
||||
private VillagerProfession profession;
|
||||
private String name;
|
||||
private int id;
|
||||
private ITradeList[][] trades;
|
||||
|
||||
public VillagerCareer(VillagerProfession parent, String name)
|
||||
{
|
||||
@@ -286,8 +233,19 @@ public class VillagerRegistry
|
||||
parent.register(this);
|
||||
}
|
||||
|
||||
private VillagerCareer init(EntityVillager.ITradeList[][] traids)
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ITradeList[][] getTrades()
|
||||
{
|
||||
return this.trades;
|
||||
}
|
||||
|
||||
private VillagerCareer init(EntityVillager.ITradeList[][] trades)
|
||||
{
|
||||
this.trades = trades;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user