Posted June 23, 201510 yr Well my Problem is that whenever I activate the onItemUse event the block, I Clicked on, get's replaced with air and the sound get's played, just as planed, but right after that the air block get´s replaced again with the block that was there before and i don't know why MC does that .I want the item to work once but without removing or destroying it. (sorry for probably bad English I'm no native speaker) Here is my Code: package items; import org.Python.StuffForMC.StuffForMC; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.DamageSource; import net.minecraft.world.World; public class Item_Work_Scope extends Item { public Item_Work_Scope(){ setCreativeTab(StuffForMC.tabStuffForMC); setMaxStackSize(1); setUnlocalizedName("Item_Work_Scope"); setTextureName("StuffForMC:WorkScope"); } @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } private static int test = 1; public boolean onItemUse(ItemStack itemStack, EntityPlayer entity, World world, int x, int y, int z, int l, float a, float b, float c){ float var4 = 1.0F; Block g = Blocks.bedrock; Block block = world.getBlock(x, y, z); if(test<2){ if (block != g) { test=test+1; world.setBlock(x, y, z, Blocks.air); world.playRecord("mob.zombie.woodbreak", x, y, z); } } return true; }}
June 23, 201510 yr Author Ok, I now have even more questions: 1) to a): why not? How I'm able to store them then? 2) to b): why? I need an explanation
June 23, 201510 yr Author There is only ever one instance of your Item in existence. So even if you were to make the field non-static it would be the same for all of your Items. If you want to store something, you need to store it in the ItemStack. Either as the damage value or in the NBT tag. I'm sorry but I really don't get what you're trying to say. If you set the Block on the client exactly what you experienced happened: The block is not really there, you cannot interact with it and so on. When you modify the world you always need to do it on the server. I don't see the problem in the Cliend or Server thing, because it works fine without all "test" variables. If I remove all "test"variables it works perfectly, but infinitly often and I want it to work just once. So i figured this variable thing out that was supposed to limit the onItemUse event to one use. That seems to work fine as well, untill the if part closes of and something decides to undo enything that happens in the if part.
June 23, 201510 yr Author Do you know what static means? The variable exists ONLY ONCE. So if two players hold your item, the variable is still the same for both of those. Oh.. I thought it was ment to just generate once. So I see my mistake here. Even if you make it non-static that will still apply. Ok...then how am i able to solve that problem?
June 23, 201510 yr Item is something like "what is this thing I am holding?" ItemStack is the "THING I am holding." Item only tells game that stuff you hold should be treated as something. ItemStack actually holds data - it's itemDamage and/or NBT. Google NBT and how to work with it (a lot of tuts). 1.7.10 is no longer supported by forge, you are on your own.
June 23, 201510 yr Author Could you give me an example, because by now I have no idea how to use that and I'm slowly getting tired (were I live it's almost 0:00)
June 23, 201510 yr If you want examples, here you got an example for like everything. For everything else, start learning java, start watching tutorials on how to mod. https://github.com/TheGreyGhost/MinecraftByExample
June 23, 201510 yr Oke, so you got to remember that the server is responsible for all the desicion makings etc. While the Client only renders the world. Since the items has logic(= server) and rendering(= Client), you need to decide what should be called where. In case of the blockPlacement you need to check if the method is called by the server side, otherwise the blockchanging would be only a visible effect, not a physical one. Add this line to check if its the server who calls //if(!World.isremote) if(!world.isremote) { world.setBlock(x, y, z, Blocks.air); } Edit: Thanks for noticing. I was typing on a mobile phone, and totaly missed that accidential typed capital. Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
June 23, 201510 yr 10 bucks some1 will copy that code and post in the forum, totally confused that its throwing errors
June 23, 201510 yr Oke, so you got to remember that the server is responsible for all the desicion makings etc. While the Client only renders the world. Since the items has logic(= server) and rendering(= Client), you need to decide what should be called where. In case of the blockPlacement you need to check if the method is called by the server side, otherwise the blockchanging would be only a visible effect, not a physical one. Add this line to check if its the server who calls if(!World.isremote) { world.setBlock(x, y, z, Blocks.air); } World != world if anyone is confused
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.