From d2aa2e0013fa09c756df9376b28251b30ca35e60 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 9 Apr 2024 21:57:57 -0700 Subject: [PATCH] There can be only one - Fix RetexturingVertexList by multiplying by 16 - Switch Chests and Shulkers to use MeshTreeCache --- .../flywheel/vanilla/ChestVisual.java | 27 ++++++++++++------- .../flywheel/vanilla/ShulkerBoxVisual.java | 23 +++++++++++----- .../vanilla/model/RetexturingVertexList.java | 4 +-- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java index f03b19ae9..16a1d07f9 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java @@ -8,6 +8,7 @@ import java.util.function.Consumer; import org.joml.Quaternionf; import com.jozufozu.flywheel.api.instance.Instance; +import com.jozufozu.flywheel.api.model.Model; import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.instance.OrientedInstance; @@ -15,10 +16,11 @@ import com.jozufozu.flywheel.lib.instance.TransformedInstance; import com.jozufozu.flywheel.lib.material.Materials; import com.jozufozu.flywheel.lib.model.ModelCache; import com.jozufozu.flywheel.lib.model.SingleMeshModel; -import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.util.Pair; import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; import com.jozufozu.flywheel.lib.visual.SimpleDynamicVisual; +import com.jozufozu.flywheel.vanilla.model.MeshTreeCache; +import com.jozufozu.flywheel.vanilla.model.RetexturedMesh; import it.unimi.dsi.fastutil.floats.Float2FloatFunction; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -43,23 +45,23 @@ public class ChestVisual extends Abstrac } private static final ModelCache> BOTTOM_MODELS = new ModelCache<>(key -> { - return new SingleMeshModel(ModelPartConverter.convert(LAYER_LOCATIONS.get(key.first()), key.second().sprite(), "bottom"), Materials.CHEST); + return chestModel(key, "bottom"); }); private static final ModelCache> LID_MODELS = new ModelCache<>(key -> { - return new SingleMeshModel(ModelPartConverter.convert(LAYER_LOCATIONS.get(key.first()), key.second().sprite(), "lid"), Materials.CHEST); + return chestModel(key, "lid"); }); private static final ModelCache> LOCK_MODELS = new ModelCache<>(key -> { - return new SingleMeshModel(ModelPartConverter.convert(LAYER_LOCATIONS.get(key.first()), key.second().sprite(), "lock"), Materials.CHEST); + return chestModel(key, "lock"); }); private OrientedInstance bottom; + private TransformedInstance lid; private TransformedInstance lock; - private ChestType chestType; + private final Quaternionf baseRotation = new Quaternionf(); private Float2FloatFunction lidProgress; - private float lastProgress = Float.NaN; public ChestVisual(VisualizationContext ctx, T blockEntity) { @@ -141,15 +143,13 @@ public class ChestVisual extends Abstrac .rotateCentered(baseRotation) .translate(0, 9f / 16f, 1f / 16f) .rotateX(angleX) - .translate(0, -9f / 16f, -1f / 16f) .setChanged(); lock.loadIdentity() .translate(getVisualPosition()) .rotateCentered(baseRotation) - .translate(0, 8f / 16f, 0) + .translate(0, 9f / 16f, 1f / 16f) .rotateX(angleX) - .translate(0, -8f / 16f, 0) .setChanged(); } @@ -171,4 +171,13 @@ public class ChestVisual extends Abstrac lid.delete(); lock.delete(); } + + public static Model chestModel(Pair key, String child) { + var mesh = MeshTreeCache.get(LAYER_LOCATIONS.get(key.first())) + .child(child) + .mesh(); + var sprite = key.second() + .sprite(); + return new SingleMeshModel(new RetexturedMesh(mesh, sprite), Materials.CHEST); + } } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java index 12eda7ca7..b00635597 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java @@ -5,16 +5,18 @@ import java.util.function.Consumer; import org.joml.Quaternionf; import com.jozufozu.flywheel.api.instance.Instance; +import com.jozufozu.flywheel.api.model.Model; import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.instance.TransformedInstance; import com.jozufozu.flywheel.lib.material.Materials; import com.jozufozu.flywheel.lib.model.ModelCache; import com.jozufozu.flywheel.lib.model.SingleMeshModel; -import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.transform.TransformStack; import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; import com.jozufozu.flywheel.lib.visual.SimpleDynamicVisual; +import com.jozufozu.flywheel.vanilla.model.MeshTreeCache; +import com.jozufozu.flywheel.vanilla.model.RetexturedMesh; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; @@ -28,15 +30,15 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; public class ShulkerBoxVisual extends AbstractBlockEntityVisual implements SimpleDynamicVisual { private static final ModelCache BASE_MODELS = new ModelCache<>(texture -> { - return new SingleMeshModel(ModelPartConverter.convert(ModelLayers.SHULKER, texture.sprite(), "base"), Materials.SHULKER); + return shulkerModel(texture, "base"); }); private static final ModelCache LID_MODELS = new ModelCache<>(texture -> { - return new SingleMeshModel(ModelPartConverter.convert(ModelLayers.SHULKER, texture.sprite(), "lid"), Materials.SHULKER); + return shulkerModel(texture, "lid"); }); private TransformedInstance base; - private TransformedInstance lid; + private TransformedInstance lid; private final PoseStack stack = new PoseStack(); private float lastProgress = Float.NaN; @@ -61,10 +63,10 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual