From 72c755ae132d930cc30e79ba2d1b55db39fd40d6 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:14:39 -0800 Subject: [PATCH] Explosive changes - Fix TNT minecarts' contents not receiving overlay and scaling - Fix all types of minecarts using the body model of the standard minecart - Add overlay to ColoredLitInstance - Make default chunk materials not disable overlay - Rename *Visualizer.shouldSkipRender -> skipVanillaRender - Rename Simple*Visualizer.configure -> builder - Rename Simple*Visualizer.*Config -> Builder - Make Simple*Visualizer.Builder always skip vanilla render by default - Remove DiffuseLightCalculator and associated methods in RenderMath - Add BackendImplemented annotation to Backend - Mark PoseTransformStack as Internal at the class level --- .../flywheel/api/backend/Backend.java | 2 + .../visualization/BlockEntityVisualizer.java | 7 +- .../api/visualization/EntityVisualizer.java | 7 +- .../visualization/VisualizationHelper.java | 6 +- .../lib/instance/ColoredLitInstance.java | 48 +++++---- .../flywheel/lib/instance/InstanceTypes.java | 56 +++++----- .../lib/instance/OrientedInstance.java | 102 ++++++++++-------- .../flywheel/lib/material/Materials.java | 10 -- .../lib/math/DiffuseLightCalculator.java | 14 --- .../flywheel/lib/math/RenderMath.java | 16 --- .../lib/transform/PoseTransformStack.java | 2 +- .../visual/SimpleBlockEntityVisualizer.java | 49 +++++---- .../lib/visual/SimpleEntityVisualizer.java | 49 +++++---- .../flywheel/vanilla/MinecartVisual.java | 42 +++++--- .../flywheel/vanilla/TntMinecartVisual.java | 41 +++++++ .../flywheel/vanilla/VanillaVisuals.java | 57 +++++----- .../flywheel/flywheel/instance/oriented.vert | 1 + .../flywheel/instance/transformed.vert | 1 + 18 files changed, 284 insertions(+), 226 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/lib/math/DiffuseLightCalculator.java create mode 100644 src/main/java/com/jozufozu/flywheel/vanilla/TntMinecartVisual.java diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java index 829721855..8a23cb5c0 100644 --- a/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java @@ -1,11 +1,13 @@ package com.jozufozu.flywheel.api.backend; +import com.jozufozu.flywheel.api.BackendImplemented; import com.jozufozu.flywheel.api.registry.IdRegistry; import com.jozufozu.flywheel.impl.IdRegistryImpl; import net.minecraft.network.chat.Component; import net.minecraft.world.level.LevelAccessor; +@BackendImplemented public interface Backend { static IdRegistry REGISTRY = IdRegistryImpl.create(); diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/BlockEntityVisualizer.java b/src/main/java/com/jozufozu/flywheel/api/visualization/BlockEntityVisualizer.java index 295f6b351..bfb354c8d 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visualization/BlockEntityVisualizer.java +++ b/src/main/java/com/jozufozu/flywheel/api/visualization/BlockEntityVisualizer.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.api.visualization; import com.jozufozu.flywheel.api.visual.BlockEntityVisual; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.world.level.block.entity.BlockEntity; /** @@ -19,9 +20,9 @@ public interface BlockEntityVisualizer { BlockEntityVisual createVisual(VisualizationContext ctx, T blockEntity); /** - * Checks if the given block entity should not be rendered normally. + * Checks if the given block entity should not be rendered with the vanilla {@link BlockEntityRenderer}. * @param blockEntity The block entity to check. - * @return {@code true} if the block entity should not be rendered normally, {@code false} if it should. + * @return {@code true} if the block entity should not be rendered with the vanilla {@link BlockEntityRenderer}, {@code false} if it should. */ - boolean shouldSkipRender(T blockEntity); + boolean skipVanillaRender(T blockEntity); } diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/EntityVisualizer.java b/src/main/java/com/jozufozu/flywheel/api/visualization/EntityVisualizer.java index a4b26d6e7..93826c5b7 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visualization/EntityVisualizer.java +++ b/src/main/java/com/jozufozu/flywheel/api/visualization/EntityVisualizer.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.api.visualization; import com.jozufozu.flywheel.api.visual.EntityVisual; +import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.world.entity.Entity; /** @@ -19,9 +20,9 @@ public interface EntityVisualizer { EntityVisual createVisual(VisualizationContext ctx, T entity); /** - * Checks if the given entity should not render normally. + * Checks if the given entity should not render with the vanilla {@link EntityRenderer}. * @param entity The entity to check. - * @return {@code true} if the entity should not render normally, {@code false} if it should. + * @return {@code true} if the entity should not render with the vanilla {@link EntityRenderer}, {@code false} if it should. */ - boolean shouldSkipRender(T entity); + boolean skipVanillaRender(T entity); } diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationHelper.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationHelper.java index b5b0c6da4..439d4dcd6 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationHelper.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationHelper.java @@ -60,7 +60,7 @@ public final class VisualizationHelper { if (visualizer == null) { return false; } - return visualizer.shouldSkipRender(blockEntity); + return visualizer.skipVanillaRender(blockEntity); } /** @@ -74,7 +74,7 @@ public final class VisualizationHelper { if (visualizer == null) { return false; } - return visualizer.shouldSkipRender(entity); + return visualizer.skipVanillaRender(entity); } public static boolean tryAddBlockEntity(T blockEntity) { @@ -91,6 +91,6 @@ public final class VisualizationHelper { manager.getBlockEntities().queueAdd(blockEntity); - return visualizer.shouldSkipRender(blockEntity); + return visualizer.skipVanillaRender(blockEntity); } } diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java b/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java index 2c1690fa9..702219e89 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/ColoredLitInstance.java @@ -4,37 +4,23 @@ import com.jozufozu.flywheel.api.instance.InstanceHandle; import com.jozufozu.flywheel.api.instance.InstanceType; import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.texture.OverlayTexture; public abstract class ColoredLitInstance extends AbstractInstance implements FlatLit { - public byte blockLight; - public byte skyLight; - public byte r = (byte) 0xFF; public byte g = (byte) 0xFF; public byte b = (byte) 0xFF; public byte a = (byte) 0xFF; + public byte blockLight; + public byte skyLight; + + public int overlay = OverlayTexture.NO_OVERLAY; + public ColoredLitInstance(InstanceType type, InstanceHandle handle) { super(type, handle); } - @Override - public ColoredLitInstance setBlockLight(int blockLight) { - this.blockLight = (byte) blockLight; - return this; - } - - @Override - public ColoredLitInstance setSkyLight(int skyLight) { - this.skyLight = (byte) skyLight; - return this; - } - - @Override - public int getPackedLight() { - return LightTexture.pack(blockLight, skyLight); - } - public ColoredLitInstance setColor(int color) { return setColor(color, false); } @@ -70,4 +56,26 @@ public abstract class ColoredLitInstance extends AbstractInstance implements Fla this.a = a; return this; } + + @Override + public ColoredLitInstance setBlockLight(int blockLight) { + this.blockLight = (byte) blockLight; + return this; + } + + @Override + public ColoredLitInstance setSkyLight(int skyLight) { + this.skyLight = (byte) skyLight; + return this; + } + + @Override + public int getPackedLight() { + return LightTexture.pack(blockLight, skyLight); + } + + public ColoredLitInstance setOverlay(int overlay) { + this.overlay = overlay; + return this; + } } diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java b/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java index c937de7fc..edf973519 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/InstanceTypes.java @@ -13,20 +13,22 @@ import com.jozufozu.flywheel.lib.math.MatrixMath; public final class InstanceTypes { public static final InstanceType TRANSFORMED = SimpleInstanceType.builder(TransformedInstance::new) .layout(LayoutBuilder.create() - .vector("light", IntegerRepr.SHORT, 2) .vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4) + .vector("light", IntegerRepr.SHORT, 2) + .vector("overlay", IntegerRepr.SHORT, 2) .matrix("pose", FloatRepr.FLOAT, 4) .matrix("normal", FloatRepr.FLOAT, 3) .build()) .writer((ptr, instance) -> { - MemoryUtil.memPutShort(ptr, instance.blockLight); - MemoryUtil.memPutShort(ptr + 2, instance.skyLight); - MemoryUtil.memPutByte(ptr + 4, instance.r); - MemoryUtil.memPutByte(ptr + 5, instance.g); - MemoryUtil.memPutByte(ptr + 6, instance.b); - MemoryUtil.memPutByte(ptr + 7, instance.a); - MatrixMath.writeUnsafe(instance.model, ptr + 8); - MatrixMath.writeUnsafe(instance.normal, ptr + 72); + MemoryUtil.memPutByte(ptr, instance.r); + MemoryUtil.memPutByte(ptr + 1, instance.g); + MemoryUtil.memPutByte(ptr + 2, instance.b); + MemoryUtil.memPutByte(ptr + 3, instance.a); + MemoryUtil.memPutShort(ptr + 4, instance.blockLight); + MemoryUtil.memPutShort(ptr + 6, instance.skyLight); + MemoryUtil.memPutInt(ptr + 8, instance.overlay); + MatrixMath.writeUnsafe(instance.model, ptr + 12); + MatrixMath.writeUnsafe(instance.normal, ptr + 76); }) .vertexShader(Flywheel.rl("instance/transformed.vert")) .cullShader(Flywheel.rl("instance/cull/transformed.glsl")) @@ -34,29 +36,31 @@ public final class InstanceTypes { public static final InstanceType ORIENTED = SimpleInstanceType.builder(OrientedInstance::new) .layout(LayoutBuilder.create() - .vector("light", IntegerRepr.SHORT, 2) .vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4) + .vector("light", IntegerRepr.SHORT, 2) + .vector("overlay", IntegerRepr.SHORT, 2) .vector("position", FloatRepr.FLOAT, 3) .vector("pivot", FloatRepr.FLOAT, 3) .vector("rotation", FloatRepr.FLOAT, 4) .build()) .writer((ptr, instance) -> { - MemoryUtil.memPutShort(ptr, instance.blockLight); - MemoryUtil.memPutShort(ptr + 2, instance.skyLight); - MemoryUtil.memPutByte(ptr + 4, instance.r); - MemoryUtil.memPutByte(ptr + 5, instance.g); - MemoryUtil.memPutByte(ptr + 6, instance.b); - MemoryUtil.memPutByte(ptr + 7, instance.a); - MemoryUtil.memPutFloat(ptr + 8, instance.posX); - MemoryUtil.memPutFloat(ptr + 12, instance.posY); - MemoryUtil.memPutFloat(ptr + 16, instance.posZ); - MemoryUtil.memPutFloat(ptr + 20, instance.pivotX); - MemoryUtil.memPutFloat(ptr + 24, instance.pivotY); - MemoryUtil.memPutFloat(ptr + 28, instance.pivotZ); - MemoryUtil.memPutFloat(ptr + 32, instance.rotation.x); - MemoryUtil.memPutFloat(ptr + 36, instance.rotation.y); - MemoryUtil.memPutFloat(ptr + 40, instance.rotation.z); - MemoryUtil.memPutFloat(ptr + 44, instance.rotation.w); + MemoryUtil.memPutByte(ptr, instance.r); + MemoryUtil.memPutByte(ptr + 1, instance.g); + MemoryUtil.memPutByte(ptr + 2, instance.b); + MemoryUtil.memPutByte(ptr + 3, instance.a); + MemoryUtil.memPutShort(ptr + 4, instance.blockLight); + MemoryUtil.memPutShort(ptr + 6, instance.skyLight); + MemoryUtil.memPutInt(ptr + 8, instance.overlay); + MemoryUtil.memPutFloat(ptr + 12, instance.posX); + MemoryUtil.memPutFloat(ptr + 16, instance.posY); + MemoryUtil.memPutFloat(ptr + 20, instance.posZ); + MemoryUtil.memPutFloat(ptr + 24, instance.pivotX); + MemoryUtil.memPutFloat(ptr + 28, instance.pivotY); + MemoryUtil.memPutFloat(ptr + 32, instance.pivotZ); + MemoryUtil.memPutFloat(ptr + 36, instance.rotation.x); + MemoryUtil.memPutFloat(ptr + 40, instance.rotation.y); + MemoryUtil.memPutFloat(ptr + 44, instance.rotation.z); + MemoryUtil.memPutFloat(ptr + 48, instance.rotation.w); }) .vertexShader(Flywheel.rl("instance/oriented.vert")) .cullShader(Flywheel.rl("instance/cull/oriented.glsl")) diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java b/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java index 82bb7be6f..905987884 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java @@ -11,61 +11,18 @@ import net.minecraft.core.Vec3i; import net.minecraft.world.phys.Vec3; public class OrientedInstance extends ColoredLitInstance implements Rotate { - public final Quaternionf rotation = new Quaternionf(); - public float pivotX = 0.5f; - public float pivotY = 0.5f; - public float pivotZ = 0.5f; public float posX; public float posY; public float posZ; + public float pivotX = 0.5f; + public float pivotY = 0.5f; + public float pivotZ = 0.5f; + public final Quaternionf rotation = new Quaternionf(); public OrientedInstance(InstanceType type, InstanceHandle handle) { super(type, handle); } - @Override - public OrientedInstance rotate(Quaternionf quaternion) { - rotation.mul(quaternion); - return this; - } - - public OrientedInstance setRotation(Quaternionf q) { - rotation.set(q); - return this; - } - - public OrientedInstance setRotation(float x, float y, float z, float w) { - rotation.set(x, y, z, w); - return this; - } - - public OrientedInstance resetRotation() { - rotation.identity(); - return this; - } - - public OrientedInstance setPivot(float x, float y, float z) { - pivotX = x; - pivotY = y; - pivotZ = z; - return this; - } - - public OrientedInstance setPivot(Vector3f pos) { - return setPivot(pos.x(), pos.y(), pos.z()); - } - - public OrientedInstance setPivot(Vec3 pos) { - return setPivot((float) pos.x(), (float) pos.y(), (float) pos.z()); - } - - public OrientedInstance nudgePosition(float x, float y, float z) { - posX += x; - posY += y; - posZ += z; - return this; - } - public OrientedInstance setPosition(float x, float y, float z) { posX = x; posY = y; @@ -81,7 +38,58 @@ public class OrientedInstance extends ColoredLitInstance implements Rotate * Only one instance of this class should exist per {@link PoseStack}. */ +@ApiStatus.Internal public class PoseTransformStack implements TransformStack { private final PoseStack stack; - @ApiStatus.Internal public PoseTransformStack(PoseStack stack) { this.stack = stack; } diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java index 644f53cf9..49f2e4d5e 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleBlockEntityVisualizer.java @@ -8,16 +8,17 @@ import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer; import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizerRegistry; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; public class SimpleBlockEntityVisualizer implements BlockEntityVisualizer { protected Factory visualFactory; - protected Predicate skipRender; + protected Predicate skipVanillaRender; - public SimpleBlockEntityVisualizer(Factory visualFactory, Predicate skipRender) { + public SimpleBlockEntityVisualizer(Factory visualFactory, Predicate skipVanillaRender) { this.visualFactory = visualFactory; - this.skipRender = skipRender; + this.skipVanillaRender = skipVanillaRender; } @Override @@ -26,8 +27,8 @@ public class SimpleBlockEntityVisualizer implements Block } @Override - public boolean shouldSkipRender(T blockEntity) { - return skipRender.test(blockEntity); + public boolean skipVanillaRender(T blockEntity) { + return skipVanillaRender.test(blockEntity); } /** @@ -37,8 +38,8 @@ public class SimpleBlockEntityVisualizer implements Block * @param The type of the block entity. * @return The configuration object. */ - public static BlockEntityConfig configure(BlockEntityType type) { - return new BlockEntityConfig<>(type); + public static Builder builder(BlockEntityType type) { + return new Builder<>(type); } @FunctionalInterface @@ -51,12 +52,12 @@ public class SimpleBlockEntityVisualizer implements Block * * @param The type of the block entity. */ - public static class BlockEntityConfig { + public static class Builder { protected BlockEntityType type; protected Factory visualFactory; - protected Predicate skipRender; + protected Predicate skipVanillaRender; - public BlockEntityConfig(BlockEntityType type) { + public Builder(BlockEntityType type) { this.type = type; } @@ -66,40 +67,44 @@ public class SimpleBlockEntityVisualizer implements Block * @param visualFactory The visual factory. * @return {@code this} */ - public BlockEntityConfig factory(Factory visualFactory) { + public Builder factory(Factory visualFactory) { this.visualFactory = visualFactory; return this; } /** - * Sets a predicate to determine whether to skip rendering a block entity. - * @param skipRender The predicate. + * Sets a predicate to determine whether to skip rendering with the vanilla {@link BlockEntityRenderer}. + * + * @param skipVanillaRender The predicate. * @return {@code this} */ - public BlockEntityConfig skipRender(Predicate skipRender) { - this.skipRender = skipRender; + public Builder skipVanillaRender(Predicate skipVanillaRender) { + this.skipVanillaRender = skipVanillaRender; return this; } /** - * Sets a predicate to always skip rendering for block entities of this type. + * Sets a predicate to never skip rendering with the vanilla {@link BlockEntityRenderer}. + * * @return {@code this} */ - public BlockEntityConfig alwaysSkipRender() { - this.skipRender = be -> true; + public Builder neverSkipVanillaRender() { + this.skipVanillaRender = blockEntity -> false; return this; } /** - * Constructs the block entity visualizer, and sets it for the block entity type. + * Constructs the block entity visualizer and sets it for the block entity type. + * * @return The block entity visualizer. */ public SimpleBlockEntityVisualizer apply() { Objects.requireNonNull(visualFactory, "Visual factory cannot be null!"); - if (skipRender == null) { - skipRender = be -> false; + if (skipVanillaRender == null) { + skipVanillaRender = blockEntity -> true; } - SimpleBlockEntityVisualizer visualizer = new SimpleBlockEntityVisualizer<>(visualFactory, skipRender); + + SimpleBlockEntityVisualizer visualizer = new SimpleBlockEntityVisualizer<>(visualFactory, skipVanillaRender); VisualizerRegistry.setVisualizer(type, visualizer); return visualizer; } diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java index 038e13abb..0cedc825d 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/SimpleEntityVisualizer.java @@ -8,16 +8,17 @@ import com.jozufozu.flywheel.api.visualization.EntityVisualizer; import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizerRegistry; +import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; public class SimpleEntityVisualizer implements EntityVisualizer { protected Factory visualFactory; - protected Predicate skipRender; + protected Predicate skipVanillaRender; - public SimpleEntityVisualizer(Factory visualFactory, Predicate skipRender) { + public SimpleEntityVisualizer(Factory visualFactory, Predicate skipVanillaRender) { this.visualFactory = visualFactory; - this.skipRender = skipRender; + this.skipVanillaRender = skipVanillaRender; } @Override @@ -26,8 +27,8 @@ public class SimpleEntityVisualizer implements EntityVisualize } @Override - public boolean shouldSkipRender(T entity) { - return skipRender.test(entity); + public boolean skipVanillaRender(T entity) { + return skipVanillaRender.test(entity); } /** @@ -37,8 +38,8 @@ public class SimpleEntityVisualizer implements EntityVisualize * @param The type of the entity. * @return The configuration object. */ - public static EntityConfig configure(EntityType type) { - return new EntityConfig<>(type); + public static Builder builder(EntityType type) { + return new Builder<>(type); } @FunctionalInterface @@ -51,12 +52,12 @@ public class SimpleEntityVisualizer implements EntityVisualize * * @param The type of the entity. */ - public static class EntityConfig { + public static class Builder { protected EntityType type; protected Factory visualFactory; - protected Predicate skipRender; + protected Predicate skipVanillaRender; - public EntityConfig(EntityType type) { + public Builder(EntityType type) { this.type = type; } @@ -66,40 +67,44 @@ public class SimpleEntityVisualizer implements EntityVisualize * @param visualFactory The visual factory. * @return {@code this} */ - public EntityConfig factory(Factory visualFactory) { + public Builder factory(Factory visualFactory) { this.visualFactory = visualFactory; return this; } /** - * Sets a predicate to determine whether to skip rendering an entity. - * @param skipRender The predicate. + * Sets a predicate to determine whether to skip rendering with the vanilla {@link EntityRenderer}. + * + * @param skipVanillaRender The predicate. * @return {@code this} */ - public EntityConfig skipRender(Predicate skipRender) { - this.skipRender = skipRender; + public Builder skipVanillaRender(Predicate skipVanillaRender) { + this.skipVanillaRender = skipVanillaRender; return this; } /** - * Sets a predicate to always skip rendering for entities of this type. + * Sets a predicate to always skip rendering with the vanilla {@link EntityRenderer}. + * * @return {@code this} */ - public EntityConfig alwaysSkipRender() { - this.skipRender = entity -> true; + public Builder neverSkipVanillaRender() { + this.skipVanillaRender = entity -> false; return this; } /** - * Constructs the entity visualizer, and sets it for the entity type. + * Constructs the entity visualizer and sets it for the entity type. + * * @return The entity visualizer. */ public SimpleEntityVisualizer apply() { Objects.requireNonNull(visualFactory, "Visual factory cannot be null!"); - if (skipRender == null) { - skipRender = entity -> false; + if (skipVanillaRender == null) { + skipVanillaRender = entity -> true; } - SimpleEntityVisualizer visualizer = new SimpleEntityVisualizer<>(visualFactory, skipRender); + + SimpleEntityVisualizer visualizer = new SimpleEntityVisualizer<>(visualFactory, skipVanillaRender); VisualizerRegistry.setVisualizer(type, visualizer); return visualizer; } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java index 00b66c83a..8fe40c5de 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java @@ -17,6 +17,7 @@ import com.jozufozu.flywheel.lib.visual.AbstractEntityVisual; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; +import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.util.Mth; import net.minecraft.world.entity.vehicle.AbstractMinecart; @@ -25,9 +26,15 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; public class MinecartVisual extends AbstractEntityVisual implements TickableVisual, DynamicVisual { - private static final ModelHolder BODY_MODEL = new ModelHolder(() -> { - return new SingleMeshModel(ModelPartConverter.convert(ModelLayers.MINECART), Materials.MINECART); - }); + public static final ModelHolder CHEST_BODY_MODEL = createBodyModelHolder(ModelLayers.CHEST_MINECART); + public static final ModelHolder COMMAND_BLOCK_BODY_MODEL = createBodyModelHolder(ModelLayers.COMMAND_BLOCK_MINECART); + public static final ModelHolder FURNACE_BODY_MODEL = createBodyModelHolder(ModelLayers.FURNACE_MINECART); + public static final ModelHolder HOPPER_BODY_MODEL = createBodyModelHolder(ModelLayers.HOPPER_MINECART); + public static final ModelHolder STANDARD_BODY_MODEL = createBodyModelHolder(ModelLayers.MINECART); + public static final ModelHolder SPAWNER_BODY_MODEL = createBodyModelHolder(ModelLayers.SPAWNER_MINECART); + public static final ModelHolder TNT_BODY_MODEL = createBodyModelHolder(ModelLayers.TNT_MINECART); + + private final ModelHolder bodyModel; private TransformedInstance body; private TransformedInstance contents; @@ -36,8 +43,15 @@ public class MinecartVisual extends AbstractEntityVi private final PoseStack stack = new PoseStack(); - public MinecartVisual(VisualizationContext ctx, T entity) { + public MinecartVisual(VisualizationContext ctx, T entity, ModelHolder bodyModel) { super(ctx, entity); + this.bodyModel = bodyModel; + } + + private static ModelHolder createBodyModelHolder(ModelLayerLocation layer) { + return new ModelHolder(() -> { + return new SingleMeshModel(ModelPartConverter.convert(layer), Materials.MINECART); + }); } @Override @@ -46,13 +60,13 @@ public class MinecartVisual extends AbstractEntityVi blockState = entity.getDisplayBlockState(); contents = createContentsInstance(); - updatePosition(partialTick); + updateInstances(partialTick); super.init(partialTick); } private TransformedInstance createBodyInstance() { - return instancerProvider.instancer(InstanceTypes.TRANSFORMED, BODY_MODEL.get(), RenderStage.AFTER_ENTITIES) + return instancerProvider.instancer(InstanceTypes.TRANSFORMED, bodyModel.get(), RenderStage.AFTER_ENTITIES) .createInstance(); } @@ -75,7 +89,7 @@ public class MinecartVisual extends AbstractEntityVi } @Override - public void tick(VisualTickContext c) { + public void tick(VisualTickContext context) { BlockState displayBlockState = entity.getDisplayBlockState(); if (displayBlockState != blockState) { @@ -98,10 +112,10 @@ public class MinecartVisual extends AbstractEntityVi return; } - updatePosition(context.partialTick()); + updateInstances(context.partialTick()); } - private void updatePosition(float partialTick) { + private void updateInstances(float partialTick) { stack.setIdentity(); double posX = Mth.lerp(partialTick, entity.xOld, entity.getX()); @@ -160,10 +174,9 @@ public class MinecartVisual extends AbstractEntityVi if (contents != null) { stack.pushPose(); stack.scale(0.75F, 0.75F, 0.75F); - stack.translate(-0.5D, (float) (displayOffset - 8) / 16, 0.5D); + stack.translate(-0.5F, (float) (displayOffset - 8) / 16, 0.5F); stack.mulPose(Axis.YP.rotationDegrees(90)); - contents.setTransform(stack) - .setChanged(); + updateContents(contents, stack, partialTick); stack.popPose(); } @@ -172,6 +185,11 @@ public class MinecartVisual extends AbstractEntityVi .setChanged(); } + protected void updateContents(TransformedInstance contents, PoseStack stack, float partialTick) { + contents.setTransform(stack) + .setChanged(); + } + public void updateLight() { relight(entity.blockPosition(), body, contents); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/TntMinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/TntMinecartVisual.java new file mode 100644 index 000000000..8ff42576f --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/vanilla/TntMinecartVisual.java @@ -0,0 +1,41 @@ +package com.jozufozu.flywheel.vanilla; + +import com.jozufozu.flywheel.api.visualization.VisualizationContext; +import com.jozufozu.flywheel.lib.instance.TransformedInstance; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.vehicle.MinecartTNT; + +public class TntMinecartVisual extends MinecartVisual { + private static final int WHITE_OVERLAY = OverlayTexture.pack(OverlayTexture.u(1.0F), 10); + + public TntMinecartVisual(VisualizationContext ctx, T entity) { + super(ctx, entity, TNT_BODY_MODEL); + } + + @Override + protected void updateContents(TransformedInstance contents, PoseStack stack, float partialTick) { + int fuseTime = entity.getFuse(); + if (fuseTime > -1 && (float) fuseTime - partialTick + 1.0F < 10.0F) { + float f = 1.0F - ((float) fuseTime - partialTick + 1.0F) / 10.0F; + f = Mth.clamp(f, 0.0F, 1.0F); + f *= f; + f *= f; + float scale = 1.0F + f * 0.3F; + stack.scale(scale, scale, scale); + } + + int overlay; + if (fuseTime > -1 && fuseTime / 5 % 2 == 0) { + overlay = WHITE_OVERLAY; + } else { + overlay = OverlayTexture.NO_OVERLAY; + } + + contents.setTransform(stack) + .setOverlay(overlay) + .setChanged(); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/VanillaVisuals.java b/src/main/java/com/jozufozu/flywheel/vanilla/VanillaVisuals.java index 087b767af..3e123d1dd 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/VanillaVisuals.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/VanillaVisuals.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.vanilla; -import static com.jozufozu.flywheel.lib.visual.SimpleBlockEntityVisualizer.configure; -import static com.jozufozu.flywheel.lib.visual.SimpleEntityVisualizer.configure; +import static com.jozufozu.flywheel.lib.visual.SimpleBlockEntityVisualizer.builder; +import static com.jozufozu.flywheel.lib.visual.SimpleEntityVisualizer.builder; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.block.entity.BlockEntityType; @@ -28,48 +28,51 @@ import net.minecraft.world.level.block.entity.BlockEntityType; */ public class VanillaVisuals { public static void init() { - configure(BlockEntityType.CHEST) - .alwaysSkipRender() + builder(BlockEntityType.CHEST) .factory(ChestVisual::new) .apply(); - configure(BlockEntityType.ENDER_CHEST) - .alwaysSkipRender() + builder(BlockEntityType.ENDER_CHEST) .factory(ChestVisual::new) .apply(); - configure(BlockEntityType.TRAPPED_CHEST) - .alwaysSkipRender() + builder(BlockEntityType.TRAPPED_CHEST) .factory(ChestVisual::new) .apply(); - configure(BlockEntityType.BELL) - .alwaysSkipRender() + builder(BlockEntityType.BELL) .factory(BellVisual::new) .apply(); - configure(BlockEntityType.SHULKER_BOX) - .alwaysSkipRender() + builder(BlockEntityType.SHULKER_BOX) .factory(ShulkerBoxVisual::new) .apply(); - configure(EntityType.MINECART) - .skipRender(MinecartVisual::shouldSkipRender) - .factory(MinecartVisual::new) + builder(EntityType.CHEST_MINECART) + .factory((ctx, entity) -> new MinecartVisual<>(ctx, entity, MinecartVisual.CHEST_BODY_MODEL)) + .skipVanillaRender(MinecartVisual::shouldSkipRender) .apply(); - configure(EntityType.COMMAND_BLOCK_MINECART) - .skipRender(MinecartVisual::shouldSkipRender) - .factory(MinecartVisual::new) + builder(EntityType.COMMAND_BLOCK_MINECART) + .factory((ctx, entity) -> new MinecartVisual<>(ctx, entity, MinecartVisual.COMMAND_BLOCK_BODY_MODEL)) + .skipVanillaRender(MinecartVisual::shouldSkipRender) .apply(); - configure(EntityType.FURNACE_MINECART) - .skipRender(MinecartVisual::shouldSkipRender) - .factory(MinecartVisual::new) + builder(EntityType.FURNACE_MINECART) + .factory((ctx, entity) -> new MinecartVisual<>(ctx, entity, MinecartVisual.FURNACE_BODY_MODEL)) + .skipVanillaRender(MinecartVisual::shouldSkipRender) .apply(); - configure(EntityType.HOPPER_MINECART) - .skipRender(MinecartVisual::shouldSkipRender) - .factory(MinecartVisual::new) + builder(EntityType.HOPPER_MINECART) + .factory((ctx, entity) -> new MinecartVisual<>(ctx, entity, MinecartVisual.HOPPER_BODY_MODEL)) + .skipVanillaRender(MinecartVisual::shouldSkipRender) .apply(); - configure(EntityType.TNT_MINECART) - .skipRender(MinecartVisual::shouldSkipRender) - .factory(MinecartVisual::new) + builder(EntityType.MINECART) + .factory((ctx, entity) -> new MinecartVisual<>(ctx, entity, MinecartVisual.STANDARD_BODY_MODEL)) + .skipVanillaRender(MinecartVisual::shouldSkipRender) + .apply(); + builder(EntityType.SPAWNER_MINECART) + .factory((ctx, entity) -> new MinecartVisual<>(ctx, entity, MinecartVisual.SPAWNER_BODY_MODEL)) + .skipVanillaRender(MinecartVisual::shouldSkipRender) + .apply(); + builder(EntityType.TNT_MINECART) + .factory(TntMinecartVisual::new) + .skipVanillaRender(MinecartVisual::shouldSkipRender) .apply(); } } diff --git a/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert b/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert index 9b3e39906..7428deafb 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert +++ b/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert @@ -4,5 +4,6 @@ void flw_instanceVertex(in FlwInstance i) { flw_vertexPos = vec4(rotateByQuaternion(flw_vertexPos.xyz - i.pivot, i.rotation) + i.pivot + i.position, 1.0); flw_vertexNormal = rotateByQuaternion(flw_vertexNormal, i.rotation); flw_vertexColor = i.color; + flw_vertexOverlay = i.overlay; flw_vertexLight = i.light / 15.0; } diff --git a/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert b/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert index 6e7d125d3..2051811d4 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert +++ b/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert @@ -2,5 +2,6 @@ void flw_instanceVertex(in FlwInstance i) { flw_vertexPos = i.pose * flw_vertexPos; flw_vertexNormal = i.normal * flw_vertexNormal; flw_vertexColor = i.color; + flw_vertexOverlay = i.overlay; flw_vertexLight = i.light / 15.0; }