Posted June 20, 20214 yr I have a backpack item with ItemStackHandler capability. A player can change the item's inventory on screen. The container gets the ItemStackHandler capability from the backpack in the player's chest slot and dynamically changes the inventory. so it needs to be synchronized with the client backpack when the container is opened or the inventory changes. How do I use packets to synchronize the server ItemStack capability with the client ItemStack capability? My code is here . Edited June 20, 20214 yr by Zemelua
June 20, 20214 yr Author But in fact it is not saved. When is the container and screen synced? And what do you think is the reason why it isn't done? https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/inventory/container/BelongingsUMUPlayerContainer.java
June 20, 20214 yr https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/inventory/container/BelongingsUMUPlayerContainer.java#L60 what are you doing here ?
June 20, 20214 yr Author 2 hours ago, diesieben07 said: What do you mean by this? My explanation was insufficient. The problem I'm having is that if I change the chest backpack with the BelongingsUMUPlayerContainer open, its contents will appear in the backpack slot. However, if I make changes to the backpack slot in that state, the changes are not saved when I close the container. When I reopen it, it will return to the state before I made the change. 2 hours ago, loordgek said: what are you doing here ? In AbstractBelongingSlot, unlike the SlotItemHandler class, itemHandler field is dynamic (not final). When SlotItemHandler class references an itemHandler, it's basically via getItemHandler(), so I can override it to return a dynamic inventory. However, some methods that are not related to the inventory contents refer directly to the itemHandler field. In other words, the itemHandler field is fine with dynamic inventory, but I'm just passing another baseItemHandler to get some elements. Its contents are not used. You don't have to worry about it.
June 21, 20214 yr Author I've been working on this issue for over a week and I don't know the cause at all ... I think it's a hassle, but could anyone help identify the cause? Please......
June 21, 20214 yr after a bit of testing i found the problem this.player.getItemStackFromSlot(EquipmentSlotType.CHEST).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(new ItemStackHandler(36) .orElse(new ItemStackHandler(36) < that is the problem NEVER EVER do that. you should never return a new object in .orElse Edited June 21, 20214 yr by loordgek
June 21, 20214 yr fixed here you are trying to get your capablilty from your backpack w/ no side(null) https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/inventory/container/BelongingsUMUPlayerContainer.java#L61 here you check if there is no side(null) https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/capability/FunctionalBackpackCapabilityProvider.java#L29 so you never get the capablilty use ifPresent instead of orElse so .ifPresent(add the slots in here)
June 22, 20214 yr Author 10 hours ago, loordgek said: .orElse(new ItemStackHandler(36) < that is the problem I fixed. Backpacks should always have Capability. .orElseThrow(() -> new IllegalStateException("Backpack inventory is Empty!")) 9 hours ago, loordgek said: so you never get the capablilty It's confusing, but there are two types, Backpack and Functional Backpack, and Backpack doesn't require a side argument. In the test, I used only Backpack, so there was no problem. I've solved these issues, but I'm still not solving the issue where inventory isn't applied ... https://github.com/Zemelua/UMU-Mod/blob/main/src/main/java/io/github/zemelua/umumod/inventory/container/AbstractUMUPlayerContainer.java#L37 It's possible that there's a problem with the arguments I'm passing on this line, but I'm not sure what's wrong. The method of implementing IContainerListener and updating the inventory as a listener also didn't work. (It looks like I need to update backpack's inventory before slotClick() is done.)
June 23, 20214 yr Author 1. Prepare two Backpacks. 2. With one Backpack on your chest, open the BelongingsScreen. 3. In the BelongingsScreen, remove the equipped Backpack and equip another one. 4. Place any items in the backpack slot. 5. Close the Screen as it is. 6. When you open the Screen again with the second Backpack equipped, the items you should have put in are missing.
June 23, 20214 yr Author Yes, that's the problem. I should be updating the inventory of the slot itself with updateInventory(), but what else is linking the inventory to the slot? Can I update it then?
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.