Jump to content

Recommended Posts

Posted (edited)

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 by Zemelua
Posted
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.

Posted

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......

Posted (edited)

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 by loordgek
Posted

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)

Posted
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.)

Posted

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.

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.