當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。