IntentScarab Posted February 16, 2021 Posted February 16, 2021 Hello, I am trying to create an item that holds experience, later it will be blocks but little steps, and when I move the experience from the Player into the book, the exp bar doesn't update. Right now I have this: playerIn.experienceTotal -= expToStore; And the next time I use the Experience Book it does say that I don't have any experience left, just that the bar doesn't update. I've tried looking at the Enchanting Table Block/Tile Entity/Container, and from what I've seen they mark the inventory dirty when using the player experience, so I added this: playerIn.inventory.markDirty(); This hasn't fixed my problem, so I must be missing something. Full code for onItemRightClick here: public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ItemStack stack = playerIn.getHeldItem(Hand.MAIN_HAND).getStack(); currentStoredExp = stack.getOrCreateTag().getInt("exp"); int expLevel = ExperienceHelper.playerTotalExp(playerIn); int expTotal = playerIn.experienceTotal; if (expTotal <= 0 || currentStoredExp == MAX_EXP) { return new ActionResult<>(ActionResultType.PASS, stack); } if ((!playerIn.isSneaking()) && handIn == Hand.MAIN_HAND && currentStoredExp < MAX_EXP) { int expToStore = (expLevel < (MAX_EXP - currentStoredExp)) ? expLevel : (MAX_EXP - currentStoredExp); //TODO: not the way to remove exp from the player app playerIn.experienceTotal -= expToStore; expToStore += currentStoredExp; stack.getTag().putInt("exp", expToStore); playerIn.inventory.markDirty(); return new ActionResult<>(ActionResultType.SUCCESS, stack); } return new ActionResult<>(ActionResultType.PASS, stack); } If I have missed anything, please let me know. Thank you! Quote
Luis_ST Posted February 17, 2021 Posted February 17, 2021 13 hours ago, IntentScarab said: This hasn't fixed my problem, so I must be missing something. Full code for onItemRightClick here: I think you should use that: player.addExperienceLevel(-5); 1 Quote
IntentScarab Posted February 17, 2021 Author Posted February 17, 2021 Oh wow, that worked. Thank you very much I have another issue with the durability bar, but I'll work on that for a while before asking the forum. Thanks again! 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.