Java Code Examples for net.minecraft.item.ItemStack#setTagCompound()
The following examples show how to use
net.minecraft.item.ItemStack#setTagCompound() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemPartFrame.java From Framez with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void getSubItems(Item i, CreativeTabs t, List l) { for (List<IFrameModifier> mods : FrameModifierRegistry.instance().getAllCombinations(PartFrame.class)) { NBTTagList tagList = new NBTTagList(); for (IFrameModifier mod : mods) tagList.appendTag(new NBTTagString(mod.getType())); NBTTagCompound tag = new NBTTagCompound(); tag.setTag("modifiers", tagList); ItemStack is = new ItemStack(this); is.setTagCompound(tag); l.add(is); } }
Example 2
Source File: ItemQuantumComputer.java From qcraft-mod with Apache License 2.0 | 6 votes |
public static void setStoredData( ItemStack stack, TileEntityQuantumComputer.AreaData data ) { // Ensure the nbt if( !stack.hasTagCompound() ) { stack.setTagCompound( new NBTTagCompound() ); } // Set the tags NBTTagCompound nbt = stack.getTagCompound(); if( data != null ) { nbt.setTag( "d", data.encode() ); } else { if( nbt.hasKey( "d" ) ) { nbt.removeTag( "d" ); } } }
Example 3
Source File: BlockWrathCage.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 6 votes |
@Override public void onBlockPreDestroy(World world, int x, int y, int z, int side) { TileEntityWrathCage spawner = (TileEntityWrathCage) world.getTileEntity(x, y, z); if (spawner != null && spawner.getSpawnerLogic().isMobSet()) { float f = world.rand.nextFloat() * 0.8F + 0.1F; float f1 = world.rand.nextFloat() * 0.8F + 0.1F; float f2 = world.rand.nextFloat() * 0.8F + 0.1F; ItemStack crystal = new ItemStack(ForbiddenItems.mobCrystal); crystal.setTagCompound(new NBTTagCompound()); String mob = spawner.getSpawnerLogic().getEntityNameToSpawn(); crystal.stackTagCompound.setString("mob", mob); EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), crystal); entityitem.motionX = (double) ((float) world.rand.nextGaussian() * 0.05F); entityitem.motionY = (double) ((float) world.rand.nextGaussian() * 0.05F + 0.2F); entityitem.motionZ = (double) ((float) world.rand.nextGaussian() * 0.05F); world.spawnEntityInWorld(entityitem); } super.onBlockPreDestroy(world, x, y, z, side); }
Example 4
Source File: TileChipStorage.java From AdvancedRocketry with MIT License | 5 votes |
@Override protected void processComplete() { super.processComplete(); ItemStack stack0 = getStackInSlot(0); ItemStack stack1 = getStackInSlot(1); stack1.setTagCompound(stack0.getTagCompound()); }
Example 5
Source File: Firework.java From minecraft-roguelike with GNU General Public License v3.0 | 5 votes |
public static ItemStack get(Random rand, int stackSize){ ItemStack rocket = new ItemStack(Items.FIREWORKS, stackSize); NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound fireworks = new NBTTagCompound(); fireworks.setByte("Flight", (byte) (rand.nextInt(3) + 1)); NBTTagList explosion = new NBTTagList(); NBTTagCompound properties = new NBTTagCompound(); properties.setByte("Flicker", (byte) (rand.nextBoolean() ? 1 : 0)); properties.setByte("Trail", (byte) (rand.nextBoolean() ? 1 : 0)); properties.setByte("Type", (byte) (rand.nextInt(5))); int size = rand.nextInt(4) + 1; int[] colorArr = new int[size]; for(int i = 0; i < size; ++i){ colorArr[i] = DyeColor.HSLToColor(rand.nextFloat(), (float)1.0, (float)0.5); } NBTTagIntArray colors = new NBTTagIntArray(colorArr); properties.setTag("Colors", colors); explosion.appendTag(properties); fireworks.setTag("Explosions", explosion); tag.setTag("Fireworks", fireworks); rocket.setTagCompound(tag); return rocket; }
Example 6
Source File: TippedArrow.java From Et-Futurum with The Unlicense | 5 votes |
public static ItemStack setEffect(ItemStack stack, Potion potion, int duration) { stack.setTagCompound(new NBTTagCompound()); NBTTagCompound nbt = new NBTTagCompound(); stack.getTagCompound().setTag("Potion", nbt); PotionEffect effect = new PotionEffect(potion.getId(), potion.isInstant() ? 1 : duration); effect.writeCustomPotionEffectToNBT(nbt); return stack; }
Example 7
Source File: NBTHelper.java From LetsModReboot with GNU General Public License v3.0 | 5 votes |
/** * Initializes the NBT Tag Compound for the given ItemStack if it is null * * @param itemStack * The ItemStack for which its NBT Tag Compound is being checked for initialization */ private static void initNBTTagCompound(ItemStack itemStack) { if (itemStack.stackTagCompound == null) { itemStack.setTagCompound(new NBTTagCompound()); } }
Example 8
Source File: BWItem.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
public net.minecraft.item.ItemStack makeItemStack(int stackSize) { ItemStack result = new ItemStack(item, stackSize, meta); if (tag != null) { result.setTagCompound(tag); } return result; }
Example 9
Source File: ItemData.java From AdvancedRocketry with MIT License | 5 votes |
public void setData(ItemStack item, int amount, DataStorage.DataType dataType) { DataStorage data = getDataStorage(item); data.setData(amount, dataType); NBTTagCompound nbt = new NBTTagCompound(); data.writeToNBT(nbt); item.setTagCompound(nbt); }
Example 10
Source File: ItemSubCollar.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
/** * Returns true if the item can be used on the given entity, e.g. shears on sheep. */ @Override public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity) { if (entity.worldObj.isRemote) { return false; } if (entity instanceof EntityPlayer) { EntityPlayer sub = (EntityPlayer)entity; IInventory baubles = BaublesApi.getBaubles(sub); if(baubles.getStackInSlot(0) == null) { if(!itemstack.hasTagCompound()){ NBTTagCompound tag = new NBTTagCompound(); itemstack.setTagCompound(tag); } itemstack.stackTagCompound.setString("owner", player.getDisplayName()); baubles.setInventorySlotContents(0, itemstack.copy()); itemstack.stackSize = 0; sub.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.placescollar").replace("%s", player.getDisplayName()))); player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.youplacecollar").replace("%s", sub.getDisplayName()))); return true; } else player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.alreadywearing").replace("%s", sub.getDisplayName()))); } return false; }
Example 11
Source File: ItemIdWithName.java From AdvancedRocketry with MIT License | 5 votes |
public void setName(ItemStack stack, String name) { if(stack.hasTagCompound()) { NBTTagCompound nbt = stack.getTagCompound(); nbt.setString("name", name); stack.setTagCompound(nbt); } }
Example 12
Source File: CrashSlimeCommand.java From seppuku with GNU General Public License v3.0 | 5 votes |
@Override public void exec(String input) { if (!this.clamp(input, 1, 1)) { this.printUsage(); return; } final Minecraft mc = Minecraft.getMinecraft(); if (!mc.player.isCreative()) { Seppuku.INSTANCE.errorChat("Creative mode is required to use this command."); return; } final ItemStack itemStack = new ItemStack(Item.getItemById(383)); final NBTTagCompound tagCompound = (itemStack.hasTagCompound()) ? itemStack.getTagCompound() : new NBTTagCompound(); final NBTTagCompound entityTag = new NBTTagCompound(); entityTag.setString("id", "minecraft:slime"); tagCompound.setTag("EntityTag", entityTag); entityTag.setInteger("Size", Integer.MAX_VALUE); itemStack.setTagCompound(tagCompound); final int slot = this.findEmptyhotbar(); mc.player.connection.sendPacket(new CPacketCreativeInventoryAction(36 + (slot != -1 ? slot : mc.player.inventory.currentItem), itemStack)); Seppuku.INSTANCE.logChat("Gave you a crash slime spawn egg"); }
Example 13
Source File: ContainerEngineeringTable.java From Cyberware with MIT License | 5 votes |
public void checkForNewBoxes() { for (int i = 0; i < playerInv.mainInventory.length; i++) { if (!this.componentBoxList.contains(i)) { ItemStack stack = playerInv.mainInventory[i]; if (stack != null && stack.getItem() == CyberwareContent.componentBox.ib) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } if (!stack.getTagCompound().hasKey("contents")) { ItemStackHandler slots = new ItemStackHandlerComponent(18); stack.getTagCompound().setTag("contents", slots.serializeNBT()); } if (componentBox == null ) { componentBox = i; componentBoxIndex = componentBoxList.size(); } componentBoxList.add(i); } } } }
Example 14
Source File: DriverItem.java From Framez with GNU General Public License v3.0 | 5 votes |
@Override public NBTTagCompound dataTag(final ItemStack stack) { if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } final NBTTagCompound nbt = stack.getTagCompound(); // This is the suggested key under which to store item component data. // You are free to change this as you please. if (!nbt.hasKey("oc:data")) { nbt.setTag("oc:data", new NBTTagCompound()); } return nbt.getCompoundTag("oc:data"); }
Example 15
Source File: FuelTests.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Test public void testBurnTimeWithWrongNbt() { Fuel fuel = gson.fromJson("{ \"item\": {\"item\" : \"minecraft:bow\", \"nbt\":\"{AInt:1}\" }, \"burnTime\":1337 }", Fuel.class); fuel.init(InitPhase.PRE_INIT, new TestContentHelper("{}", TestContent.class)); ItemStack stack = new ItemStack(Items.BOW); stack.setTagCompound(new NBTTagCompound()); stack.getTagCompound().setInteger("AInt", 2); assertFalse(fuel.appliesToStack(stack)); }
Example 16
Source File: SoulNetworkHandler.java From Framez with GNU General Public License v3.0 | 5 votes |
public static void checkAndSetItemOwner(ItemStack item, String ownerName) { if (item.stackTagCompound == null) { item.setTagCompound(new NBTTagCompound()); } if (item.stackTagCompound.getString("ownerName").equals("")) { item.stackTagCompound.setString("ownerName", ownerName); } }
Example 17
Source File: GTItemInventoryDestructoPack.java From GT-Classic with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void onClose(ItemStack stack) { stack.setTagCompound(null); }
Example 18
Source File: ItemTofuEnergyContained.java From TofuCraftReload with MIT License | 4 votes |
@Override public void setEnergyMax(ItemStack inst, int amount) { inst.setTagCompound(NBTUtil.setInteger(inst.getTagCompound(), TAG_TFMAX, amount)); }
Example 19
Source File: TippedArrow.java From minecraft-roguelike with GNU General Public License v3.0 | 3 votes |
public static ItemStack get(net.minecraft.potion.PotionType type, int amount){ String id = net.minecraft.potion.PotionType.REGISTRY.getNameForObject(type).toString(); ItemStack arrow = new ItemStack(Items.TIPPED_ARROW, amount); NBTTagCompound nbt = new NBTTagCompound(); nbt.setString("Potion", id); arrow.setTagCompound(nbt); return arrow; }
Example 20
Source File: NBTUtil.java From PneumaticCraft with GNU General Public License v3.0 | 2 votes |
/** * Initializes the {@link NBTTagCompound} for the given {@link ItemStack} if * it is null. * * @param itemStack * The {@link ItemStack} which holds the {@link NBTTagCompound}. */ public static void initNBTTagCompound(ItemStack itemStack){ if(itemStack.stackTagCompound == null) { itemStack.setTagCompound(new NBTTagCompound()); } }