mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +01:00
There can be only one
- Fix RetexturingVertexList by multiplying by 16 - Switch Chests and Shulkers to use MeshTreeCache
This commit is contained in:
parent
b51ccd43e2
commit
d2aa2e0013
3 changed files with 36 additions and 18 deletions
|
@ -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<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
}
|
||||
|
||||
private static final ModelCache<Pair<ChestType, Material>> 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<Pair<ChestType, Material>> 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<Pair<ChestType, Material>> 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<T extends BlockEntity & LidBlockEntity> 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<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
lid.delete();
|
||||
lock.delete();
|
||||
}
|
||||
|
||||
public static Model chestModel(Pair<ChestType, Material> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ShulkerBoxBlockEntity> implements SimpleDynamicVisual {
|
||||
private static final ModelCache<Material> 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<Material> 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<ShulkerBoxBlockE
|
|||
TransformStack.of(stack)
|
||||
.translate(getVisualPosition())
|
||||
.translate(0.5)
|
||||
.scale(0.9995f)
|
||||
.rotate(rotation)
|
||||
.scale(1, -1, -1)
|
||||
.translateY(-1);
|
||||
.scale(0.9995f)
|
||||
.translate(0, -0.5, 0)
|
||||
.scale(1, -1, -1);
|
||||
|
||||
base = createBaseInstance(texture).setTransform(stack);
|
||||
lid = createLidInstance(texture).setTransform(stack);
|
||||
|
@ -134,4 +136,11 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
|||
base.delete();
|
||||
lid.delete();
|
||||
}
|
||||
|
||||
private static Model shulkerModel(Material texture, String child) {
|
||||
var mesh = MeshTreeCache.get(ModelLayers.SHULKER)
|
||||
.child(child)
|
||||
.mesh();
|
||||
return new SingleMeshModel(new RetexturedMesh(mesh, texture.sprite()), Materials.SHULKER);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ public class RetexturingVertexList extends WrappedVertexList {
|
|||
|
||||
@Override
|
||||
public void u(int index, float u) {
|
||||
super.u(index, sprite.getU(u));
|
||||
super.u(index, sprite.getU(u * 16));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void v(int index, float v) {
|
||||
super.v(index, sprite.getV(v));
|
||||
super.v(index, sprite.getV(v * 16));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue