本文整理汇总了Java中net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData类的典型用法代码示例。如果您正苦于以下问题:Java IEntityAdditionalSpawnData类的具体用法?Java IEntityAdditionalSpawnData怎么用?Java IEntityAdditionalSpawnData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IEntityAdditionalSpawnData类属于net.minecraftforge.fml.common.registry包,在下文中一共展示了IEntityAdditionalSpawnData类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBytes
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; //导入依赖的package包/类
@Override
void toBytes(ByteBuf buf)
{
super.toBytes(buf);
ByteBufUtils.writeUTF8String(buf, modId);
buf.writeInt(modEntityTypeId);
buf.writeLong(entity.getUniqueID().getMostSignificantBits());
buf.writeLong(entity.getUniqueID().getLeastSignificantBits());
// posX, posY, posZ
buf.writeDouble(entity.posX);
buf.writeDouble(entity.posY);
buf.writeDouble(entity.posZ);
// yaw, pitch
buf.writeByte((byte)(entity.rotationYaw * 256.0F / 360.0F));
buf.writeByte((byte) (entity.rotationPitch * 256.0F / 360.0F));
// head yaw
if (entity instanceof EntityLivingBase)
{
buf.writeByte((byte) (((EntityLivingBase)entity).rotationYawHead * 256.0F / 360.0F));
}
else
{
buf.writeByte(0);
}
ByteBuf tmpBuf = Unpooled.buffer();
PacketBuffer pb = new PacketBuffer(tmpBuf);
try
{
entity.getDataManager().writeEntries(pb);
} catch (IOException e)
{
FMLLog.log(Level.FATAL,e,"Encountered fatal exception trying to send entity spawn data watchers");
throw Throwables.propagate(e);
}
buf.writeBytes(tmpBuf);
if (entity instanceof IThrowableEntity)
{
Entity owner = ((IThrowableEntity)entity).getThrower();
buf.writeInt(owner == null ? entity.getEntityId() : owner.getEntityId());
double maxVel = 3.9D;
double mX = entity.motionX;
double mY = entity.motionY;
double mZ = entity.motionZ;
if (mX < -maxVel) mX = -maxVel;
if (mY < -maxVel) mY = -maxVel;
if (mZ < -maxVel) mZ = -maxVel;
if (mX > maxVel) mX = maxVel;
if (mY > maxVel) mY = maxVel;
if (mZ > maxVel) mZ = maxVel;
buf.writeInt((int)(mX * 8000D));
buf.writeInt((int)(mY * 8000D));
buf.writeInt((int)(mZ * 8000D));
}
else
{
buf.writeInt(0);
}
if (entity instanceof IEntityAdditionalSpawnData)
{
tmpBuf = Unpooled.buffer();
((IEntityAdditionalSpawnData)entity).writeSpawnData(tmpBuf);
buf.writeBytes(tmpBuf);
}
}
示例2: spawnEntity
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; //导入依赖的package包/类
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);
}
}