Process default water color as null

This commit is contained in:
tibs 2022-04-13 19:03:56 -04:00
parent dd82aca3c9
commit 471eb9007d
Signed by untrusted user who does not match committer: tibs
GPG key ID: 047833989F50F88F

View file

@ -14,11 +14,12 @@ import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class WaterCauldronBlockEntity extends BlockEntity { public class WaterCauldronBlockEntity extends BlockEntity {
private final int[] EMPTY_NBT = new int[] {-1, -1, -1};
private int[] color; private int[] color;
public WaterCauldronBlockEntity(BlockPos pos, BlockState state) { public WaterCauldronBlockEntity(BlockPos pos, BlockState state) {
super(CauldronDyeing.WATER_CAULDRON_BLOCK_ENTITY, pos, state); super(CauldronDyeing.WATER_CAULDRON_BLOCK_ENTITY, pos, state);
color = new int[]{-1, -1, -1}; color = null;
} }
// Formula taken from https://minecraft.fandom.com/wiki/Dye#Dyeing_armor and DyeableItem#blendAndSetColor // Formula taken from https://minecraft.fandom.com/wiki/Dye#Dyeing_armor and DyeableItem#blendAndSetColor
@ -30,7 +31,7 @@ public class WaterCauldronBlockEntity extends BlockEntity {
newColor[1] = (int) (colorComponents[1] * 255.0f); newColor[1] = (int) (colorComponents[1] * 255.0f);
newColor[2] = (int) (colorComponents[2] * 255.0f); newColor[2] = (int) (colorComponents[2] * 255.0f);
if (hasColor()) { if (color != null) {
var avgColor = new int[3]; var avgColor = new int[3];
avgColor[0] = (color[0] + newColor[0]) / 2; avgColor[0] = (color[0] + newColor[0]) / 2;
avgColor[1] = (color[1] + newColor[1]) / 2; avgColor[1] = (color[1] + newColor[1]) / 2;
@ -51,29 +52,26 @@ public class WaterCauldronBlockEntity extends BlockEntity {
markDirty(); markDirty();
} }
public boolean hasColor() {
return color.length == 3 && color[0] != -1 && color[1] != -1 && color[2] != -1;
}
public int getColor() { public int getColor() {
return hasColor() ? (color[0] << 16) + (color[1] << 8) + color[2] : -1; return color != null ? (color[0] << 16) + (color[1] << 8) + color[2] : -1;
} }
public void resetColor() { public void resetColor() {
color = new int[]{-1, -1, -1}; color = null;
markDirty(); markDirty();
} }
@Override @Override
public void writeNbt(NbtCompound tag) { public void writeNbt(NbtCompound tag) {
super.writeNbt(tag); super.writeNbt(tag);
tag.putIntArray("color", color); tag.putIntArray("color", color != null ? color : EMPTY_NBT);
} }
@Override @Override
public void readNbt(NbtCompound tag) { public void readNbt(NbtCompound tag) {
super.readNbt(tag); super.readNbt(tag);
color = tag.getIntArray("color"); var value = tag.getIntArray("color");
color = value != EMPTY_NBT ? color : null;
markDirty(); markDirty();
} }