mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 20:52:34 +00:00
New system in EntityRegistry to allow modders to register spawn eggs.
For entites that do not use the global ID system.
{Which no mod entity should}
Vanilla spawn eggs will now detect a 'entity_name' entry in it's NBT data and use that for spawning/rendering.
This commit is contained in:
1 parent
ed09a25c65
commit
c158af902f
7 files changed
+232
-1
No files matched your search
@@ -0,0 +1,19 @@
|
||||
--- ../src-base/minecraft/net/minecraft/client/gui/achievement/GuiStats.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/gui/achievement/GuiStats.java
|
||||
@@ -769,6 +769,7 @@
|
||||
super(p_i45510_2_, GuiStats.this.field_146294_l, GuiStats.this.field_146295_m, 32, GuiStats.this.field_146295_m - 64, GuiStats.this.field_146289_q.field_78288_b * 4);
|
||||
this.func_148130_a(false);
|
||||
Iterator iterator = EntityList.field_75627_a.values().iterator();
|
||||
+ iterator = com.google.common.collect.Iterators.concat(iterator, net.minecraftforge.fml.common.registry.EntityRegistry.getEggs().values().iterator());
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
@@ -806,7 +807,7 @@
|
||||
protected void func_180791_a(int p_180791_1_, int p_180791_2_, int p_180791_3_, int p_180791_4_, int p_180791_5_, int p_180791_6_)
|
||||
{
|
||||
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)this.field_148222_l.get(p_180791_1_);
|
||||
- String s = I18n.func_135052_a("entity." + EntityList.func_75617_a(entityegginfo.field_75613_a) + ".name", new Object[0]);
|
||||
+ String s = I18n.func_135052_a("entity." + entityegginfo.name + ".name", new Object[0]);
|
||||
int k1 = GuiStats.this.field_146546_t.func_77444_a(entityegginfo.field_151512_d);
|
||||
int l1 = GuiStats.this.field_146546_t.func_77444_a(entityegginfo.field_151513_e);
|
||||
String s1 = I18n.func_135052_a("stat.entityKills", new Object[] {Integer.valueOf(k1), s});
|
||||
@@ -30,3 +30,31 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -344,7 +355,9 @@
|
||||
|
||||
public static class EntityEggInfo
|
||||
{
|
||||
+ @Deprecated // This is not always a valid number in the global ID list.
|
||||
public final int field_75613_a;
|
||||
+ public final String name;
|
||||
public final int field_75611_b;
|
||||
public final int field_75612_c;
|
||||
public final StatBase field_151512_d;
|
||||
@@ -358,6 +371,17 @@
|
||||
this.field_75612_c = p_i1583_3_;
|
||||
this.field_151512_d = StatList.func_151182_a(this);
|
||||
this.field_151513_e = StatList.func_151176_b(this);
|
||||
+ this.name = EntityList.func_75617_a(p_i1583_1_);
|
||||
}
|
||||
+
|
||||
+ public EntityEggInfo(String name, int primaryColor, int secondaryColor)
|
||||
+ {
|
||||
+ this.field_75613_a = -1;
|
||||
+ this.name = name;
|
||||
+ this.field_75611_b = primaryColor;
|
||||
+ this.field_75612_c = secondaryColor;
|
||||
+ this.field_151512_d = (new StatBase("stat.killEntity." + name, new net.minecraft.util.ChatComponentTranslation("stat.entityKill", new net.minecraft.util.ChatComponentTranslation("entity." + name + ".name")))).func_75971_g();
|
||||
+ this.field_151513_e = (new StatBase("stat.entityKilledBy." + name, new net.minecraft.util.ChatComponentTranslation("stat.entityKilledBy", new net.minecraft.util.ChatComponentTranslation("entity." + name + ".name")))).func_75971_g();
|
||||
+ }
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,15 @@
|
||||
}
|
||||
|
||||
public int func_82145_z()
|
||||
@@ -2139,6 +2141,22 @@
|
||||
@@ -1725,6 +1727,7 @@
|
||||
}
|
||||
|
||||
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)EntityList.field_75627_a.get(Integer.valueOf(EntityList.func_75619_a(p_70074_1_)));
|
||||
+ if (entityegginfo == null) entityegginfo = net.minecraftforge.fml.common.registry.EntityRegistry.getEggs().get(EntityList.func_75621_b(p_70074_1_));
|
||||
|
||||
if (entityegginfo != null)
|
||||
{
|
||||
@@ -2139,6 +2142,22 @@
|
||||
this.field_175153_bG = p_175150_1_;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
--- ../src-base/minecraft/net/minecraft/entity/player/EntityPlayerMP.java
|
||||
+++ ../src-work/minecraft/net/minecraft/entity/player/EntityPlayerMP.java
|
||||
@@ -481,6 +481,7 @@
|
||||
if (entitylivingbase != null)
|
||||
{
|
||||
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)EntityList.field_75627_a.get(Integer.valueOf(EntityList.func_75619_a(entitylivingbase)));
|
||||
+ if (entityegginfo == null) entityegginfo = net.minecraftforge.fml.common.registry.EntityRegistry.getEggs().get(EntityList.func_75621_b(entitylivingbase));
|
||||
|
||||
if (entityegginfo != null)
|
||||
{
|
||||
@@ -0,0 +1,107 @@
|
||||
--- ../src-base/minecraft/net/minecraft/item/ItemMonsterPlacer.java
|
||||
+++ ../src-work/minecraft/net/minecraft/item/ItemMonsterPlacer.java
|
||||
@@ -39,7 +39,7 @@
|
||||
public String func_77653_i(ItemStack p_77653_1_)
|
||||
{
|
||||
String s = ("" + StatCollector.func_74838_a(this.func_77658_a() + ".name")).trim();
|
||||
- String s1 = EntityList.func_75617_a(p_77653_1_.func_77960_j());
|
||||
+ String s1 = ItemMonsterPlacer.getEntityName(p_77653_1_);
|
||||
|
||||
if (s1 != null)
|
||||
{
|
||||
@@ -52,7 +52,7 @@
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int func_82790_a(ItemStack p_82790_1_, int p_82790_2_)
|
||||
{
|
||||
- EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)EntityList.field_75627_a.get(Integer.valueOf(p_82790_1_.func_77960_j()));
|
||||
+ EntityList.EntityEggInfo entityegginfo = ItemMonsterPlacer.getEggInfo(p_82790_1_);
|
||||
return entityegginfo != null ? (p_82790_2_ == 0 ? entityegginfo.field_75611_b : entityegginfo.field_75612_c) : 16777215;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
if (tileentity instanceof TileEntityMobSpawner)
|
||||
{
|
||||
MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).func_145881_a();
|
||||
- mobspawnerbaselogic.func_98272_a(EntityList.func_75617_a(p_180614_1_.func_77960_j()));
|
||||
+ mobspawnerbaselogic.func_98272_a(ItemMonsterPlacer.getEntityName(p_180614_1_));
|
||||
tileentity.func_70296_d();
|
||||
p_180614_3_.func_175689_h(p_180614_4_);
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
d0 = 0.5D;
|
||||
}
|
||||
|
||||
- Entity entity = func_77840_a(p_180614_3_, p_180614_1_.func_77960_j(), (double)p_180614_4_.func_177958_n() + 0.5D, (double)p_180614_4_.func_177956_o() + d0, (double)p_180614_4_.func_177952_p() + 0.5D);
|
||||
+ Entity entity = spawnCreature(p_180614_3_, ItemMonsterPlacer.getEntityName(p_180614_1_), (double)p_180614_4_.func_177958_n() + 0.5D, (double)p_180614_4_.func_177956_o() + d0, (double)p_180614_4_.func_177952_p() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
@@ -149,7 +149,7 @@
|
||||
|
||||
if (p_77659_2_.func_180495_p(blockpos).func_177230_c() instanceof BlockLiquid)
|
||||
{
|
||||
- Entity entity = func_77840_a(p_77659_2_, p_77659_1_.func_77960_j(), (double)blockpos.func_177958_n() + 0.5D, (double)blockpos.func_177956_o() + 0.5D, (double)blockpos.func_177952_p() + 0.5D);
|
||||
+ Entity entity = spawnCreature(p_77659_2_, ItemMonsterPlacer.getEntityName(p_77659_1_), (double)blockpos.func_177958_n() + 0.5D, (double)blockpos.func_177956_o() + 0.5D, (double)blockpos.func_177952_p() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
@@ -173,19 +173,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ @Deprecated // Use string version below.
|
||||
public static Entity func_77840_a(World p_77840_0_, int p_77840_1_, double p_77840_2_, double p_77840_4_, double p_77840_6_)
|
||||
{
|
||||
if (!EntityList.field_75627_a.containsKey(Integer.valueOf(p_77840_1_)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
+ return spawnCreature(p_77840_0_, EntityList.func_75617_a(p_77840_1_), p_77840_2_, p_77840_4_, p_77840_6_);
|
||||
+ }
|
||||
+
|
||||
+ public static Entity spawnCreature(World p_77840_0_, String name, double p_77840_2_, double p_77840_4_, double p_77840_6_)
|
||||
+ {
|
||||
+ if (!EntityList.field_75625_b.containsKey(name))
|
||||
+ {
|
||||
+ return null;
|
||||
+ }
|
||||
else
|
||||
{
|
||||
Entity entity = null;
|
||||
|
||||
for (int j = 0; j < 1; ++j)
|
||||
{
|
||||
- entity = EntityList.func_75616_a(p_77840_1_, p_77840_0_);
|
||||
+ entity = EntityList.func_75620_a(name, p_77840_0_);
|
||||
|
||||
if (entity instanceof EntityLivingBase)
|
||||
{
|
||||
@@ -213,5 +223,28 @@
|
||||
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)iterator.next();
|
||||
p_150895_3_.add(new ItemStack(p_150895_1_, 1, entityegginfo.field_75613_a));
|
||||
}
|
||||
+
|
||||
+ for (String name : net.minecraftforge.fml.common.registry.EntityRegistry.getEggs().keySet())
|
||||
+ {
|
||||
+ ItemStack stack = new ItemStack(p_150895_1_);
|
||||
+ net.minecraft.nbt.NBTTagCompound nbt = new net.minecraft.nbt.NBTTagCompound();
|
||||
+ nbt.func_74778_a("entity_name", name);
|
||||
+ stack.func_77982_d(nbt);
|
||||
+ p_150895_3_.add(stack);
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ private static String getEntityName(ItemStack stack)
|
||||
+ {
|
||||
+ if (stack.func_77942_o() && stack.func_77978_p().func_150297_b("entity_name", 8))
|
||||
+ return stack.func_77978_p().func_74779_i("entity_name");
|
||||
+ return EntityList.func_75617_a(stack.func_77960_j());
|
||||
+ }
|
||||
+
|
||||
+ private static EntityList.EntityEggInfo getEggInfo(ItemStack stack)
|
||||
+ {
|
||||
+ if (stack.func_77942_o() && stack.func_77978_p().func_150297_b("entity_name", 8))
|
||||
+ net.minecraftforge.fml.common.registry.EntityRegistry.getEggs().get(stack.func_77978_p().func_74779_i("entity_name"));
|
||||
+ return (EntityList.EntityEggInfo)EntityList.field_75627_a.get(stack.func_77960_j());
|
||||
+ }
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -117,6 +118,9 @@ public class EntityRegistry
|
||||
private ListMultimap<ModContainer, EntityRegistration> entityRegistrations = ArrayListMultimap.create();
|
||||
private Map<String,ModContainer> entityNames = Maps.newHashMap();
|
||||
private BiMap<Class<? extends Entity>, EntityRegistration> entityClassRegistrations = HashBiMap.create();
|
||||
private Map<String, EntityList.EntityEggInfo> entityEggs = Maps.newHashMap();
|
||||
private Map<String, EntityList.EntityEggInfo> entityEggsUn = Collections.unmodifiableMap(entityEggs);
|
||||
|
||||
public static EntityRegistry instance()
|
||||
{
|
||||
return INSTANCE;
|
||||
@@ -148,6 +152,26 @@ public class EntityRegistry
|
||||
instance().doModEntityRegistration(entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the mod entity type with FML
|
||||
* This will also register a spawn egg.
|
||||
|
||||
* @param entityClass The entity class
|
||||
* @param entityName A unique name for the entity
|
||||
* @param id A mod specific ID for the entity
|
||||
* @param mod The mod
|
||||
* @param trackingRange The range at which MC will send tracking updates
|
||||
* @param updateFrequency The frequency of tracking updates
|
||||
* @param sendsVelocityUpdates Whether to send velocity information packets as well
|
||||
* @param eggPrimary Primary egg color
|
||||
* @param eggSecondary Secondary egg color
|
||||
*/
|
||||
public static void registerModEntity(Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates, int eggPrimary, int eggSecondary)
|
||||
{
|
||||
instance().doModEntityRegistration(entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates);
|
||||
EntityRegistry.registerEgg(entityClass, eggPrimary, eggSecondary);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void doModEntityRegistration(Class<? extends Entity> entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
|
||||
{
|
||||
@@ -177,6 +201,40 @@ public class EntityRegistry
|
||||
entityRegistrations.put(mc, er);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a spawn egg for the specified entity class.
|
||||
* The class must already be registered in the EntityList.classToStringMapping.
|
||||
* This can be done either by using the global ID system, or preferably the registerModEntity functions above.
|
||||
* Once registered mob eggs can be created by using minecraft:spawn_egg with NBT entry 'entity_name' with
|
||||
* value of the name this class is registered in the classToStringMapping with.
|
||||
*
|
||||
* @param entityClass The entity class
|
||||
* @param primary Primary egg color
|
||||
* @param secondary Secondary egg color
|
||||
*
|
||||
* @throws IllegalArgumentException if entityClass is not registered in classToStringMapping.
|
||||
*
|
||||
*/
|
||||
public static void registerEgg(Class<? extends Entity> entityClass, int primary, int secondary)
|
||||
{
|
||||
if (!EntityList.classToStringMapping.containsKey(entityClass))
|
||||
throw new IllegalArgumentException("Entity not registered in classToString map: " + entityClass);
|
||||
|
||||
String name = (String)EntityList.classToStringMapping.get(entityClass);
|
||||
EntityRegistry.instance().entityEggs.put(name, new EntityList.EntityEggInfo(name, primary, secondary));
|
||||
FMLLog.fine("Registering entity egg '%s' for %s", name, entityClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Unmodifiable view of the registered entity eggs list.
|
||||
*
|
||||
* @return An Unmodifiable view of the registered entity eggs list.
|
||||
*/
|
||||
public static Map<String, EntityList.EntityEggInfo> getEggs()
|
||||
{
|
||||
return instance().entityEggsUn;
|
||||
}
|
||||
|
||||
public static void registerGlobalEntityID(Class <? extends Entity > entityClass, String entityName, int id)
|
||||
{
|
||||
if (EntityList.classToStringMapping.containsKey(entityClass))
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
net/minecraft/server/management/ServerConfigurationManager.initializeConnectionToPlayer(Lnet/minecraft/network/NetworkManager;Lnet/minecraft/entity/player/EntityPlayerMP;Lnet/minecraft/network/NetHandlerPlayServer;)V=|p_72355_1_,p_72355_2_,nethandlerplayserver
|
||||
net/minecraft/item/ItemMonsterPlacer.spawnCreature(Lnet/minecraft/world/World;Ljava/lang/String;DDD)Lnet/minecraft/entity/Entity;=|p_77840_0_,name,p_77840_2_,p_77840_4_,p_77840_6_
|
||||
Reference in new issue
Block a user