本文整理匯總了Java中net.minecraft.entity.Entity.readFromNBT方法的典型用法代碼示例。如果您正苦於以下問題:Java Entity.readFromNBT方法的具體用法?Java Entity.readFromNBT怎麽用?Java Entity.readFromNBT使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.entity.Entity
的用法示例。
在下文中一共展示了Entity.readFromNBT方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: onTooltip
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
@SubscribeEvent
public void onTooltip(RenderTooltipEvent.PostText event) {
if (event.getStack() == null || event.getStack().isEmpty()) return;
if (event.getStack().getItem() instanceof MobImprisonmentToolItem && ((MobImprisonmentToolItem) event.getStack().getItem()).containsEntity(event.getStack())) {
try {
Entity entity = EntityList.createEntityByID(event.getStack().getTagCompound().getInteger("id"), Minecraft.getMinecraft().world);
entity.readFromNBT(event.getStack().getTagCompound());
ItemStackUtils.renderEntity((int) (event.getX() + 15 + entity.width), (int) (event.getY() + 58 + entity.height), 15, 0, 0, (EntityLivingBase) entity);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
示例3: onPlayerTick
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event)
{
if(event.player.world.isRemote)
for(Entity e : event.player.world.getLoadedEntityList())
if(ENTITY_MAP.containsKey(e.getEntityId()))
{
e.readFromNBT(ENTITY_MAP.get(e.getEntityId()));
ENTITY_MAP.remove(e.getEntityId());
}
}
示例4: getEntityFromStack
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
public Entity getEntityFromStack(ItemStack stack, World world, boolean withInfo) {
Entity entity = EntityList.createEntityByIDFromName(new ResourceLocation(stack.getTagCompound().getString("entity")), world);
if (withInfo) entity.readFromNBT(stack.getTagCompound());
return entity;
}
示例5: spawnNewEntity
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
private Entity spawnNewEntity(Entity entityIn, boolean spawn)
{
if (this.getRandomEntity() != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
entityIn.writeToNBTOptional(nbttagcompound);
for (String s : this.getRandomEntity().nbtData.getKeySet())
{
NBTBase nbtbase = this.getRandomEntity().nbtData.getTag(s);
nbttagcompound.setTag(s, nbtbase.copy());
}
entityIn.readFromNBT(nbttagcompound);
if (entityIn.worldObj != null && spawn)
{
entityIn.worldObj.spawnEntityInWorld(entityIn);
}
NBTTagCompound nbttagcompound2;
for (Entity entity = entityIn; nbttagcompound.hasKey("Riding", 10); nbttagcompound = nbttagcompound2)
{
nbttagcompound2 = nbttagcompound.getCompoundTag("Riding");
Entity entity1 = EntityList.createEntityByName(nbttagcompound2.getString("id"), entityIn.worldObj);
if (entity1 != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
entity1.writeToNBTOptional(nbttagcompound1);
for (String s1 : nbttagcompound2.getKeySet())
{
NBTBase nbtbase1 = nbttagcompound2.getTag(s1);
nbttagcompound1.setTag(s1, nbtbase1.copy());
}
entity1.readFromNBT(nbttagcompound1);
entity1.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
if (entityIn.worldObj != null && spawn)
{
entityIn.worldObj.spawnEntityInWorld(entity1);
}
entity.mountEntity(entity1);
}
entity = entity1;
}
}
else if (entityIn instanceof EntityLivingBase && entityIn.worldObj != null && spawn)
{
if (entityIn instanceof EntityLiving)
{
((EntityLiving)entityIn).onInitialSpawn(entityIn.worldObj.getDifficultyForLocation(new BlockPos(entityIn)), (IEntityLivingData)null);
}
entityIn.worldObj.spawnEntityInWorld(entityIn);
}
return entityIn;
}
示例6: processCommand
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
/**
* Callback when the command is invoked
*/
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 2)
{
throw new WrongUsageException("commands.entitydata.usage", new Object[0]);
}
else
{
Entity entity = func_175768_b(sender, args[0]);
if (entity instanceof EntityPlayer)
{
throw new CommandException("commands.entitydata.noPlayers", new Object[] {entity.getDisplayName()});
}
else
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
entity.writeToNBT(nbttagcompound);
NBTTagCompound nbttagcompound1 = (NBTTagCompound)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()});
}
nbttagcompound2.removeTag("UUIDMost");
nbttagcompound2.removeTag("UUIDLeast");
nbttagcompound.merge(nbttagcompound2);
if (nbttagcompound.equals(nbttagcompound1))
{
throw new CommandException("commands.entitydata.failed", new Object[] {nbttagcompound.toString()});
}
else
{
entity.readFromNBT(nbttagcompound);
notifyOperators(sender, this, "commands.entitydata.success", new Object[] {nbttagcompound.toString()});
}
}
}
}
示例7: 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()});
}
}
}
}
示例8: getCollisionBox
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
@Override
public AxisAlignedBB getCollisionBox(Entity entityIn) {
if (!this.world.isRemote && !this.isExit() && this.getTPprogress() <= 0 && entityIn != null
&& entityIn instanceof EntityLivingBase && !(entityIn instanceof EntityBuilding)
&& ((this.getOwner() != null && ((WeaponsCapability.get(this.getOwner()).teleporterEntity && !(entityIn instanceof EntityPlayer)) ||
(WeaponsCapability.get(this.getOwner()).teleporterPlayer && entityIn instanceof EntityPlayer && entityIn.getTeam() == null)))
|| TF2Util.isOnSameTeam(EntityTeleporter.this, entityIn))
&& entityIn.getEntityBoundingBox()
.intersects(this.getEntityBoundingBox().grow(0, 0.5, 0).offset(0, 0.5D, 0)))
if (ticksToTeleport <= 0)
if (ticksToTeleport < 0)
ticksToTeleport = 10;
else {
TeleporterData exit = this.getTeleportExit();
if (exit != null) {
if (exit.dimension != this.dimension) {
if(entityIn instanceof EntityPlayerMP && net.minecraftforge.common.ForgeHooks.onTravelToDimension(this, exit.dimension)) {
this.world.getMinecraftServer().getPlayerList().transferPlayerToDimension((EntityPlayerMP) entityIn,
exit.dimension, new TeleporterDim((WorldServer) this.world,exit));
}
else {
World destworld = this.world.getMinecraftServer().getWorld(exit.dimension);
Entity newent = EntityList.newEntity(entityIn.getClass(), destworld);
if(newent != null) {
NBTTagCompound data = entityIn.writeToNBT(new NBTTagCompound());
data.removeTag("Dimension");
newent.readFromNBT(data);
entityIn.setDead();
newent.forceSpawn = true;
entityIn.moveToBlockPosAndAngles(exit, entityIn.rotationYaw, entityIn.rotationPitch);
destworld.spawnEntity(newent);
entityIn = newent;
}
}
}
entityIn.setPositionAndUpdate(exit.getX() + 0.5, exit.getY() + 0.23, exit.getZ() + 0.5);
this.setTeleports(this.getTeleports() + 1);
this.setTPprogress(this.getLevel() == 1 ? 200 : (this.getLevel() == 2 ? 100 : 60));
this.playSound(TF2Sounds.MOB_TELEPORTER_SEND, 1.5f, 1f);
entityIn.playSound(TF2Sounds.MOB_TELEPORTER_RECEIVE, 0.75f, 1f);
if(this.getOwner() instanceof EntityPlayerMP){
((EntityPlayer) this.getOwner()).addStat(TF2Achievements.TELEPORTED);
/*if(((EntityPlayerMP) this.getOwner()).getStatFile().readStat(TF2Achievements.TELEPORTED)>=100)
((EntityPlayer) this.getOwner()).addStat(TF2Achievements.TELEPORTS);*/
}
}
}
return super.getCollisionBox(entityIn);
}
示例9: giveMerch
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
@Override
public void giveMerch ( EntityPlayerMP serverPlayer, Merch merch, int amount ) {
EntityInfo info = ( EntityInfo ) merch ;
if ( info . limit != -1 ) {
if ( info . limit < amount ) {
MineDonate . logError ( "Buy error, amount[" + amount +"] > info[" + info . toString ( ) + "].limit[" + info . limit + "]" ) ;
return ;
}
info . limit -= amount ;
updateEntityInfo ( info ) ;
}
try {
Entity entity = (Entity) Class.forName(info.classpath).getDeclaredConstructor(net.minecraft.world.World.class).newInstance(serverPlayer.getEntityWorld());
entity.readFromNBT(info.entity_data);
entity.setLocationAndAngles(serverPlayer.posX, serverPlayer.posY, serverPlayer.posZ, serverPlayer.rotationYaw, serverPlayer.rotationPitch);
serverPlayer.getEntityWorld().spawnEntityInWorld(entity);
} catch ( Exception ex ) {
ex . printStackTrace ( ) ;
}
}