Posted July 12, 20169 yr Ok so I'm trying to create an item that when is right clicked will get destroyed and will give me a random item. I tried with a simple random range of 2(will be 20 in the end) and the out puts are if its 0 it will be a potion effect, if its 1 it gives me an axe. My problem is that sometimes it gives me both the potion effect and the axe or sometimes the potion effect just does nothing, my hearts turn green(poison effect), but take no damage. Class of the item. package com.champion.tutorial.item; import java.util.Random; import com.champion.tutorial.client.TutorialMod; import com.champion.tutorial.init.TutorialItems; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; public class ItemDice extends Item { public ItemDice(String unlocalizedName){ this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(TutorialMod.tabTutorial); maxStackSize = 1; setMaxDamage(1); } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if(!worldIn.isRemote){ Random ran = new Random(); int x = ran.nextInt(2); if(x == 0) { itemStackIn.damageItem(2, playerIn); playerIn.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("poison"), 200)); } if(x == 1){ itemStackIn.damageItem(2, playerIn); playerIn.inventory.addItemStackToInventory(new ItemStack(TutorialItems.garnet_axe)); } //itemStackIn.damageItem(2, playerIn); //playerIn.inventory.addItemStackToInventory(new ItemStack(TutorialItems.garnet_axe)); } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn); } }
July 12, 20169 yr Author Well I've red the document(really interesting by the way), but I don't really understand what to do with that information. If I'm not mistaken I must check if world.isRemote is false, thats what I did so I assume its not what I'm supposed to do and I'm kinda lost on what I have to do with this.
July 12, 20169 yr I am sorry, but nowhere in your code I see side-checks. Whatever you do that manipulates data (that is not display-only) - you do it on server (!world.isRemote). EDIT Basically what I'm saying - throw whole method's code into that check. 1.7.10 is no longer supported by forge, you are on your own.
July 12, 20169 yr Author Oups, forgot to update the code. Looks like the problem was just Eclipse because I restarted it and not it works!
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.