Jump to content

I need help with block scanning!


WimpyLlama

Recommended Posts

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);
	}
	
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.