IvanTune Posted September 13, 2015 Share Posted September 13, 2015 Hello! I was wondering how you would go about allowing an int value to be saved to a specific block, so when a player breaks the block and places it again the block contains the storage (rf) it had before (and this block can now not be stacked any more with the same blocks). I have saved the rf storage to NBT, and logging out and in again works fine, but I am not sure how to save the storage to an instanced block. Thanks. Quote Link to comment Share on other sites More sharing options...
IvanTune Posted September 13, 2015 Author Share Posted September 13, 2015 Thanks for the reply, and yes the data is stored in a tileentity. I had a look at the getDrops method (which I assume is the only one I need from the BlockFlowerPot class?), and this is what I got from it. It does drop an extra block when broken, but did it apply the data to the dropped block like this? @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); if (te != null && te instanceof TileEntityRedstoneMacerator) ret.add(new ItemStack(ModBlocks.blockRedstoneMaceratorIdle, 1, te.getEnergyStored())); return ret; } Quote Link to comment Share on other sites More sharing options...
IvanTune Posted September 13, 2015 Author Share Posted September 13, 2015 Since I was getting 2 items I set the getItemDropped to null, and this is code so far, is it now storing the data in the block that gets dropped? The te.getEnergyStored() is returning the internal storage the tileentity has. @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); if (te != null && te instanceof TileEntityRedstoneMacerator) ret.add(new ItemStack(ModBlocks.blockRedstoneMaceratorIdle, 1, te.getEnergyStored())); return ret; } @Override public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { if (willHarvest){ return true; //If it will harvest, delay deletion of the block until after getDrops } return super.removedByPlayer(world, player, x, y, z, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) { super.harvestBlock(world, player, x, y, z, meta); world.setBlockToAir(x, y, z); } Quote Link to comment Share on other sites More sharing options...
IvanTune Posted September 13, 2015 Author Share Posted September 13, 2015 Do you mean changing it to ArrayList<ItemStack> ret = new ArrayList<ItemStack>();? I tried that also but when I break the block and pick it back up again it goes back into the same stack it was in. I also tried adding other data into it but it didn't go into its own stack when picked up. Like when I try to add te.cookTime() same thing happens. Does the data need to be done in a special way in the tileentity in order to be stored? For cooktime all I did was make the int, store it in NBT, then change its value depending on what machine was doing. nbt.setShort("CookTime", (short) this.cookTime); this.cookTime = (int) nbt.getShort("CookTime"); Quote Link to comment Share on other sites More sharing options...
IvanTune Posted September 14, 2015 Author Share Posted September 14, 2015 I am probably missing something, but I thought the ret.add was adding my block to the itemstack, then adding the data to the block and returning the itemstack as a drop with the data. @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); if (te instanceof TileEntityRedstoneMacerator) ret.add(new ItemStack(ModBlocks.blockRedstoneMaceratorIdle, 1, te.getEnergyStored())); return ret; } Quote Link to comment Share on other sites More sharing options...
IvanTune Posted September 14, 2015 Author Share Posted September 14, 2015 Really appricate the answers diesieben07. You mean something like this? @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); ItemStack stack = new ItemStack(world.getBlock(x, y, z), 1, metadata); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); int i = te.cookTime; if (te instanceof TileEntityRedstoneMacerator){ if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } stack.getTagCompound().setInteger("CookTime", i); ret.add(stack); } return ret; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.