本文整理汇总了Java中net.minecraft.entity.Entity.setUniqueId方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.setUniqueId方法的具体用法?Java Entity.setUniqueId怎么用?Java Entity.setUniqueId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.Entity
的用法示例。
在下文中一共展示了Entity.setUniqueId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyItemEntityDataToEntity
import net.minecraft.entity.Entity; //导入方法依赖的package包/类
/**
* Applies the data in the EntityTag tag of the given ItemStack to the given Entity.
*/
public static void applyItemEntityDataToEntity(World entityWorld, @Nullable EntityPlayer player, ItemStack stack, @Nullable Entity targetEntity)
{
MinecraftServer minecraftserver = entityWorld.getMinecraftServer();
if (minecraftserver != null && targetEntity != null)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound != null && nbttagcompound.hasKey("EntityTag", 10))
{
if (!entityWorld.isRemote && targetEntity.ignoreItemEntityData() && (player == null || !minecraftserver.getPlayerList().canSendCommands(player.getGameProfile())))
{
return;
}
NBTTagCompound nbttagcompound1 = targetEntity.writeToNBT(new NBTTagCompound());
UUID uuid = targetEntity.getUniqueID();
nbttagcompound1.merge(nbttagcompound.getCompoundTag("EntityTag"));
targetEntity.setUniqueId(uuid);
targetEntity.readFromNBT(nbttagcompound1);
}
}
}
示例2: execute
import net.minecraft.entity.Entity; //导入方法依赖的package包/类
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.entitydata.usage", new Object[0]);
}
else
{
Entity entity = getEntity(server, sender, args[0]);
if (entity instanceof EntityPlayer)
{
throw new CommandException("commands.entitydata.noPlayers", new Object[] {entity.getDisplayName()});
}
else
{
NBTTagCompound nbttagcompound = entityToNBT(entity);
NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
NBTTagCompound nbttagcompound2;
try
{
nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 1).getUnformattedText());
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.entitydata.tagError", new Object[] {nbtexception.getMessage()});
}
UUID uuid = entity.getUniqueID();
nbttagcompound.merge(nbttagcompound2);
entity.setUniqueId(uuid);
if (nbttagcompound.equals(nbttagcompound1))
{
throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
}
else
{
entity.readFromNBT(nbttagcompound);
notifyCommandListener(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound.toString()});
}
}
}
}
示例3: spawnEntity
import net.minecraft.entity.Entity; //导入方法依赖的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);
}
}