Posted June 21, 20214 yr The durability of my custom Item goes down only for a second then goes back to where it was before I clicked. I'd really appreciate if someone can point me in the right direction to get this working. @Override public ActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) { ItemStack stack = playerEntity.getItemInHand(hand); if (!world.isClientSide) { ItemStack newStack = new ItemStack(stack.getItem()); newStack.setDamageValue(stack.getDamageValue() + 1); return ActionResult.success(newStack); } else return super.use(world, playerEntity, hand); } Edited June 21, 20214 yr by RCKraken
June 21, 20214 yr You never put the new ItemStack into hand of the player Edited June 21, 20214 yr by Luis_ST
June 21, 20214 yr you should just apply damage to the current stack instead of creating a new stack (at least the way you are doing it) because you will lose other settings, like enchantments
June 21, 20214 yr Author Okay, so 7 hours ago, Luis_ST said: You never put the new ItemStack into hand of the player doesn't return ActionResult.success(stack); give the player's hand the new itemstack? Also, 5 hours ago, lupicus said: you should just apply damage to the current stack instead of creating a new stack (at least the way you are doing it) because you will lose other settings, like enchantments This is my new code: @Override public ActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) { if (!world.isClientSide) { ItemStack stack = playerEntity.getItemInHand(hand); stack.setDamageValue(stack.getDamageValue() + 1); return ActionResult.success(stack); } else return super.use(world, playerEntity, hand); } This still does not work. I can see that ActionResult.success(stack) does get run, because of the in game animation, but the durability doesn't change.
June 21, 20214 yr 20 minutes ago, RCKraken said: This still does not work. I can see that ActionResult.success(stack) does get run, because of the in game animation, but the durability doesn't change. playerEntity.getItemInHand(hand).setDamageValue(playerEntity.getItemInHand(hand).getDamageValue() + 1); this is the best solution for your problem
June 21, 20214 yr The new code you posted works, but you are probably in creative mode which restores item damage.
June 21, 20214 yr 5 hours ago, RCKraken said: doesn't return ActionResult.success(stack); give the player's hand the new itemstack? No. Compare and contrast: 14 hours ago, RCKraken said: ItemStack newStack = new ItemStack(stack.getItem()); //Creates a new stack 5 hours ago, RCKraken said: ItemStack stack = playerEntity.getItemInHand(hand); //Does not create a new stack Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
June 21, 20214 yr 5 hours ago, Luis_ST said: playerEntity.getItemInHand(hand).setDamageValue(playerEntity.getItemInHand(hand).getDamageValue() + 1); this is the best solution for your problem the only way in which this code differs from his, which is storing the ItemInHand in a local variable, is that this is less readable. as Lupicus said, his code works, he's probably just in creative mode. creative mode cancels any attempts at damaging items when using them Edited June 21, 20214 yr by kiou.23
June 23, 20214 yr Author So just for clarification, in case anyone has the same problem, if you're trying to damage an item on right click in creative mode, it will go down to whatever you set it to and then bounce right back, but has completely normal behavior in survival. I am beyond embarrassed that I spent 2 days on this lol. Thanks everyone!
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.