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;
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations