Java 类net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration 实例源码
项目:IGW-mod
文件:Util.java
public static String getModIdForEntity(Class<? extends Entity> entity){
if(reflectionFailed) return "minecraft";
if(entityNames == null) {
try {
entityNames = (HashMap<String, ModContainer>)ReflectionHelper.findField(EntityRegistry.class, "entityNames").get(EntityRegistry.instance());
} catch(Exception e) {
IGWLog.warning("IGW-Mod failed to perform reflection! A result of this is that wiki pages related to Entities will not be found. Report to MineMaarten please!");
e.printStackTrace();
reflectionFailed = true;
return "minecraft";
}
}
EntityRegistration entityReg = EntityRegistry.instance().lookupModSpawn(entity, true);
if(entityReg == null) return "minecraft";
ModContainer mod = entityNames.get(entityReg.getEntityName());
if(mod == null) {
IGWLog.info("Couldn't find the owning mod of the entity " + entityReg.getEntityName() + " even though it's registered through the EntityRegistry!");
return "minecraft";
} else {
return mod.getModId().toLowerCase();
}
}
项目:CustomWorldGen
文件:FMLNetworkHandler.java
public static Packet<?> getEntitySpawningPacket(Entity entity)
{
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(entity.getClass(), false);
if (er == null)
{
return null;
}
if (er.usesVanillaSpawning())
{
return null;
}
return channelPair.get(Side.SERVER).generatePacketFrom(new FMLMessage.EntitySpawnMessage(er, entity, er.getContainer()));
}
项目:MMDLib-old
文件:ModUtils.java
/**
* Attempts to get the name of the mod which registered the entity. Minecraft will be
* returned for vanilla content while Unknown will be used for invalid cases.
*
* @param entity The entity to get the mod name for.
* @return The name of the mod which registered the entity.
*/
public static String getModName (Entity entity) {
if (entity == null)
return "Unknown";
final EntityRegistration reg = EntityRegistry.instance().lookupModSpawn(entity.getClass(), false);
if (reg != null) {
final ModContainer mod = reg.getContainer();
if (mod != null)
return mod.getName();
return "Unknown";
}
return "Minecraft";
}
项目:CustomWorldGen
文件:FMLMessage.java
public EntitySpawnMessage(EntityRegistration er, Entity entity, ModContainer modContainer)
{
super(entity);
modId = modContainer.getModId();
modEntityTypeId = er.getModEntityId();
}
项目:CustomWorldGen
文件:EntitySpawnHandler.java
private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg)
{
ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
if (er == null)
{
throw new RuntimeException( "Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId +
" at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
}
WorldClient wc = FMLClientHandler.instance().getWorldClient();
Class<? extends Entity> cls = er.getEntityClass();
try
{
Entity entity;
if (er.hasCustomSpawning())
{
entity = er.doCustomSpawning(spawnMsg);
} else
{
entity = cls.getConstructor(World.class).newInstance(wc);
int offset = spawnMsg.entityId - entity.getEntityId();
entity.setEntityId(spawnMsg.entityId);
entity.setUniqueId(spawnMsg.entityUUID);
entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
if (entity instanceof EntityLiving)
{
((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
}
Entity parts[] = entity.getParts();
if (parts != null)
{
for (int j = 0; j < parts.length; j++)
{
parts[j].setEntityId(parts[j].getEntityId() + offset);
}
}
}
EntityTracker.updateServerPosition(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
if (entity instanceof IThrowableEntity)
{
Entity thrower = clientPlayer.getEntityId() == spawnMsg.throwerId ? clientPlayer : wc.getEntityByID(spawnMsg.throwerId);
((IThrowableEntity) entity).setThrower(thrower);
}
if (spawnMsg.dataWatcherList != null)
{
entity.getDataManager().setEntryValues(spawnMsg.dataWatcherList);
}
if (spawnMsg.throwerId > 0)
{
entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
}
if (entity instanceof IEntityAdditionalSpawnData)
{
((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
}
wc.addEntityToWorld(spawnMsg.entityId, entity);
} catch (Exception e)
{
FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ +")");
throw Throwables.propagate(e);
}
}
项目:Bookshelf
文件:ModUtils.java
/**
* Gets the name of a mod that registered the entity. Due to Entity not using
* IForgeRegistryEntry.Impl a special method is required.
*
* @param entity The entity to get the mod name for.
* @return String The name of the mod that registered the entity.
*/
public static String getModName (Entity entity) {
if (entity == null) {
return "Unknown";
}
final EntityRegistration reg = getRegistryInfo(entity);
if (reg != null) {
final ModContainer mod = reg.getContainer();
if (mod != null) {
return mod.getName();
}
return "Unknown";
}
return "Minecraft";
}
项目:Bookshelf
文件:ModUtils.java
/**
* Gets registry info for an entity.
*
* @param entity The entity to get registry info of.
* @return The entities registry info. Can be null.
*/
public static EntityRegistration getRegistryInfo (Entity entity) {
return getRegistryInfo(entity.getClass());
}
项目:Bookshelf
文件:ModUtils.java
/**
* Gets registry info for an entity, from it's class.
*
* @param entity The class to look for.
* @return The entities registry info. Can be null.
*/
public static EntityRegistration getRegistryInfo (Class<? extends Entity> entity) {
return EntityRegistry.instance().lookupModSpawn(entity, false);
}