MrProg Posted December 11, 2013 Posted December 11, 2013 Okay this will be a bit hard to explain but here I go. I have a block (a gift block) that when you right-click it with an item it gets saved into the block until it's broken and then that item you just stored will pop into your inventory. The only problem is that, if you have one block placed and store something in it and then you place a second gift block down, they act as the same block. So if I put something in the first block, and when I break the second block I get the contents from the first block. So if anyone could please help me that would be great! Thanks! Gift Block Code public class BlockGift extends BlockBaseBlock{ private String giftGiver = "This gift is empty."; private static int giftID; private static int giftMeta; private static int giftStack; @SideOnly(Side.CLIENT) private Icon iconPresentTop; @SideOnly(Side.CLIENT) private Icon iconPresentBottom; public BlockGift(int par1, Material par2Material) { super(par1, par2Material); } @Override public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if(!par5EntityPlayer.worldObj.isRemote && par5EntityPlayer.isSneaking() == true){ par5EntityPlayer.addChatMessage(giftGiver); } if(!par5EntityPlayer.worldObj.isRemote && par5EntityPlayer.isSneaking() == false && par5EntityPlayer.getCurrentItemOrArmor(0) != null && giftStack == 0){ giftID = par5EntityPlayer.getCurrentEquippedItem().itemID; giftMeta = par5EntityPlayer.getCurrentEquippedItem().getItemDamage(); giftStack = par5EntityPlayer.getCurrentEquippedItem().stackSize; giftGiver = "Gift from: " + par5EntityPlayer.username; par5EntityPlayer.getCurrentEquippedItem().stackSize -= par5EntityPlayer.getCurrentEquippedItem().stackSize; } else { if(!par5EntityPlayer.worldObj.isRemote){ par5EntityPlayer.addChatMessage("This gift is full!"); } } return true; } public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) { par1World.playSoundAtEntity(par6EntityPlayer, "wintercraft:rip", 1F, 1F); if(!par6EntityPlayer.worldObj.isRemote){ par6EntityPlayer.addChatMessage(giftGiver); } giftGiver = "This gift is empty."; par6EntityPlayer.inventory.addItemStackToInventory(new ItemStack(giftID, giftStack, giftMeta)); giftID = 0; giftMeta = 0; giftStack = 0; } @Override public int idDropped(int par1, Random par2Random, int par3) { return 0; } @SideOnly(Side.CLIENT) /** * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata */ public Icon getIcon(int par1, int par2) { return par1 == 1 ? this.iconPresentTop : (par1 == 0 ? this.iconPresentBottom : this.blockIcon); } public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { if (par5 == 1) { return this.iconPresentTop; } else if (par5 == 0) { return this.iconPresentBottom; } else { return this.blockIcon; } } @SideOnly(Side.CLIENT) /** * When this method is called, your block should register all the icons it needs with the given IconRegister. This * is the only chance you get to register icons. */ public void registerIcons(IconRegister par1IconRegister) { //Trying Something making it easier to make dirt blocks this.blockIcon = par1IconRegister.registerIcon(Wintercraft.modid + ":" + this.getUnlocalizedName().substring(5) + "_side"); this.iconPresentTop = par1IconRegister.registerIcon(Wintercraft.modid + ":" + this.getUnlocalizedName().substring(5) + "_top"); this.iconPresentBottom = par1IconRegister.registerIcon(Wintercraft.modid + ":" + this.getUnlocalizedName().substring(5) + "_side"); } protected boolean canSilkHarvest() { return true; } } Quote
Draco18s Posted December 11, 2013 Posted December 11, 2013 LOL, static values. Go learn Java. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
TheGreyGhost Posted December 11, 2013 Posted December 11, 2013 Hi Just to expand a bit on what Draco said :-) There is only one blockGift ever created, regardless of how many you place in the world. And on top of that, you've declared the variables static, so even if there were many blockGifts, you would still only have one of each variable for all of those blockGifts (that's what static means). http://greyminecraftcoder.blogspot.com.au/2013/10/the-most-important-minecraft-classes_9.html http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html If you want to store information about each gift that you have put in the world, you need to use TileEntity instead. That's a little bit more complicated, but there are a few tutorials out there which can get you started, google should bring them up pretty quick. -TGG Quote
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.