Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • 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.

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.

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.