Remove 'has recipe error' container data from smithing table

Fixes #909
This commit is contained in:
Nassim Jahnke 2024-11-05 20:18:48 +01:00
parent ab2a407742
commit 498bec9065
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 37 additions and 4 deletions

View File

@ -86,7 +86,6 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol<ClientboundPac
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS); new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES); new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES);
translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);

View File

@ -86,6 +86,18 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
handleItemToClient(wrapper.user(), item); handleItemToClient(wrapper.user(), item);
}); });
protocol.registerClientbound(ClientboundPackets1_21_2.OPEN_SCREEN, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Id
final int containerType = wrapper.passthrough(Types.VAR_INT);
if (containerType == 21) {
// Track smithing table to remove new data
wrapper.user().get(InventoryStateIdStorage.class).setSmithingTableOpen(true);
}
protocol.getComponentRewriter().passthroughAndProcess(wrapper);
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> { protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> {
updateContainerId(wrapper); updateContainerId(wrapper);
@ -108,11 +120,24 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
wrapper.passthrough(Types.SHORT); // Slot id wrapper.passthrough(Types.SHORT); // Slot id
passthroughClientboundItem(wrapper); passthroughClientboundItem(wrapper);
}); });
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, wrapper -> {
updateContainerId(wrapper);
if (wrapper.user().get(InventoryStateIdStorage.class).smithingTableOpen()) {
// Cancel new data for smithing table
wrapper.cancel();
}
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, wrapper -> {
updateContainerId(wrapper);
wrapper.user().get(InventoryStateIdStorage.class).setSmithingTableOpen(false);
});
protocol.registerClientbound(ClientboundPackets1_21_2.SET_HELD_SLOT, ClientboundPackets1_21.SET_CARRIED_ITEM); protocol.registerClientbound(ClientboundPackets1_21_2.SET_HELD_SLOT, ClientboundPackets1_21.SET_CARRIED_ITEM);
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, this::updateContainerId);
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, this::updateContainerId);
protocol.registerClientbound(ClientboundPackets1_21_2.HORSE_SCREEN_OPEN, this::updateContainerId); protocol.registerClientbound(ClientboundPackets1_21_2.HORSE_SCREEN_OPEN, this::updateContainerId);
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, this::updateContainerIdServerbound); protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, wrapper -> {
updateContainerIdServerbound(wrapper);
wrapper.user().get(InventoryStateIdStorage.class).setSmithingTableOpen(false);
});
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> { protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> {
updateContainerIdServerbound(wrapper); updateContainerIdServerbound(wrapper);
wrapper.passthrough(Types.VAR_INT); // State id wrapper.passthrough(Types.VAR_INT); // State id

View File

@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.connection.StorableObject;
public final class InventoryStateIdStorage implements StorableObject { public final class InventoryStateIdStorage implements StorableObject {
private boolean smithingTableOpen;
private int stateId = -1; private int stateId = -1;
public int stateId() { public int stateId() {
@ -30,4 +31,12 @@ public final class InventoryStateIdStorage implements StorableObject {
public void setStateId(final int stateId) { public void setStateId(final int stateId) {
this.stateId = stateId; this.stateId = stateId;
} }
public boolean smithingTableOpen() {
return smithingTableOpen;
}
public void setSmithingTableOpen(final boolean smithingTableOpen) {
this.smithingTableOpen = smithingTableOpen;
}
} }