Skip to content

Commit

Permalink
Remove 'has recipe error' container data from smithing table
Browse files Browse the repository at this point in the history
Fixes #909
  • Loading branch information
kennytv committed Nov 5, 2024
1 parent ab2a407 commit 498bec9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ protected void registerPackets() {
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
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_TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ public void registerPackets() {
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 -> {
updateContainerId(wrapper);

Expand All @@ -108,11 +120,24 @@ public void registerPackets() {
wrapper.passthrough(Types.SHORT); // Slot id
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.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.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 -> {
updateContainerIdServerbound(wrapper);
wrapper.passthrough(Types.VAR_INT); // State id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public final class InventoryStateIdStorage implements StorableObject {

private boolean smithingTableOpen;
private int stateId = -1;

public int stateId() {
Expand All @@ -30,4 +31,12 @@ public int stateId() {
public void setStateId(final int stateId) {
this.stateId = stateId;
}

public boolean smithingTableOpen() {
return smithingTableOpen;
}

public void setSmithingTableOpen(final boolean smithingTableOpen) {
this.smithingTableOpen = smithingTableOpen;
}
}

0 comments on commit 498bec9

Please sign in to comment.