Fixed spellbook not repainting when its state is updated from the server

This commit is contained in:
Sollace 2023-01-21 22:52:20 +00:00
parent 65c1c4289d
commit 598f4273da
2 changed files with 12 additions and 0 deletions

View file

@ -134,6 +134,9 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> imple
@Override @Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) { public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
if (getState().isDirty()) {
clearAndInit();
}
super.render(matrices, mouseX, mouseY, partialTicks); super.render(matrices, mouseX, mouseY, partialTicks);
drawMouseoverTooltip(matrices, mouseX, mouseY); drawMouseoverTooltip(matrices, mouseX, mouseY);
} }

View file

@ -15,8 +15,16 @@ import net.minecraft.util.math.MathHelper;
public class SpellbookState extends Synchronizable<SpellbookState> implements NbtSerialisable { public class SpellbookState extends Synchronizable<SpellbookState> implements NbtSerialisable {
private Optional<Identifier> currentPageId = Optional.empty(); private Optional<Identifier> currentPageId = Optional.empty();
private boolean dirty;
private final Map<Identifier, PageState> states = new HashMap<>(); private final Map<Identifier, PageState> states = new HashMap<>();
public boolean isDirty() {
boolean isDirty = dirty;
dirty = false;
return isDirty;
}
public Optional<Identifier> getCurrentPageId() { public Optional<Identifier> getCurrentPageId() {
return currentPageId; return currentPageId;
} }
@ -34,6 +42,7 @@ public class SpellbookState extends Synchronizable<SpellbookState> implements Nb
public void copyFrom(SpellbookState state) { public void copyFrom(SpellbookState state) {
currentPageId = state.currentPageId; currentPageId = state.currentPageId;
state.states.forEach((id, page) -> getState(id).copyFrom(page)); state.states.forEach((id, page) -> getState(id).copyFrom(page));
dirty = true;
} }
public void toPacket(PacketByteBuf buf) { public void toPacket(PacketByteBuf buf) {