当前位置: 首页>>代码示例>>Java>>正文


Java TileEntity.writeToNBT方法代码示例

本文整理汇总了Java中net.minecraft.tileentity.TileEntity.writeToNBT方法的典型用法代码示例。如果您正苦于以下问题:Java TileEntity.writeToNBT方法的具体用法?Java TileEntity.writeToNBT怎么用?Java TileEntity.writeToNBT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.tileentity.TileEntity的用法示例。


在下文中一共展示了TileEntity.writeToNBT方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CraftBlockState

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.light = block.getLightLevel();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;
    // Cauldron start - save TE data
    TileEntity te = world.getHandle().getTileEntity(x, y, z);
    if (te != null)
    {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    }
    else nbt = null;
    // Cauldron end

    createData(block.getData());
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:22,代码来源:CraftBlockState.java

示例2: dropBlockAsItemWithChance

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * Spawns this Block's drops into the World as EntityItems.
 */
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof TileEntityBanner)
    {
        ItemStack itemstack = new ItemStack(Items.banner, 1, ((TileEntityBanner)tileentity).getBaseColor());
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        tileentity.writeToNBT(nbttagcompound);
        nbttagcompound.removeTag("x");
        nbttagcompound.removeTag("y");
        nbttagcompound.removeTag("z");
        nbttagcompound.removeTag("id");
        itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
        spawnAsEntity(worldIn, pos, itemstack);
    }
    else
    {
        super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:25,代码来源:BlockBanner.java

示例3: func_181036_a

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private ItemStack func_181036_a(Item p_181036_1_, int p_181036_2_, TileEntity p_181036_3_)
{
    ItemStack itemstack = new ItemStack(p_181036_1_, 1, p_181036_2_);
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    p_181036_3_.writeToNBT(nbttagcompound);

    if (p_181036_1_ == Items.skull && nbttagcompound.hasKey("Owner"))
    {
        NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
        NBTTagCompound nbttagcompound3 = new NBTTagCompound();
        nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
        itemstack.setTagCompound(nbttagcompound3);
        return itemstack;
    }
    else
    {
        itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        NBTTagList nbttaglist = new NBTTagList();
        nbttaglist.appendTag(new NBTTagString("(+NBT)"));
        nbttagcompound1.setTag("Lore", nbttaglist);
        itemstack.setTagInfo("display", nbttagcompound1);
        return itemstack;
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:26,代码来源:Minecraft.java

示例4: compressAsArray

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private BlockArray compressAsArray(World world, BlockPos center) {
    BlockArray out = new BlockArray();
    for (BlockPos pos : this.selectedPositions) {
        IBlockState state = world.getBlockState(pos);
        BlockArray.IBlockStateDescriptor descr = new BlockArray.IBlockStateDescriptor(state);
        BlockArray.BlockInformation bi = new BlockArray.BlockInformation(Lists.newArrayList(descr));
        TileEntity te = world.getTileEntity(pos);
        if(te != null) {
            NBTTagCompound cmp = new NBTTagCompound();
            te.writeToNBT(cmp);

            cmp.removeTag("x");
            cmp.removeTag("y");
            cmp.removeTag("z");

            bi.setMatchingTag(cmp);
        }
        out.addBlock(pos.subtract(center), bi);
    }
    return out;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:22,代码来源:PlayerStructureSelectionHelper.java

示例5: getNBTData

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos)
{
    if (te != null)
        te.writeToNBT(tag);
    return tag;
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:8,代码来源:WailaCS4DataProvider.java

示例6: getTileTag

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * Get tile entity as NBT tag
 * @param pos Block position over tile entity
 * @return Serialized to NBT tag tile entity
 */
public NBTTagCompound getTileTag(UBlockPos pos) {
    TileEntity tile = getTileEntity(pos);
    if (tile == null) {
        return null;
    }
    NBTTagCompound tag = new NBTTagCompound();
    tile.writeToNBT(tag);
    return tag;
}
 
开发者ID:ternsip,项目名称:StructPro,代码行数:15,代码来源:UWorld.java

示例7: matches

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public boolean matches(World world, BlockPos at, boolean default_) {
    if(!world.isBlockLoaded(at)) {
        return default_;
    }

    if(matchingTag != null) {
        TileEntity te = world.getTileEntity(at);
        if(te != null && matchingTag.getSize() > 0) {
            NBTTagCompound cmp = new NBTTagCompound();
            te.writeToNBT(cmp);
            if(!NBTMatchingHelper.matchNBTCompound(matchingTag, cmp)) {
                return false; //No match at this position.
            }
        }
    }

    IBlockState state = world.getBlockState(at);
    Block atBlock = state.getBlock();
    int atMeta = atBlock.getMetaFromState(state);

    for (IBlockStateDescriptor descriptor : matchingStates) {
        for (IBlockState applicable : descriptor.applicable) {
            Block type = applicable.getBlock();
            int meta = type.getMetaFromState(applicable);
            if(type.equals(state.getBlock()) && meta == atMeta) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:32,代码来源:BlockArray.java

示例8: grabChest

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
private void grabChest(TransportableChest chest, ItemStack stack, EntityPlayer player, World world, BlockPos pos)
{
    TileEntity tile = world.getTileEntity(pos);
    if (tile != null)
    {
        IBlockState iblockstate = world.getBlockState(pos);
        Block chestBlock = iblockstate.getBlock();

        getTagCompound(stack).setString("ChestName", chest.getRegistryName().toString());
        if (chest.copyTileEntity())
        {
            NBTTagCompound nbt = new NBTTagCompound();
            tile.writeToNBT(nbt);
            getTagCompound(stack).setTag("ChestTile", nbt);
            world.removeTileEntity(pos);
        } else
        {
            IInventory inv = (IInventory) tile;
            moveItemsIntoStack(inv, stack);
        }

        chest.preRemoveChest(world, pos, player, stack);

        world.setBlockToAir(pos);
        SoundType soundType = chestBlock.getSoundType();
        world.playSound(player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
    }
}
 
开发者ID:cubex2,项目名称:chesttransporter,代码行数:29,代码来源:ItemChestTransporter.java

示例9: placeBlock

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public boolean placeBlock(BlockPos blockpos) {
	Block block = this.block.getBlock();
	IBlockState prevstate=this.world.getBlockState(blockpos);
	if (!this.isBreakingAnvil
			&& this.world.mayPlace(block, blockpos, true, EnumFacing.UP, (Entity) null)
			&& (!BlockFalling.canFallThrough(this.world.getBlockState(blockpos.offset(EnumFacing.DOWN)))
					|| (this.sticky == 1 && this.canBuildAt(blockpos)) || this.nogravity)
			&& this.world.setBlockState(blockpos, this.block, 3)) {
		if (this.isFired)
			for (int a = 0; a < 6; a++) {
				EnumFacing facing = EnumFacing.VALUES[a];
				BlockPos firepos = new BlockPos(blockpos.getX() + facing.getFrontOffsetX(),
						blockpos.getY() + facing.getFrontOffsetY(), blockpos.getZ() + facing.getFrontOffsetZ());
				if (this.world.getBlockState(firepos).getBlock().isReplaceable(world, firepos))
					this.world.setBlockState(firepos, this.fireBlock.getDefaultState());
			}
		if (block instanceof BlockFalling)
			((BlockFalling) block).onEndFalling(this.world, blockpos, this.block, prevstate);

		if (this.dataTag != null && block instanceof ITileEntityProvider) {
			TileEntity tileentity = this.world.getTileEntity(blockpos);

			if (tileentity != null) {
				NBTTagCompound nbttagcompound = new NBTTagCompound();
				tileentity.writeToNBT(nbttagcompound);
				Iterator iterator = this.dataTag.getKeySet().iterator();

				while (iterator.hasNext()) {
					String s = (String) iterator.next();
					NBTBase nbtbase = this.dataTag.getTag(s);

					if (!s.equals("x") && !s.equals("y") && !s.equals("z"))
						nbttagcompound.setTag(s, nbtbase.copy());
				}

				tileentity.readFromNBT(nbttagcompound);
				tileentity.markDirty();
			}
		}
		return true;
	}
	return false;
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:44,代码来源:EntityFallingEnchantedBlock.java

示例10: execute

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:65,代码来源:CommandBlockData.java

示例11: takeBlocksFromWorld

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * takes blocks from the world and puts the data them into this template
 */
public void takeBlocksFromWorld(World worldIn, BlockPos actualPosition, BlockPos startPos, BlockPos endPos, boolean takeEntities, @Nullable Block toIgnore)
{
    if (endPos.getX() >= 1 && endPos.getY() >= 1 && endPos.getZ() >= 1)
    {
        BlockPos blockpos = startPos.add(endPos).add(-1, -1, -1);
        List<Template.BlockInfo> list = Lists.<Template.BlockInfo>newArrayList();
        List<Template.BlockInfo> list1 = Lists.<Template.BlockInfo>newArrayList();
        List<Template.BlockInfo> list2 = Lists.<Template.BlockInfo>newArrayList();
        BlockPos blockpos1 = new BlockPos(Math.min(startPos.getX(), blockpos.getX()), Math.min(startPos.getY(), blockpos.getY()), Math.min(startPos.getZ(), blockpos.getZ()));
        BlockPos blockpos2 = new BlockPos(Math.max(startPos.getX(), blockpos.getX()), Math.max(startPos.getY(), blockpos.getY()), Math.max(startPos.getZ(), blockpos.getZ()));
        this.size = endPos;
        this.pos = actualPosition;

        for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos1, blockpos2))
        {
            BlockPos blockpos3 = blockpos$mutableblockpos.subtract(blockpos1);
            IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos);

            if (toIgnore == null || toIgnore != iblockstate.getBlock())
            {
                TileEntity tileentity = worldIn.getTileEntity(blockpos$mutableblockpos);

                if (tileentity != null)
                {
                    NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                    nbttagcompound.removeTag("x");
                    nbttagcompound.removeTag("y");
                    nbttagcompound.removeTag("z");
                    list1.add(new Template.BlockInfo(blockpos3, iblockstate, nbttagcompound));
                }
                else if (!iblockstate.isFullBlock() && !iblockstate.isFullCube())
                {
                    list2.add(new Template.BlockInfo(blockpos3, iblockstate, (NBTTagCompound)null));
                }
                else
                {
                    list.add(new Template.BlockInfo(blockpos3, iblockstate, (NBTTagCompound)null));
                }
            }
        }

        this.blocks.clear();
        this.blocks.addAll(list);
        this.blocks.addAll(list1);
        this.blocks.addAll(list2);

        if (takeEntities)
        {
            this.takeEntitiesFromWorld(worldIn, blockpos1, blockpos2.add(1, 1, 1));
        }
        else
        {
            this.entities.clear();
        }
    }
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:60,代码来源:HarshenTemplate.java

示例12: processCommand

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                tileentity.writeToNBT(nbttagcompound);
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.markBlockForUpdate(blockpos);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyOperators(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:65,代码来源:CommandBlockData.java

示例13: processCreativeInventoryAction

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * Update the server with an ItemStack in a slot.
 */
public void processCreativeInventoryAction(C10PacketCreativeInventoryAction packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());

    if (this.playerEntity.theItemInWorldManager.isCreative())
    {
        boolean flag = packetIn.getSlotId() < 0;
        ItemStack itemstack = packetIn.getStack();

        if (itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("BlockEntityTag", 10))
        {
            NBTTagCompound nbttagcompound = itemstack.getTagCompound().getCompoundTag("BlockEntityTag");

            if (nbttagcompound.hasKey("x") && nbttagcompound.hasKey("y") && nbttagcompound.hasKey("z"))
            {
                BlockPos blockpos = new BlockPos(nbttagcompound.getInteger("x"), nbttagcompound.getInteger("y"), nbttagcompound.getInteger("z"));
                TileEntity tileentity = this.playerEntity.worldObj.getTileEntity(blockpos);

                if (tileentity != null)
                {
                    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                    tileentity.writeToNBT(nbttagcompound1);
                    nbttagcompound1.removeTag("x");
                    nbttagcompound1.removeTag("y");
                    nbttagcompound1.removeTag("z");
                    itemstack.setTagInfo("BlockEntityTag", nbttagcompound1);
                }
            }
        }

        boolean flag1 = packetIn.getSlotId() >= 1 && packetIn.getSlotId() < 36 + InventoryPlayer.getHotbarSize();
        boolean flag2 = itemstack == null || itemstack.getItem() != null;
        boolean flag3 = itemstack == null || itemstack.getMetadata() >= 0 && itemstack.stackSize <= 64 && itemstack.stackSize > 0;

        if (flag1 && flag2 && flag3)
        {
            if (itemstack == null)
            {
                this.playerEntity.inventoryContainer.putStackInSlot(packetIn.getSlotId(), (ItemStack)null);
            }
            else
            {
                this.playerEntity.inventoryContainer.putStackInSlot(packetIn.getSlotId(), itemstack);
            }

            this.playerEntity.inventoryContainer.setCanCraft(this.playerEntity, true);
        }
        else if (flag && flag2 && flag3 && this.itemDropThreshold < 200)
        {
            this.itemDropThreshold += 20;
            EntityItem entityitem = this.playerEntity.dropPlayerItemWithRandomChoice(itemstack, true);

            if (entityitem != null)
            {
                entityitem.setAgeToCreativeDespawnTime();
            }
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:63,代码来源:NetHandlerPlayServer.java

示例14: takeBlocksFromWorld

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
/**
 * takes blocks from the world and puts the data them into this template
 */
public void takeBlocksFromWorld(World worldIn, BlockPos startPos, BlockPos endPos, boolean takeEntities, @Nullable Block toIgnore)
{
    if (endPos.getX() >= 1 && endPos.getY() >= 1 && endPos.getZ() >= 1)
    {
        BlockPos blockpos = startPos.add(endPos).add(-1, -1, -1);
        List<Template.BlockInfo> list = Lists.<Template.BlockInfo>newArrayList();
        List<Template.BlockInfo> list1 = Lists.<Template.BlockInfo>newArrayList();
        List<Template.BlockInfo> list2 = Lists.<Template.BlockInfo>newArrayList();
        BlockPos blockpos1 = new BlockPos(Math.min(startPos.getX(), blockpos.getX()), Math.min(startPos.getY(), blockpos.getY()), Math.min(startPos.getZ(), blockpos.getZ()));
        BlockPos blockpos2 = new BlockPos(Math.max(startPos.getX(), blockpos.getX()), Math.max(startPos.getY(), blockpos.getY()), Math.max(startPos.getZ(), blockpos.getZ()));
        this.size = endPos;

        for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos1, blockpos2))
        {
            BlockPos blockpos3 = blockpos$mutableblockpos.subtract(blockpos1);
            IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos);

            if (toIgnore == null || toIgnore != iblockstate.getBlock())
            {
                TileEntity tileentity = worldIn.getTileEntity(blockpos$mutableblockpos);

                if (tileentity != null)
                {
                    NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                    nbttagcompound.removeTag("x");
                    nbttagcompound.removeTag("y");
                    nbttagcompound.removeTag("z");
                    list1.add(new Template.BlockInfo(blockpos3, iblockstate, nbttagcompound));
                }
                else if (!iblockstate.isFullBlock() && !iblockstate.isFullCube())
                {
                    list2.add(new Template.BlockInfo(blockpos3, iblockstate, (NBTTagCompound)null));
                }
                else
                {
                    list.add(new Template.BlockInfo(blockpos3, iblockstate, (NBTTagCompound)null));
                }
            }
        }

        this.blocks.clear();
        this.blocks.addAll(list);
        this.blocks.addAll(list1);
        this.blocks.addAll(list2);

        if (takeEntities)
        {
            this.takeEntitiesFromWorld(worldIn, blockpos1, blockpos2.add(1, 1, 1));
        }
        else
        {
            this.entities.clear();
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:59,代码来源:Template.java

示例15: setTileEntityNBT

import net.minecraft.tileentity.TileEntity; //导入方法依赖的package包/类
public static boolean setTileEntityNBT(World worldIn, EntityPlayer pos, BlockPos stack, ItemStack p_179224_3_)
{
    MinecraftServer minecraftserver = MinecraftServer.getServer();

    if (minecraftserver == null)
    {
        return false;
    }
    else
    {
        if (p_179224_3_.hasTagCompound() && p_179224_3_.getTagCompound().hasKey("BlockEntityTag", 10))
        {
            TileEntity tileentity = worldIn.getTileEntity(stack);

            if (tileentity != null)
            {
                if (!worldIn.isRemote && tileentity.func_183000_F() && !minecraftserver.getConfigurationManager().canSendCommands(pos.getGameProfile()))
                {
                    return false;
                }

                NBTTagCompound nbttagcompound = new NBTTagCompound();
                NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
                tileentity.writeToNBT(nbttagcompound);
                NBTTagCompound nbttagcompound2 = (NBTTagCompound)p_179224_3_.getTagCompound().getTag("BlockEntityTag");
                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", stack.getX());
                nbttagcompound.setInteger("y", stack.getY());
                nbttagcompound.setInteger("z", stack.getZ());

                if (!nbttagcompound.equals(nbttagcompound1))
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    return true;
                }
            }
        }

        return false;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:43,代码来源:ItemBlock.java


注:本文中的net.minecraft.tileentity.TileEntity.writeToNBT方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。