本文整理匯總了Java中net.minecraft.entity.Entity.writeToNBT方法的典型用法代碼示例。如果您正苦於以下問題:Java Entity.writeToNBT方法的具體用法?Java Entity.writeToNBT怎麽用?Java Entity.writeToNBT使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.entity.Entity
的用法示例。
在下文中一共展示了Entity.writeToNBT方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: entityToNBT
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
protected static NBTTagCompound entityToNBT(Entity theEntity)
{
NBTTagCompound nbttagcompound = theEntity.writeToNBT(new NBTTagCompound());
if (theEntity instanceof EntityPlayer)
{
ItemStack itemstack = ((EntityPlayer)theEntity).inventory.getCurrentItem();
if (!itemstack.func_190926_b())
{
nbttagcompound.setTag("SelectedItem", itemstack.writeToNBT(new NBTTagCompound()));
}
}
return nbttagcompound;
}
示例3: entityToNBT
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
protected static NBTTagCompound entityToNBT(Entity theEntity)
{
NBTTagCompound nbttagcompound = theEntity.writeToNBT(new NBTTagCompound());
if (theEntity instanceof EntityPlayer)
{
ItemStack itemstack = ((EntityPlayer)theEntity).inventory.getCurrentItem();
if (itemstack != null && itemstack.getItem() != null)
{
nbttagcompound.setTag("SelectedItem", itemstack.writeToNBT(new NBTTagCompound()));
}
}
return nbttagcompound;
}
示例4: checkBoundingBoxSize
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
public static boolean checkBoundingBoxSize(Entity entity, AxisAlignedBB aabb)
{
if (entity instanceof EntityLivingBase && (!(entity instanceof IBossDisplayData) || !(entity instanceof IEntityMultiPart))
&& !(entity instanceof EntityPlayer))
{
int logSize = MinecraftServer.cauldronConfig.largeBoundingBoxLogSize.getValue();
if (logSize <= 0 || !MinecraftServer.cauldronConfig.checkEntityBoundingBoxes.getValue()) return false;
int x = MathHelper.floor_double(aabb.minX);
int x1 = MathHelper.floor_double(aabb.maxX + 1.0D);
int y = MathHelper.floor_double(aabb.minY);
int y1 = MathHelper.floor_double(aabb.maxY + 1.0D);
int z = MathHelper.floor_double(aabb.minZ);
int z1 = MathHelper.floor_double(aabb.maxZ + 1.0D);
int size = Math.abs(x1 - x) * Math.abs(y1 - y) * Math.abs(z1 - z);
if (size > MinecraftServer.cauldronConfig.largeBoundingBoxLogSize.getValue())
{
logWarning("Entity being removed for bounding box restrictions");
logWarning("BB Size: {0} > {1} avg edge: {2}", size, logSize, aabb.getAverageEdgeLength());
logWarning("Motion: ({0}, {1}, {2})", entity.motionX, entity.motionY, entity.motionZ);
logWarning("Calculated bounding box: {0}", aabb);
logWarning("Entity bounding box: {0}", entity.getBoundingBox());
logWarning("Entity: {0}", entity);
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
logWarning("Entity NBT: {0}", tag);
logStack();
entity.setDead();
return true;
}
}
return false;
}
示例5: EntityInfo
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
public EntityInfo(int _shopId, int _catId, int merch_id, int _rating, int cost, Entity entity, String name, int limit) {
super(_shopId, _catId, merch_id, _rating);
this.cost = cost;
this.entity_data = new NBTTagCompound();
entity.writeToNBT(entity_data);
this.name = name;
this.classpath = entity.getClass().getName();
entity_data.setString("classpath", this.classpath);
this.limit = limit;
}
示例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 < 1)
{
throw new WrongUsageException("commands.testfor.usage", new Object[0]);
}
else
{
Entity entity = func_175768_b(sender, args[0]);
NBTTagCompound nbttagcompound = null;
if (args.length >= 2)
{
try
{
nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
}
}
if (nbttagcompound != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
entity.writeToNBT(nbttagcompound1);
if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
{
throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
}
}
notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
}
}
示例7: checkEntitySpeed
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
public static boolean checkEntitySpeed(Entity entity, double x, double y, double z)
{
int maxSpeed = MinecraftServer.cauldronConfig.entityMaxSpeed.getValue();
if (maxSpeed > 0 && MinecraftServer.cauldronConfig.checkEntityMaxSpeeds.getValue())
{
double distance = x * x + z * z;
if (distance > maxSpeed)
{
if (MinecraftServer.cauldronConfig.logEntitySpeedRemoval.getValue())
{
logInfo("Speed violation: {0} was over {1} - Removing Entity: {2}", distance, maxSpeed, entity);
if (entity instanceof EntityLivingBase)
{
EntityLivingBase livingBase = (EntityLivingBase)entity;
logInfo("Entity Motion: ({0}, {1}, {2}) Move Strafing: {3} Move Forward: {4}", entity.motionX, entity.motionY, entity.motionZ, livingBase.moveStrafing, livingBase.moveForward);
}
if (MinecraftServer.cauldronConfig.logWithStackTraces.getValue())
{
logInfo("Move offset: ({0}, {1}, {2})", x, y, z);
logInfo("Motion: ({0}, {1}, {2})", entity.motionX, entity.motionY, entity.motionZ);
logInfo("Entity: {0}", entity);
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
logInfo("Entity NBT: {0}", tag);
logStack();
}
}
if (entity instanceof EntityPlayer) // Skip killing players
{
entity.motionX = 0;
entity.motionY = 0;
entity.motionZ = 0;
return false;
}
// Remove the entity;
entity.isDead = true;
return false;
}
}
return true;
}
示例8: 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()});
}
}
}
}
示例9: setPlayer
import net.minecraft.entity.Entity; //導入方法依賴的package包/類
protected void setPlayer(ICommandSender p_147197_1_, String[] p_147197_2_, int p_147197_3_) throws CommandException
{
String s = p_147197_2_[p_147197_3_ - 1];
int i = p_147197_3_;
String s1 = getEntityName(p_147197_1_, p_147197_2_[p_147197_3_++]);
if (s1.length() > 40)
{
throw new SyntaxErrorException("commands.scoreboard.players.name.tooLong", new Object[] {s1, Integer.valueOf(40)});
}
else
{
ScoreObjective scoreobjective = this.getObjective(p_147197_2_[p_147197_3_++], true);
int j = s.equalsIgnoreCase("set") ? parseInt(p_147197_2_[p_147197_3_++]) : parseInt(p_147197_2_[p_147197_3_++], 0);
if (p_147197_2_.length > p_147197_3_)
{
Entity entity = func_175768_b(p_147197_1_, p_147197_2_[i]);
try
{
NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(buildString(p_147197_2_, p_147197_3_));
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
entity.writeToNBT(nbttagcompound1);
if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
{
throw new CommandException("commands.scoreboard.players.set.tagMismatch", new Object[] {s1});
}
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.scoreboard.players.set.tagError", new Object[] {nbtexception.getMessage()});
}
}
Scoreboard scoreboard = this.getScoreboard();
Score score = scoreboard.getValueFromObjective(s1, scoreobjective);
if (s.equalsIgnoreCase("set"))
{
score.setScorePoints(j);
}
else if (s.equalsIgnoreCase("add"))
{
score.increseScore(j);
}
else
{
score.decreaseScore(j);
}
notifyOperators(p_147197_1_, this, "commands.scoreboard.players.set.success", new Object[] {scoreobjective.getName(), s1, Integer.valueOf(score.getScorePoints())});
}
}
示例10: 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);
}