diff --git a/CHANGELOG.md b/CHANGELOG.md index 3766e6a8..c1dd06b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,4 +91,11 @@ - Fixed X-ray with certain mods using double shelves blocks. +### 1.0.0-beta.18 + +- Improved rendering performances of the painter's palette. +- Improved compatibility for wood-based features. +- Fixed wrong leaf texture on cherry wood stumps. +- Fixed bad serialization of empty blackboards causing stacking issues. + [EMI]: https://modrinth.com/mod/emi "EMI Modrinth page" diff --git a/gradle.properties b/gradle.properties index d89b67a5..dc89fa83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx1G # Mod properties -mod_version=1.0.0-beta.17 +mod_version=1.0.0-beta.18 maven_group=dev.lambdaurora archives_base_name=aurorasdecorations modrinth_id=GOqAnOfW diff --git a/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/Blackboard.java b/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/Blackboard.java index e55e818f..a9a6024a 100644 --- a/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/Blackboard.java +++ b/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/Blackboard.java @@ -313,11 +313,13 @@ public NbtCompound writeNbt(NbtCompound nbt) { } } + nbt.putInt("version", 2); nbt.putByteArray("pixels", pixels); + nbt.putBoolean("lit", this.isLit()); + } else if (this.isLit()) { + nbt.putBoolean("lit", true); } - nbt.putBoolean("lit", this.isLit()); - nbt.putInt("version", 2); return nbt; } diff --git a/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardColor.java b/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardColor.java index 8c2286a5..91038014 100644 --- a/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardColor.java +++ b/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardColor.java @@ -236,8 +236,8 @@ public static void tryRegisterColorFromItem(Identifier id, Item item) { } @Override - public boolean matchItem(ItemStack item) { - return this.item == item.getItem(); + public boolean matchItem(Item item) { + return this.item == item; } @Override diff --git a/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardDrawModifier.java b/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardDrawModifier.java index ee23aeae..837d4ee3 100644 --- a/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardDrawModifier.java +++ b/src/main/java/dev/lambdaurora/aurorasdeco/blackboard/BlackboardDrawModifier.java @@ -17,6 +17,7 @@ package dev.lambdaurora.aurorasdeco.blackboard; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.registry.tag.ItemTags; @@ -38,8 +39,9 @@ public abstract class BlackboardDrawModifier { public static final BlackboardDrawModifier SHADE_INCREASE = new BlackboardDrawModifier("aurorasdeco.blackboard.modifier.darken", 0xff444444) { @Override - public boolean matchItem(ItemStack item) { - return item.isIn(ItemTags.COALS); + @SuppressWarnings("deprecated") + public boolean matchItem(Item item) { + return item.getBuiltInRegistryHolder().isIn(ItemTags.COALS); } @Override @@ -57,8 +59,8 @@ public short apply(short colorData) { public static final BlackboardDrawModifier SHADE_DECREASE = new BlackboardDrawModifier("aurorasdeco.blackboard.modifier.lighten", 0xffeeeeee) { @Override - public boolean matchItem(ItemStack item) { - return item.isOf(Items.BONE_MEAL); + public boolean matchItem(Item item) { + return item == Items.BONE_MEAL; } @Override @@ -76,8 +78,8 @@ public short apply(short colorData) { public static final BlackboardDrawModifier SATURATION = new BlackboardDrawModifier("aurorasdeco.blackboard.modifier.saturation", 0xffffbc5e) { @Override - public boolean matchItem(ItemStack item) { - return item.isOf(Items.GLOWSTONE_DUST); + public boolean matchItem(Item item) { + return item == Items.GLOWSTONE_DUST; } @Override @@ -111,11 +113,11 @@ public int getColor() { return this.color; } - public abstract boolean matchItem(ItemStack item); + public abstract boolean matchItem(Item item); public abstract short apply(short colorData); - public static @Nullable BlackboardDrawModifier fromItem(ItemStack item) { + public static @Nullable BlackboardDrawModifier fromItem(Item item) { for (var modifier : MODIFIERS) { if (modifier.matchItem(item)) return modifier; @@ -123,4 +125,8 @@ public int getColor() { return null; } + + public static @Nullable BlackboardDrawModifier fromItem(ItemStack item) { + return fromItem(item.getItem()); + } } diff --git a/src/main/java/dev/lambdaurora/aurorasdeco/item/PainterPaletteItem.java b/src/main/java/dev/lambdaurora/aurorasdeco/item/PainterPaletteItem.java index 0434aebd..faa81581 100644 --- a/src/main/java/dev/lambdaurora/aurorasdeco/item/PainterPaletteItem.java +++ b/src/main/java/dev/lambdaurora/aurorasdeco/item/PainterPaletteItem.java @@ -35,12 +35,14 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; +import net.minecraft.registry.Registries; import net.minecraft.screen.PropertyDelegate; import net.minecraft.screen.slot.Slot; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.ClickType; import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -194,15 +196,63 @@ public boolean onScroll(PlayerEntity player, ItemStack paletteStack, double scro } public int getColor(ItemStack paletteStack, int tintIndex) { - var inventory = PainterPaletteInventory.fromNbt(paletteStack.getSubNbt("inventory")); + NbtCompound nbt = paletteStack.getSubNbt("inventory"); + + BlackboardDrawModifier primaryColor = null; + BlackboardDrawModifier previousColor = null; + BlackboardDrawModifier nextColor = null; + + if (nbt != null) { + int selectedColor; + + if (nbt.contains(PainterPaletteInventory.SELECTED_COLOR_KEY, NbtElement.BYTE_TYPE)) { + selectedColor = nbt.getByte(PainterPaletteInventory.SELECTED_COLOR_KEY); + } else { + selectedColor = 0; + } + + NbtList colors = nbt.getList("colors", NbtElement.COMPOUND_TYPE); + + int previousSlot = -1, nextSlot = -1; + NbtCompound previousNbt = null, nextNbt = null; + + for (var colorNbt : colors) { + var slotNbt = (NbtCompound) colorNbt; + int slot = slotNbt.getByte("slot"); - var primaryColor = BlackboardDrawModifier.fromItem(inventory.getSelectedColor()); - BlackboardDrawModifier nextColor = inventory.getNextColor(); - BlackboardDrawModifier previousColor = inventory.getPreviousColor(); + if (slot == selectedColor) { + primaryColor = modifierFromNbt(slotNbt); + } else if (slot > selectedColor) { + if (nextSlot < selectedColor || slot < nextSlot || nextSlot == -1) { + nextSlot = slot; + nextNbt = slotNbt; + } + if (previousSlot == -1 || (slot > previousSlot && previousSlot > selectedColor)) { + previousSlot = slot; + previousNbt = slotNbt; + } + } else { + if (nextSlot == -1 || (slot < nextSlot && nextSlot < selectedColor)) { + nextSlot = slot; + nextNbt = slotNbt; + } + if (previousSlot > selectedColor || slot > previousSlot || previousSlot == -1) { + previousSlot = slot; + previousNbt = slotNbt; + } + } + } + + if (nextSlot == -1 || nextSlot == previousSlot) nextNbt = null; + if (previousSlot == -1) previousNbt = null; - if (primaryColor == BlackboardColor.EMPTY) primaryColor = null; - if (previousColor == BlackboardColor.EMPTY) previousColor = null; - if (nextColor == BlackboardColor.EMPTY) nextColor = null; + previousColor = previousNbt == null ? BlackboardColor.EMPTY : modifierFromNbt(previousNbt); + nextColor = nextNbt == null ? BlackboardColor.EMPTY : modifierFromNbt(nextNbt); + + if (primaryColor == BlackboardColor.EMPTY) primaryColor = null; + if (previousColor == BlackboardColor.EMPTY) previousColor = null; + if (nextColor == BlackboardColor.EMPTY) nextColor = null; + } return switch (tintIndex) { case 1 -> primaryColor == null ? DEFAULT_BACKGROUND_COLOR : primaryColor.getColor(); @@ -309,34 +359,33 @@ public PropertyDelegate getProperties() { } private byte findFirstNextColor() { - byte i = (byte) ((this.selectedColor + 1) % COLOR_SIZE); - while (i != this.selectedColor) { + byte i = this.selectedColor; + + do { + i = (byte) ((i + 1) % COLOR_SIZE); var stack = this.getStack(i); if (!stack.isEmpty()) { return i; } - - i = (byte) ((i + 1) % COLOR_SIZE); - } + } while (i != this.selectedColor); return -1; } private byte findFirstPreviousColor() { - byte i = (byte) (this.selectedColor - 1); - if (i == -1) i = COLOR_SIZE - 1; + byte i = this.selectedColor; + + do { + i--; + if (i == -1) i = COLOR_SIZE - 1; - while (i != this.selectedColor) { var stack = this.getStack(i); if (!stack.isEmpty()) { return i; } - - i--; - if (i == -1) i = COLOR_SIZE - 1; - } + } while (i != this.selectedColor); return -1; } @@ -478,4 +527,16 @@ private void readInventoryPart(NbtList nbtList, int from) { } } } + + private static BlackboardDrawModifier modifierFromNbt(NbtCompound nbt) { + var itemNbt = nbt.getCompound("item"); + Identifier id = Identifier.tryParse(itemNbt.getString("id")); + + if (id == null) return BlackboardColor.EMPTY; + + Item item = Registries.ITEM.get(id); + BlackboardDrawModifier modifier = BlackboardDrawModifier.fromItem(item); + + return modifier == null ? BlackboardColor.EMPTY : modifier; + } } diff --git a/src/main/java/dev/lambdaurora/aurorasdeco/registry/WoodType.java b/src/main/java/dev/lambdaurora/aurorasdeco/registry/WoodType.java index 238b98e0..d8c80db5 100644 --- a/src/main/java/dev/lambdaurora/aurorasdeco/registry/WoodType.java +++ b/src/main/java/dev/lambdaurora/aurorasdeco/registry/WoodType.java @@ -397,10 +397,24 @@ public enum ComponentType { if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(sideId)).isPresent()) return sideId; - // For mods similar to how Promenade does it. - sideId = new Identifier(componentId.getNamespace(), "block/" + componentId.getPath() + "/side"); + // For mods that don't use standard texture paths but logically evil. + sideId = new Identifier( + componentId.getNamespace(), + "block/" + component.woodType().getId().getPath() + "/" + component.woodType().getLogType() + "/side" + ); + if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(sideId)).isPresent()) + return sideId; + + // For mods similar to how Yttr does it. + sideId = new Identifier(componentId.getNamespace(), "block/" + componentId.getPath() + "_side"); if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(sideId)).isPresent()) return sideId; + + // For mods similar to how Promenade did it. + sideId = new Identifier(componentId.getNamespace(), "block/" + componentId.getPath() + "/side"); + if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(sideId)).isPresent()) { + return sideId; + } } return texture; }, (resourceManager, component) -> { @@ -418,7 +432,12 @@ public enum ComponentType { if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(topId)).isPresent()) return topId; - // For mods similar to how Promenade does it. + // For mods that don't use standard texture paths but logically evil. + topId = new Identifier(componentId.getNamespace(), "block/" + component.woodType().getId().getPath() + "/log/top"); + if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(topId)).isPresent()) + return topId; + + // For mods similar to how Promenade did it. topId = new Identifier(componentId.getNamespace(), "block/" + componentId.getPath() + "/top"); if (resourceManager.getResource(AuroraUtil.toAbsoluteTexturesId(topId)).isPresent()) return topId; diff --git a/src/main/resources/assets/aurorasdeco/blockstates/stump/yttr/squeeze.json b/src/main/resources/assets/aurorasdeco/blockstates/stump/yttr/squeeze.json new file mode 100644 index 00000000..17febe69 --- /dev/null +++ b/src/main/resources/assets/aurorasdeco/blockstates/stump/yttr/squeeze.json @@ -0,0 +1,21 @@ +{ + "variants": { + "": [ + { + "model": "aurorasdeco:block/stump/yttr/squeeze", + "y": 180 + }, + { + "model": "aurorasdeco:block/stump/yttr/squeeze" + }, + { + "model": "aurorasdeco:block/stump/yttr/squeeze", + "y": 90 + }, + { + "model": "aurorasdeco:block/stump/yttr/squeeze", + "y": 270 + } + ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/aurorasdeco/models/block/stump/cherry_brown_mushroom.json b/src/main/resources/assets/aurorasdeco/models/block/stump/cherry_brown_mushroom.json new file mode 100644 index 00000000..a989d0a8 --- /dev/null +++ b/src/main/resources/assets/aurorasdeco/models/block/stump/cherry_brown_mushroom.json @@ -0,0 +1,9 @@ +{ + "parent": "aurorasdeco:block/template/log_stump_brown_mushroom", + "textures": { + "log_side": "minecraft:block/cherry_log", + "log_top": "minecraft:block/cherry_log_top", + "leaf": "aurorasdeco:block/cherry_log_stump_leaf", + "mushroom": "minecraft:block/brown_mushroom_block" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/aurorasdeco/models/block/stump/cherry_red_mushroom.json b/src/main/resources/assets/aurorasdeco/models/block/stump/cherry_red_mushroom.json new file mode 100644 index 00000000..3bfd2155 --- /dev/null +++ b/src/main/resources/assets/aurorasdeco/models/block/stump/cherry_red_mushroom.json @@ -0,0 +1,9 @@ +{ + "parent": "aurorasdeco:block/template/log_stump_red_mushroom", + "textures": { + "log_side": "minecraft:block/cherry_log", + "log_top": "minecraft:block/cherry_log_top", + "leaf": "aurorasdeco:block/cherry_log_stump_leaf", + "mushroom": "minecraft:block/red_mushroom_block" + } +} \ No newline at end of file