Posted April 15, 201510 yr So i have some code that adds a NBT tag to a block when i pass it through a shapeless crafting reciepe MastStack.setTagCompound(new NBTTagCompound()); NBTTagCompound tags = MastStack.stackTagCompound; tags.setBoolean("Upright", true); GameRegistry.addShapelessRecipe(MastStack, new Object[] {MastUp,MastUp,MastUp}); however it doesn't preserve the data when it is placed as a block/tileentity. The data will be stored in the TE as i have set up several setters/getters and am already storing most of my data there anyway, however i have no idea how to pass the data form Item to TE [glow=green,2,300]TEmast[/glow] package ships.addon.blocks_items; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; public class TEmast extends TileEntity { private byte Direction; private byte Dye; private boolean Upright; private boolean Connected; @Override public AxisAlignedBB getRenderBoundingBox() { return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1); } //---- Setters and Getters ----\\ public byte getValue() { return Direction; } public void setValue(byte value) { Direction = value; } public byte getDye() { return Dye; } public void setDye(byte value) { Dye = value; } public boolean getBoolean() { return Upright; } public void setBoolean(boolean value) { Upright = value; } public boolean getBool() { return Connected; } public void setBool(boolean value) { Connected = value; } //---- Read and Write ----\\ public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); nbt.setBoolean("Connected", this.Connected); nbt.setBoolean("Upright", this.Upright); nbt.setByte("Direction", this.Direction); nbt.setByte("Dye", this.Dye); markForUpdate(); } public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); this.Connected = nbt.getBoolean("Connected"); this.Upright = nbt.getBoolean("Upright"); this.Direction = nbt.getByte("Direction"); this.Dye = nbt.getByte("Dye"); } //---- Packets ----\\ @Override public Packet getDescriptionPacket(){ NBTTagCompound tileTag = new NBTTagCompound(); this.writeToNBT(tileTag); return new S35PacketUpdateTileEntity(this.xCoord,this.yCoord,this.zCoord,0,tileTag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); } //---- Mark for Update ----\\ public void markForUpdate() { this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } [glow=red,2,300]Crafting with the For loops and Items stacks[/glow] for(int i=0; i<12; i++){ //Iterate Item Stacks ItemStack MastStack = new ItemStack(Registry.Mast, 3, i); ItemStack MastUp = new ItemStack(Registry.Mast, 1, i); ItemStack WoodStack = new ItemStack(Blocks.log, 3, 0); if(i<4){WoodStack = new ItemStack(Blocks.log, 3, i);} else if(i<6){WoodStack = new ItemStack(Blocks.log2, 3, i-4);} else{WoodStack = new ItemStack(Blocks.planks, 3, i-6);} GameRegistry.addShapedRecipe(MastStack, new Object[]{ "LLL", "WWW", 'L',WoodStack,'W',Registry.Sail }); MastStack.setTagCompound(new NBTTagCompound()); NBTTagCompound tags = MastStack.stackTagCompound; tags.setBoolean("Upright", true); GameRegistry.addShapelessRecipe(MastStack, new Object[] {MastUp,MastUp,MastUp}); }
April 15, 201510 yr To do this you need to create own item block for this block, to override on item use, to pass nbt to te... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
April 18, 201510 yr Author To do this you need to create own item block for this block, to override on item use, to pass nbt to te... Thanks, where would i find an example of this? Cuase i already have a ItemBlock however i am not sure how to use onItemUse() [glow=red,2,300]ItemBlockMast[/glow] public class ItemMast extends ItemBlock{ private final Block Mast; public ItemMast(Block block) { super(block); this.Mast = block; this.setHasSubtypes(true); } public String getUnlocalizedName(ItemStack item){ int i = item.getItemDamage(); if(i<0||i>=BlockMast.subBlocks.length){ i=i-BlockMast.subBlocks.length; } return super.getUnlocalizedName()+"."+BlockMast.subBlocks[i]; } public int getMetadata(int meta){ return meta; } @SideOnly(Side.CLIENT) public IIcon getIconFromDamage(int meta) { return this.Mast.getIcon(0, meta); } } Yes Im in 1.7.10
April 18, 201510 yr You call super.onItemUse first, that will place block for you. Then you use getTileEntityAt, check that it's your te and you can do what ever you want... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.