Repository navigation
Conversation
| handler(wrapper -> { | ||
| if (wrapper.get(Types.VAR_INT, 0) == tracker(wrapper.user()).clientEntityId()) { | ||
| // Vanilla 1.8.9 doesn't properly handle this and Forge handles it differently, use set | ||
| // slot packets instead | ||
| final Item item = wrapper.get(Types.ITEM1_8, 0); | ||
| final int slot = 4 - wrapper.get(Types.SHORT, 0); | ||
| wrapper.cancel(); | ||
| final ContainerEquipmentTracker equipment = wrapper.user().get(ContainerEquipmentTracker.class); | ||
| final WindowTracker window = wrapper.user().get(WindowTracker.class); | ||
| equipment.setEquipment(slot, item); | ||
| if (window.openWindowId() == 0) { | ||
| equipment.sendAsSlot(wrapper.user(), slot); | ||
| } | ||
| } | ||
| }); |
There was a problem hiding this comment.
There should probably be a check whether wrapper is cancelled + a slot check (to prevent offhand/main handmessing with equipment)
handler(wrapper -> {
if (wrapper.isCancelled()) {
return;
}
if (wrapper.get(Types.VAR_INT, 0) == tracker(wrapper.user()).clientEntityId()) {
// Vanilla 1.8.9 doesn't properly handle this and Forge handles it differently, use set
// slot packets instead
wrapper.cancel();
final short equipmentSlot = wrapper.get(Types.SHORT, 0);
if (equipmentSlot < 1 || equipmentSlot > 4) {
return;
}
final Item item = wrapper.get(Types.ITEM1_8, 0);
final int slot = 4 - equipmentSlot;
final ContainerEquipmentTracker equipment = wrapper.user().get(ContainerEquipmentTracker.class);
final WindowTracker window = wrapper.user().get(WindowTracker.class);
equipment.setEquipment(slot, item);
if (window.openWindowId() == 0) {
equipment.sendAsSlot(wrapper.user(), slot);
}
}
});There was a problem hiding this comment.
you're right, worth noting though that back then Florian didn't really like this part that touches equipment packets, so it might be removed eventually
iirc it was because this isn't possible in vanilla and is instead just something viabackwards uses, the alternative is to change the viabackwards patch to use -2 set slots which I wouldn't be completely against (esp. if it makes this patch cleaner)
|
|
||
| if (windowId != 0) { | ||
| final ContainerEquipmentTracker equipment = wrapper.user().get(ContainerEquipmentTracker.class); | ||
| equipment.sendAll(wrapper.user()); | ||
| } |
There was a problem hiding this comment.
the equipment flushing should happen after the container close packet
also the 1.8 client does not care about window id for the close container packet, so the window id check is not needed (this also needs a fix in WindowTracker then)
There was a problem hiding this comment.
would it still not be good to skip equipment checking/flushing if the server thinks it's closing the player inventory?
There was a problem hiding this comment.
would it still not be good to skip equipment checking/flushing if the server thinks it's closing the player inventory?
well technically a modded server could close a custom window using window id 0 and then viarewind will never flush equipment
| } else if (slot >= 9 && slot <= 35) { | ||
| containerSlot = size + slot - 9; | ||
| } else { // armor/offhand: no slot in a foreign container | ||
| if (slot <= 39) { |
There was a problem hiding this comment.
| if (slot <= 39) { | |
| if (slot >= 36 && slot <= 39) { |
There was a problem hiding this comment.
sure, though i guess this just catches invalid (< 0) inputs
70ac883 to
ef03076
Compare
As mentioned on Discord, properly handles what was reported in #733.
Test this by running
/item replace entity @p armor.chest with [anything]while the player (on 1.8) has a chest/container open. Other interactions that would update the item like damaging armor would work too.In brief:
This makes it so equipment changes while inside foreign containers are tracked and sent when the container is closed. This also handles equipment sent as set slot packets with window ID -2, which is not present in 1.8.
To test the -2 case, you can apply this patch to ViaBackwards, which is an alternative version of the one linked above (tested working in 1.21.1):
ViaBackwards patch for -2 set slot