Search in sources :

Example 91 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class ItemNotepad method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (Game.isClient(world))
        return EnumActionResult.SUCCESS;
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity != null) {
        if (// COPY
        player.isSneaking()) {
            EnumMap<Contents, NBTTagCompound> contents = new EnumMap<Contents, NBTTagCompound>(Contents.class);
            for (Contents contentType : Contents.VALUES) {
                NBTTagCompound data = contentType.copy(tileEntity);
                if (data != null)
                    contents.put(contentType, data);
            }
            if (contents.isEmpty()) {
                //TODO: Fix in 1.8 to use getDisplayName
                ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.copy.fail");
            } else {
                setContents(stack, contents);
                if (tileEntity instanceof IWorldNameable)
                    ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.copy", tileEntity.getDisplayName());
                stack.damageItem(1, player);
            }
        } else // PASTE
        {
            EnumMap<Contents, NBTTagCompound> contents = getContents(stack);
            if (contents.isEmpty()) {
                ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.empty");
            } else {
                PasteMode pasteMode = getPasteMode(stack);
                boolean pasted = false;
                for (Map.Entry<Contents, NBTTagCompound> entry : getContents(stack).entrySet()) {
                    if (pasteMode.allows(entry.getKey()))
                        pasted |= entry.getKey().paste(tileEntity, entry.getValue());
                }
                if (pasted) {
                    if (tileEntity instanceof IWorldNameable)
                        ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.paste", tileEntity.getDisplayName());
                } else
                    //TODO: Fix in 1.8 to use getDisplayName
                    ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.paste.fail");
            }
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldNameable(net.minecraft.world.IWorldNameable)

Example 92 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class ItemFocusBasic method setFocusUpgradeTagList.

private void setFocusUpgradeTagList(ItemStack focusstack, short[] upgrades) {
    if (!focusstack.hasTagCompound())
        focusstack.setTagCompound(new NBTTagCompound());
    NBTTagCompound nbttagcompound = focusstack.getTagCompound();
    NBTTagList tlist = new NBTTagList();
    nbttagcompound.setTag("upgrade", tlist);
    for (short id : upgrades) {
        NBTTagCompound f = new NBTTagCompound();
        f.setShort("id", id);
        tlist.appendTag(f);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 93 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class ItemPost method addInformation.

@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> info, boolean adv) {
    if (stack.getItemDamage() == EnumPost.EMBLEM.ordinal() && stack.hasTagCompound()) {
        NBTTagCompound nbt = stack.getTagCompound();
        NBTTagString emblemIdent = (NBTTagString) nbt.getTag("emblem");
        if (emblemIdent == null || EmblemToolsClient.packageManager == null)
            return;
        Emblem emblem = EmblemToolsClient.packageManager.getEmblem(emblemIdent.getString());
        if (emblem != null)
            info.add(TextFormatting.GRAY + emblem.displayName);
    }
}
Also used : Emblem(mods.railcraft.client.emblems.Emblem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 94 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class RailcraftTileEntity method getUpdateTag.

@Override
public final NBTTagCompound getUpdateTag() {
    NBTTagCompound nbt = super.getUpdateTag();
    ByteBuf byteBuf = Unpooled.buffer();
    try (ByteBufOutputStream out = new ByteBufOutputStream(byteBuf);
        RailcraftOutputStream data = new RailcraftOutputStream(out)) {
        writePacketData(data);
    } catch (IOException e) {
        Game.logThrowable("Error constructing tile packet: {0}", e, getClass());
        if (Game.DEVELOPMENT_ENVIRONMENT)
            throw new RuntimeException(e);
    }
    nbt.setByteArray("sync", byteBuf.array());
    return nbt;
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 95 with NBTTagCompound

use of net.minecraft.nbt.NBTTagCompound in project Railcraft by Railcraft.

the class InvTools method addNBTTag.

public static void addNBTTag(ItemStack stack, String key, String value) {
    NBTTagCompound nbt = getItemData(stack);
    nbt.setString(key, value);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3985 NBTTagList (net.minecraft.nbt.NBTTagList)1052 ItemStack (net.minecraft.item.ItemStack)883 BlockPos (net.minecraft.util.math.BlockPos)229 TileEntity (net.minecraft.tileentity.TileEntity)173 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)148 ArrayList (java.util.ArrayList)99 Block (net.minecraft.block.Block)98 ResourceLocation (net.minecraft.util.ResourceLocation)96 IBlockState (net.minecraft.block.state.IBlockState)92 EntityPlayer (net.minecraft.entity.player.EntityPlayer)81 NBTTagString (net.minecraft.nbt.NBTTagString)79 Nonnull (javax.annotation.Nonnull)74 Map (java.util.Map)71 UUID (java.util.UUID)69 NBTBase (net.minecraft.nbt.NBTBase)66 HashMap (java.util.HashMap)64 EnumFacing (net.minecraft.util.EnumFacing)61 NotNull (org.jetbrains.annotations.NotNull)60 Item (net.minecraft.item.Item)55