本文整理匯總了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);
}
}