Skip to content

Commit

Permalink
Improve performances, compatibility, and fix some things.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Aug 10, 2023
1 parent 51e5c9a commit 58422f9
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 35 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -111,16 +113,20 @@ 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;
}

return null;
}

public static @Nullable BlackboardDrawModifier fromItem(ItemStack item) {
return fromItem(item.getItem());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
25 changes: 22 additions & 3 deletions src/main/java/dev/lambdaurora/aurorasdeco/registry/WoodType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
]
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 58422f9

Please sign in to comment.