Jump to content

Recommended Posts

Posted

I am working on a 1.10.2 mod and I need help. NOTICE: I am new at modding!


What I am trying to do is create an item that tests if you are looking at a grass block when you right click with it. And if you are looking at a grass block a piece of cobblestone appears. And the item only has 64 uses. I have some code for the item that I got from a tutorial on a heart that heals you. I am trying to base my code on this but I can't figure out what to do. Please help!

 

package wimpyllama.wimprimstuff.items;

import java.util.List;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import wimpyllama.wimprimstuff.Reference;
import wimpyllama.wimprimstuff.util.Utils;

public class ItemSifter extends Item{

	public ItemSifter(String unlocalizedName) {
		this.setUnlocalizedName(unlocalizedName);
		this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
	}
	
	@Override
	public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player,
			EnumHand hand) {
		if(player.getHealth() < player.getMaxHealth()) {
			player.heal(4);
			int damageToBe = player.getHeldItem(hand).getItemDamage() + 1;
			if(damageToBe > 4) {
				player.getHeldItem(hand).stackSize--;
			} else {
				player.getHeldItem(hand).setItemDamage(player.getHeldItem(hand).getItemDamage() + 1);
			}
		}
		return super.onItemRightClick(stack, world, player, hand);
	}
	
}
Posted

As I said, I am new to modding. I don't understand what this is. And I don't want to update to 1.12.2 because most modpacks, including the one I am making, are for 1.10.2 so I just rather make it for 1.10.2 for now and maybe update it in the future.

Posted

I don't understand what Item::rayTrace means. All I need is to create an if statement that tests if the player is looking at a grass block. if(blockAtPlayerCross == Blocks.GRASS) is what I'm trying to do but I don't know the real statement. I have looked on youtube and google and I can't find anything.

Posted
12 minutes ago, WimpyLlama said:

Never mind, I figured it out by opening mcreator and making the item in there then I copied some of the code and edited it to my liking.

face palm

 

DONT use that, learn java and code it properly

Posted

I am learning java. I don't use mcreator anymore but it is useful for learning how to do things if you look at the code. I am still coding my mod by myself I just used a bit of mcreators code.

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.