NathanMndz1 Posted November 8, 2019 Posted November 8, 2019 Hello, i need some help/suggestions on implementing a method. I have created a class that allows the player to summon ender pearls via a staff. I want to make it so when the items durability reaches 0, instead of the item breaking, the class searches the players inventory for ender pearls if it finds some it then removes a certain amount and it replenishes the objects durability. Any suggestions? Below is the staff class. package com.aww_man.Teleportation.items; import com.aww_man.Teleportation.Main; import com.aww_man.Teleportation.init.ModItems; import com.aww_man.Teleportation.util.IHasModel; import com.mojang.realmsclient.dto.PlayerInfo; import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityEnderPearl; 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.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.client.event.sound.PlaySoundEvent; public class VoidStaff extends Item implements IHasModel{ public VoidStaff(String name) { setUnlocalizedName(name); setRegistryName(name); setCreativeTab(Main.modtabs); ModItems.ITEMS.add(this); setMaxDamage(100); setMaxStackSize(1); } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack enderpearls = playerIn.getHeldItemOffhand(); ItemStack item = playerIn.getHeldItem(handIn); Vec3d Look = playerIn.getLookVec(); item.damageItem(5, playerIn); EntityEnderPearl enderpearl = new EntityEnderPearl(worldIn, playerIn); enderpearl.setPosition(playerIn.posX+Look.x*30d, playerIn.posY+Look.y*30d, playerIn.posZ+Look.z*30d); worldIn.spawnEntity(enderpearl); playerIn.getCooldownTracker().setCooldown(this, 60); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS,item); } @Override public void registerModels() { Main.proxy.registerItemRender(this,0,"inventory"); } } Quote
SerpentDagger Posted November 8, 2019 Posted November 8, 2019 For the damage, you can check/set the ItemStack's damage with ItemStack#getDamage() and ItemStack#setDamage(). For the inventory searching, you can get the player's inventory through the EntityPlayer object, use that to check for the ender pearls, and get an ItemStack of them to interact with and change. Quote Fancy 3D Graphing Calculator mod, with many different coordinate systems. Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.
Recommended Posts
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.