Posted January 7, 20178 yr Hey there! So I'm in need of accessing a block's TE so I can get a couple of integers from it.. How would I do this? I have the itemblock already setup, however I do not know how to access that information from the TE.. I know I'll probably have to send a packet with the data in it, but I need to access it first. Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
January 7, 20178 yr I'm not sure what you mean. Blocks in the world don't have tooltips (at least in vanilla) and item stacks in an inventory don't have tile entities. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 7, 20178 yr Author I have a custom ItemBlock public static class TheItemBlock extends ItemBlockBase { public TheItemBlock(Block block){ super(block); this.setHasSubtypes(false); this.setMaxDamage(0); } @Override public String getUnlocalizedName(ItemStack stack){ return this.getUnlocalizedName(); } @Override public int getMetadata(int damage){ return damage; } @Override public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean bool){ list.add(StringUtil.localize("")); } } which is a inner class to the block. I want to put inside the ItemBlock tooltip some values from the TE.. The TE generates randomly, with randomly assigned values, when you pick it up, I want those values to display in the tooltip. Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
January 7, 20178 yr As I said before items and item blocks in inventories don't have tile entities. You can use NBT data to store arbitrary data in a tile entity. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 7, 20178 yr Author Yes I know blocks and items blocks don't have tile entities, the block itself has one with 3 data numbers... So what I'm asking can I get information from the BLOCK TE and put it into the ITEMBLOCK an tooltip.... ex: public class BlockVoidCrystal extends BlockContainerBase { public BlockVoidCrystal(String name) { super(Material.GLASS, name); } @Override public ItemBlockBase getItemBlock() { return new TheItemBlock(this); } @Nullable @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityVoidCrystal(); } @Override @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) { return false; } @Override public boolean isBlockNormalCube(IBlockState blockState) { return false; } @Override public boolean isOpaqueCube(IBlockState blockState) { return false; } public static class TheItemBlock extends ItemBlockBase { public TheItemBlock(Block block){ super(block); this.setHasSubtypes(false); this.setMaxDamage(0); } @Override public String getUnlocalizedName(ItemStack stack){ return this.getUnlocalizedName(); } @Override public int getMetadata(int damage){ return damage; } @Override public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean bool){ list.add(StringUtil.localize("")); } } } How would I access said arbitrary data?.. Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
January 7, 20178 yr So the ItemBlock has three different metadata values? In the addInformation method, just switch on stack.getMetadata() and add a different string to the list depending on the value. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 7, 20178 yr Author No no no.. The Block HAS a TileEntity, which stores 3 values.. I want to access those values and display them on the tooltip. Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
January 7, 20178 yr Yes, exactly what diesieben07 said. When your block breaks, you need to add NBT to the dropped ItemStack based on the value stored in the tile entity. You can then access those values from the addInformation method. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 8, 20178 yr Author Okay, how do I get the integers from the TE to assign the NBT to the block? Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
January 8, 20178 yr I assume you want to add the integers from the TileEntity to the NBT of an ItemStack ? You want to override getDrops to return a List<ItemStack> with the NBT set to the values of the TileEntity , which you can access using the IBlockAccess and BlockPos provided. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
January 8, 20178 yr Note that by default, the TileEntity is removed from the world before Block#getDrops is called. You need to delay its removal like Forge's patch to BlockFlowerPot does. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
January 8, 20178 yr Author Here is what I have so far: @Override public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { TileEntityVoidCrystal te = (TileEntityVoidCrystal)world.getTileEntity(pos); ArrayList<ItemStack> stack = new ArrayList<>(); if(te != null) { NBTTagCompound compound = new NBTTagCompound(); compound.setFloat("Decay", te.decay); compound.setFloat("Purity", te.purity); compound.setFloat("Charge", te.charge); stack.add(new ItemStack()) } } @Override public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { if(willHarvest) return true; return super.removedByPlayer(state, world, pos, player, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack tool) { super.harvestBlock(world, player, pos, state, te, tool); world.setBlockToAir(pos); } However, how do I write that NBT to the ItemStack? Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
January 8, 20178 yr You want to make an ItemStack variable, then call ItemStack#setTagCompound(NBTTagCompound) on that variable. This is also the ItemStack you want to add to the List<ItemStack> . Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
January 8, 20178 yr Author Thanks for your help! If anybody is searching for this here is the completed code: @Override public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { TileEntityVoidCrystal te = (TileEntityVoidCrystal)world.getTileEntity(pos); ArrayList<ItemStack> stacks = new ArrayList<>(); if(te != null) { ItemStack itemToReturn = new ItemStack(InitBlocks.blockVoidCrystal); NBTTagCompound compound = new NBTTagCompound(); compound.setFloat("Decay", te.decay); compound.setFloat("Purity", te.purity); compound.setFloat("Charge", te.charge); itemToReturn.setTagCompound(compound); stacks.add(itemToReturn); } return stacks; } @Override public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { if(willHarvest) return true; return super.removedByPlayer(state, world, pos, player, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack tool) { super.harvestBlock(world, player, pos, state, te, tool); world.setBlockToAir(pos); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) { super.onBlockPlacedBy(world, pos, state, entity, stack); if(!world.isRemote) { TileEntityVoidCrystal te = (TileEntityVoidCrystal) world.getTileEntity(pos); if (te != null) { NBTTagCompound compound = stack.getTagCompound(); if (compound != null) { float tempDecay = compound.getFloat("Decay"); float tempPurity = compound.getFloat("Purity"); float tempCharge = compound.getFloat("Charge"); te.decay = tempDecay; te.purity = tempPurity; te.charge = tempCharge; } } } } Relatively new to modding. Currently developing: https://github.com/LambdaXV/DynamicGenerators
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.