Jump to content

Recommended Posts

Posted

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);
}
}

Posted

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.

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.