Skip to content

Commit

Permalink
Extra bracket validation Creators-of-Create#6271
Browse files Browse the repository at this point in the history
  • Loading branch information
simibubi committed Jul 25, 2024
1 parent f6dfe7d commit dd7eedd
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public BlockState removeBracket(boolean inOnReplacedContext) {
public boolean isBracketPresent() {
return bracket != null;
}

public boolean isBracketValid(BlockState bracketState) {
return bracketState.getBlock() instanceof BracketBlock;
}

@Nullable
public BlockState getBracket() {
Expand All @@ -110,7 +114,7 @@ public boolean isSafeNBT() {

@Override
public void write(CompoundTag nbt, boolean clientPacket) {
if (isBracketPresent()) {
if (isBracketPresent() && isBracketValid(bracket)) {
nbt.put("Bracket", NbtUtils.writeBlockState(bracket));
}
if (clientPacket && reRender) {
Expand All @@ -122,8 +126,12 @@ public void write(CompoundTag nbt, boolean clientPacket) {

@Override
public void read(CompoundTag nbt, boolean clientPacket) {
if (nbt.contains("Bracket"))
bracket = NbtUtils.readBlockState(nbt.getCompound("Bracket"));
if (nbt.contains("Bracket")) {
bracket = null;
BlockState readBlockState = NbtUtils.readBlockState(nbt.getCompound("Bracket"));
if (isBracketValid(readBlockState))
bracket = readBlockState;
}
if (clientPacket && nbt.contains("Redraw"))
getWorld().sendBlockUpdated(getPos(), blockEntity.getBlockState(), blockEntity.getBlockState(), 16);
super.read(nbt, clientPacket);
Expand Down

0 comments on commit dd7eedd

Please sign in to comment.