Blackwing_Forged Posted March 13, 2017 Posted March 13, 2017 (edited) I have this event and its supposed to be whenever a player sneak right clicks with a empty glass bottle they take 3 hearts of damage and gives them a vial of blood but it doesn't do anything. Any help appreciated, thanks. Event: Reveal hidden contents @SubscribeEvent public void bloodVialRightClick(LivingEntityUseItemEvent.Start e) { EntityPlayer player = (EntityPlayer) e.getEntityLiving(); ItemStack itemUsed = e.getItem(); if(itemUsed == new ItemStack(Items.GLASS_BOTTLE) && player.isSneaking()) { float health = player.getHealth(); float newHealth = player.getHealth() - 3; player.setHealth(newHealth); player.inventory.addItemStackToInventory(new ItemStack(ItemRegistry.bloodVial)); itemUsed.shrink(1); } } Edited March 13, 2017 by Blackwing_Forged Quote
jtsfour Posted March 13, 2017 Posted March 13, 2017 (edited) this should fix things the LivingEntityUseItemEvent.Start only works for items that can be used i.e. food i wrote the fixed code for you below. EDIT: just realized you wanted sneak-right-click i fixed the code below //used when rightclicking while looking at a block @SubscribeEvent() public void rightClickBlock(PlayerInteractEvent.RightClickBlock e){ //this checks if the entities world is the server we only run this on the server so it doesn't mess with things if(!e.getEntity().getEntityWorld().isRemote){ EntityPlayer player = e.getEntityPlayer();//the player //check if player is sneaking if(player.isSneaking()){ ItemStack heldItem = player.getHeldItemMainhand();//the items in the players hand //we compare the Item contained in the ItemStack not the ItemStack itself //we use .equals here not == only use == for numbers or booleans if(heldItem.getItem().equals(Items.GLASS_BOTTLE)){ onGlassBottleRightClick(player, heldItem);//this is the method where you put the code when the player right-clicks with an item } } } } //used when rightclicking with an item while not looking at a block @SubscribeEvent() public void rightClickItem(PlayerInteractEvent.RightClickItem e){ //this checks if the entities world is the server we only run this on the server so it doesn't mess with things if(!e.getEntity().getEntityWorld().isRemote){ EntityPlayer player = e.getEntityPlayer();//the player //check if player is sneaking if(player.isSneaking()){ ItemStack heldItem = player.getHeldItemMainhand();//the items in the players hand //we compare the Item contained in the ItemStack not the ItemStack itself //we use .equals here not == only use == for numbers or booleans if(heldItem.getItem().equals(Items.GLASS_BOTTLE)){ onGlassBottleRightClick(player, heldItem);//this is the method where you put the code when the player right-clicks with an item } } } } private void onGlassBottleRightClick(EntityPlayer player, ItemStack bottlestack){ player.attackEntityFrom(DamageSource.GENERIC, 3F); //player.inventory.addItemStackToInventory(new ItemStack(ItemRegistry.bloodVial)); } Edited March 13, 2017 by jtsfour error 1 Quote
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.