diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 0cfe41aba..7f0ff40a7 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -9,11 +9,13 @@ import com.jozufozu.flywheel.config.BackendTypeArgument; import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.core.Contexts; +import com.jozufozu.flywheel.core.GameStateRegistry; import com.jozufozu.flywheel.core.Models; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.material.MaterialShaders; +import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider; import com.jozufozu.flywheel.core.structs.InstanceShaders; import com.jozufozu.flywheel.core.vertex.LayoutShaders; import com.jozufozu.flywheel.event.ReloadRenderersEvent; @@ -86,6 +88,8 @@ public class Flywheel { Contexts.init(); MaterialShaders.init(); + GameStateRegistry.register(NormalDebugStateProvider.INSTANCE); + VanillaInstances.init(); // https://github.com/Jozufozu/Flywheel/issues/69 diff --git a/src/main/java/com/jozufozu/flywheel/api/material/Material.java b/src/main/java/com/jozufozu/flywheel/api/material/Material.java index e1492b98b..397be99b9 100644 --- a/src/main/java/com/jozufozu/flywheel/api/material/Material.java +++ b/src/main/java/com/jozufozu/flywheel/api/material/Material.java @@ -1,17 +1,15 @@ package com.jozufozu.flywheel.api.material; -import java.util.function.Supplier; - import com.jozufozu.flywheel.core.source.FileResolution; import net.minecraft.client.renderer.RenderType; public class Material { protected final RenderType renderType; - protected final Supplier vertexShader; - protected final Supplier fragmentShader; + protected final FileResolution vertexShader; + protected final FileResolution fragmentShader; - public Material(RenderType renderType, Supplier vertexShader, Supplier fragmentShader) { + public Material(RenderType renderType, FileResolution vertexShader, FileResolution fragmentShader) { this.renderType = renderType; this.vertexShader = vertexShader; this.fragmentShader = fragmentShader; @@ -22,10 +20,10 @@ public class Material { } public FileResolution getVertexShader() { - return vertexShader.get(); + return vertexShader; } public FileResolution getFragmentShader() { - return fragmentShader.get(); + return fragmentShader; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/GLSLVersion.java b/src/main/java/com/jozufozu/flywheel/backend/gl/GLSLVersion.java index 11a81427a..eb128ad69 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/GLSLVersion.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/GLSLVersion.java @@ -11,6 +11,9 @@ public enum GLSLVersion { V410(410), V420(420), V430(430), + V440(440), + V450(450), + V460(460), ; public final int version; diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java index 12cb002be..feadbdc6f 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlShader.java @@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.gl.shader; import java.io.File; import java.io.FileWriter; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import org.lwjgl.opengl.GL20; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java index 3a2ebdbae..75d3573ec 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java @@ -214,7 +214,6 @@ public class InstancingEngine

implements Engine { int dZ = cZ - originCoordinate.getZ(); if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) { - shiftListeners(cX, cY, cZ); } } diff --git a/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java b/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java index bf70b366d..e64837738 100644 --- a/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java +++ b/src/main/java/com/jozufozu/flywheel/core/BasicModelSupplier.java @@ -15,7 +15,7 @@ import com.jozufozu.flywheel.util.NonNullSupplier; import net.minecraft.client.renderer.RenderType; public class BasicModelSupplier implements ModelSupplier { - private static final Material DEFAULT_MATERIAL = new Material(RenderType.solid(), () -> MaterialShaders.DEFAULT_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT); + private static final Material DEFAULT_MATERIAL = new Material(RenderType.solid(), MaterialShaders.DEFAULT_VERTEX, MaterialShaders.DEFAULT_FRAGMENT); private Material material; private final Lazy supplier; diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java index 87092d959..c87d58e9a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java +++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java @@ -1,41 +1,48 @@ package com.jozufozu.flywheel.core; +import java.util.function.BiConsumer; + import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.gl.GLSLVersion; import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.crumbling.CrumblingProgram; -import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.SourceChecks; +import com.jozufozu.flywheel.core.source.SourceFile; +import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; public class Contexts { + public static final BiConsumer VERTEX_CHECK = SourceChecks.checkFunctionArity("flw_contextVertex", 0); + public static final BiConsumer FRAGMENT_CHECK = SourceChecks.checkFunctionArity("flw_contextFragment", 0); - public static ProgramCompiler WORLD; - public static ProgramCompiler CRUMBLING; + public static final ProgramCompiler WORLD; + public static final ProgramCompiler CRUMBLING; - public static void init() { - GameStateRegistry.register(NormalDebugStateProvider.INSTANCE); - - var checkFrag = SourceChecks.checkFunctionArity("flw_contextFragment", 0); - var checkVert = SourceChecks.checkFunctionArity("flw_contextVertex", 0); - - var worldVertex = FileResolution.get(ResourceUtil.subPath(Names.WORLD, ".vert")) - .validateWith(checkVert); - var worldFragment = FileResolution.get(ResourceUtil.subPath(Names.WORLD, ".frag")) - .validateWith(checkFrag); - var crumblingVertex = FileResolution.get(ResourceUtil.subPath(Names.CRUMBLING, ".vert")) - .validateWith(checkVert); - var crumblingFragment = FileResolution.get(ResourceUtil.subPath(Names.CRUMBLING, ".frag")) - .validateWith(checkFrag); + static { + var worldVertex = createVertex(ResourceUtil.subPath(Names.WORLD, ".vert")); + var worldFragment = createFragment(ResourceUtil.subPath(Names.WORLD, ".frag")); + var crumblingVertex = createVertex(ResourceUtil.subPath(Names.CRUMBLING, ".vert")); + var crumblingFragment = createFragment(ResourceUtil.subPath(Names.CRUMBLING, ".frag")); WORLD = ProgramCompiler.create(WorldProgram::new, worldVertex, worldFragment, GLSLVersion.V330); CRUMBLING = ProgramCompiler.create(CrumblingProgram::new, crumblingVertex, crumblingFragment, GLSLVersion.V330); } + public static FileResolution createVertex(ResourceLocation location) { + return FileResolution.get(location).validateWith(VERTEX_CHECK); + } + + public static FileResolution createFragment(ResourceLocation location) { + return FileResolution.get(location).validateWith(FRAGMENT_CHECK); + } + + public static void init() { + } + public static class Names { public static final ResourceLocation WORLD = Flywheel.rl("context/world"); public static final ResourceLocation CRUMBLING = Flywheel.rl("context/crumbling"); diff --git a/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java b/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java index bd88b465c..0c925373f 100644 --- a/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.core.compile; -import java.util.Objects; - import com.google.common.collect.ImmutableList; import com.jozufozu.flywheel.backend.gl.GLSLVersion; import com.jozufozu.flywheel.backend.gl.shader.GlShader; diff --git a/src/main/java/com/jozufozu/flywheel/core/compile/ProgramAssembler.java b/src/main/java/com/jozufozu/flywheel/core/compile/ProgramAssembler.java index 3210db125..c64716e45 100644 --- a/src/main/java/com/jozufozu/flywheel/core/compile/ProgramAssembler.java +++ b/src/main/java/com/jozufozu/flywheel/core/compile/ProgramAssembler.java @@ -8,13 +8,10 @@ import static org.lwjgl.opengl.GL20.glGetProgramInfoLog; import static org.lwjgl.opengl.GL20.glGetProgrami; import static org.lwjgl.opengl.GL20.glLinkProgram; -import java.util.List; - import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlShader; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.resources.ResourceLocation; public class ProgramAssembler { diff --git a/src/main/java/com/jozufozu/flywheel/core/material/MaterialShaders.java b/src/main/java/com/jozufozu/flywheel/core/material/MaterialShaders.java index 6a0e366ee..78ca6a488 100644 --- a/src/main/java/com/jozufozu/flywheel/core/material/MaterialShaders.java +++ b/src/main/java/com/jozufozu/flywheel/core/material/MaterialShaders.java @@ -1,27 +1,33 @@ package com.jozufozu.flywheel.core.material; +import java.util.function.BiConsumer; + import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.SourceChecks; +import com.jozufozu.flywheel.core.source.SourceFile; +import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; public class MaterialShaders { - public static FileResolution DEFAULT_VERTEX; - public static FileResolution DEFAULT_FRAGMENT; - public static FileResolution SHADED_VERTEX; + public static final BiConsumer VERTEX_CHECK = SourceChecks.checkFunctionArity("flw_materialVertex", 0); + public static final BiConsumer FRAGMENT_CHECK = SourceChecks.checkFunctionArity("flw_materialFragment", 0); + + public static final FileResolution DEFAULT_VERTEX = createVertex(ResourceUtil.subPath(Names.DEFAULT, ".vert")); + public static final FileResolution DEFAULT_FRAGMENT = createFragment(ResourceUtil.subPath(Names.DEFAULT, ".frag")); + public static final FileResolution SHADED_VERTEX = createVertex(ResourceUtil.subPath(Names.SHADED, ".vert")); + + public static FileResolution createVertex(ResourceLocation location) { + return FileResolution.get(location).validateWith(VERTEX_CHECK); + } + + public static FileResolution createFragment(ResourceLocation location) { + return FileResolution.get(location).validateWith(FRAGMENT_CHECK); + } public static void init() { - var checkVert = SourceChecks.checkFunctionArity("flw_materialVertex", 0); - var checkFrag = SourceChecks.checkFunctionArity("flw_materialFragment", 0); - - DEFAULT_VERTEX = FileResolution.get(ResourceUtil.subPath(Names.DEFAULT, ".vert")) - .validateWith(checkVert); - DEFAULT_FRAGMENT = FileResolution.get(ResourceUtil.subPath(Names.DEFAULT, ".frag")) - .validateWith(checkFrag); - SHADED_VERTEX = FileResolution.get(ResourceUtil.subPath(Names.SHADED, ".vert")) - .validateWith(checkVert); } public static class Names { diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java index 819ede8e2..8013db065 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java @@ -271,12 +271,13 @@ public class ModelTransformer { } normal.mul(-1.0F); + return this; } float f = 1.0F / pX; float f1 = 1.0F / pY; float f2 = 1.0F / pZ; - float f3 = Mth.fastInvCubeRoot(f * f1 * f2); + float f3 = Mth.fastInvCubeRoot(Math.abs(f * f1 * f2)); normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2)); return this; } diff --git a/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java b/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java index c76a08e88..56aa16e06 100644 --- a/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java +++ b/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java @@ -15,7 +15,6 @@ import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.parse.Import; import com.jozufozu.flywheel.core.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderStruct; -import com.jozufozu.flywheel.core.source.parse.Variable; import com.jozufozu.flywheel.core.source.span.ErrorSpan; import com.jozufozu.flywheel.core.source.span.Span; import com.jozufozu.flywheel.core.source.span.StringSpan; diff --git a/src/main/java/com/jozufozu/flywheel/core/structs/InstanceShaders.java b/src/main/java/com/jozufozu/flywheel/core/structs/InstanceShaders.java index fdc5e4768..84e45497a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/structs/InstanceShaders.java +++ b/src/main/java/com/jozufozu/flywheel/core/structs/InstanceShaders.java @@ -1,23 +1,27 @@ package com.jozufozu.flywheel.core.structs; +import java.util.function.BiConsumer; + import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.SourceChecks; +import com.jozufozu.flywheel.core.source.SourceFile; +import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; public class InstanceShaders { - public static FileResolution MODEL; - public static FileResolution ORIENTED; + public static final BiConsumer CHECK = SourceChecks.checkFunctionParameterTypeExists("flw_instanceVertex", 1, 0); + + public static final FileResolution MODEL = create(ResourceUtil.subPath(Names.MODEL, ".vert")); + public static final FileResolution ORIENTED = create(ResourceUtil.subPath(Names.ORIENTED, ".vert")); + + public static FileResolution create(ResourceLocation location) { + return FileResolution.get(location).validateWith(CHECK); + } public static void init() { - var check = SourceChecks.checkFunctionParameterTypeExists("flw_instanceVertex", 1, 0); - - MODEL = FileResolution.get(ResourceUtil.subPath(Names.MODEL, ".vert")) - .validateWith(check); - ORIENTED = FileResolution.get(ResourceUtil.subPath(Names.ORIENTED, ".vert")) - .validateWith(check); } public static class Names { diff --git a/src/main/java/com/jozufozu/flywheel/core/structs/model/ModelData.java b/src/main/java/com/jozufozu/flywheel/core/structs/model/ModelData.java index 24b486f08..fa364c901 100644 --- a/src/main/java/com/jozufozu/flywheel/core/structs/model/ModelData.java +++ b/src/main/java/com/jozufozu/flywheel/core/structs/model/ModelData.java @@ -10,6 +10,9 @@ import com.mojang.math.Quaternion; import net.minecraft.util.Mth; public class ModelData extends BasicData implements Transform { + private static final Matrix4f EMPTY_MATRIX_4f = new Matrix4f(); + private static final Matrix3f EMPTY_MATRIX_3f = new Matrix3f(); + public final Matrix4f model = new Matrix4f(); public final Matrix3f normal = new Matrix3f(); @@ -31,8 +34,8 @@ public class ModelData extends BasicData implements Transform { public ModelData setEmptyTransform() { markDirty(); - this.model.load(new Matrix4f()); - this.normal.load(new Matrix3f()); + this.model.load(EMPTY_MATRIX_4f); + this.normal.load(EMPTY_MATRIX_3f); return this; } @@ -64,12 +67,13 @@ public class ModelData extends BasicData implements Transform { } normal.mul(-1.0F); + return this; } float f = 1.0F / pX; float f1 = 1.0F / pY; float f2 = 1.0F / pZ; - float f3 = Mth.fastInvCubeRoot(f * f1 * f2); + float f3 = Mth.fastInvCubeRoot(Math.abs(f * f1 * f2)); normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2)); return this; } diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/LayoutShaders.java b/src/main/java/com/jozufozu/flywheel/core/vertex/LayoutShaders.java index ff3b8de25..95843694c 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/LayoutShaders.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/LayoutShaders.java @@ -1,24 +1,27 @@ package com.jozufozu.flywheel.core.vertex; +import java.util.function.BiConsumer; + import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.SourceChecks; +import com.jozufozu.flywheel.core.source.SourceFile; +import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; public class LayoutShaders { - public static FileResolution BLOCK; - public static FileResolution POS_TEX_NORMAL; + public static final BiConsumer CHECK = SourceChecks.checkFunctionArity("flw_layoutVertex", 0); + + public static final FileResolution BLOCK = create(ResourceUtil.subPath(Names.BLOCK, ".vert")); + public static final FileResolution POS_TEX_NORMAL = create(ResourceUtil.subPath(Names.POS_TEX_NORMAL, ".vert")); + + public static FileResolution create(ResourceLocation location) { + return FileResolution.get(location).validateWith(CHECK); + } public static void init() { - var check = SourceChecks.checkFunctionArity("flw_layoutVertex", 0); - - BLOCK = FileResolution.get(ResourceUtil.subPath(Names.BLOCK, ".vert")) - .validateWith(check); - - POS_TEX_NORMAL = FileResolution.get(ResourceUtil.subPath(Names.POS_TEX_NORMAL, ".vert")) - .validateWith(check); } public static class Names { diff --git a/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java b/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java index c2c5d806d..52e31ff9b 100644 --- a/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java +++ b/src/main/java/com/jozufozu/flywheel/event/ForgeEvents.java @@ -6,7 +6,6 @@ import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.util.WorldAttached; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.LocalPlayer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.TickEvent; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java index 125408f43..af93f13cc 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -22,7 +22,7 @@ import net.minecraft.world.level.block.entity.BellBlockEntity; public class BellInstance extends BlockEntityInstance implements DynamicInstance { - private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT)); + private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)); private final OrientedData bell; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index bac103498..22c4c9a9f 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -34,8 +34,8 @@ import net.minecraft.world.level.block.state.properties.ChestType; public class ChestInstance extends BlockEntityInstance implements DynamicInstance { - private static final BiFunction LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); - private static final BiFunction BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); + private static final BiFunction LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT))); + private static final BiFunction BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT))); private final OrientedData body; private final ModelData lid; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index 90f354cba..13d47f072 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -31,36 +31,44 @@ import net.minecraft.world.phys.Vec3; public class MinecartInstance extends EntityInstance implements DynamicInstance, TickableInstance { private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); - private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new Material(RenderType.entitySolid(MINECART_LOCATION), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT)); + private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new Material(RenderType.entitySolid(MINECART_LOCATION), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)); private final PoseStack stack = new PoseStack(); private final ModelData body; private ModelData contents; - private BlockState blockstate; + private BlockState blockState; + private boolean active; public MinecartInstance(InstancerManager instancerManager, T entity) { super(instancerManager, entity); - blockstate = entity.getDisplayBlockState(); - contents = getContents(); body = getBody(); + blockState = entity.getDisplayBlockState(); + contents = getContents(); } @Override public void tick() { BlockState displayBlockState = entity.getDisplayBlockState(); - if (displayBlockState != blockstate) { - blockstate = displayBlockState; + if (displayBlockState != blockState) { + blockState = displayBlockState; contents.delete(); contents = getContents(); - updateLight(); + if (contents != null) { + relight(getWorldPosition(), contents); + } } } @Override public void beginFrame() { + // TODO: add proper way to temporarily disable rendering a specific instance + if (!active) { + return; + } + TransformStack tstack = TransformStack.cast(stack); stack.setIdentity(); float pt = AnimationTickHolder.getPartialTicks(); @@ -146,11 +154,20 @@ public class MinecartInstance extends EntityInstance } private ModelData getContents() { - if (blockstate.getRenderShape() == RenderShape.INVISIBLE) + RenderShape shape = blockState.getRenderShape(); + + if (shape == RenderShape.ENTITYBLOCK_ANIMATED) { + body.setEmptyTransform(); + active = false; + return null; + } + active = true; + + if (shape == RenderShape.INVISIBLE) return null; return instancerManager.factory(StructTypes.MODEL) - .model(Models.block(blockstate)) + .model(Models.block(blockState)) .createInstance(); } @@ -171,4 +188,8 @@ public class MinecartInstance extends EntityInstance .cuboid().invertYZ().start(-8, y, -8).size(16, 8, 2).endCuboid() .build(); } + + public static boolean shouldSkipRender(AbstractMinecart minecart) { + return minecart.getDisplayBlockState().getRenderShape() != RenderShape.ENTITYBLOCK_ANIMATED; + } } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index b2857164d..665525183 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -28,8 +28,8 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; public class ShulkerBoxInstance extends BlockEntityInstance implements DynamicInstance { - private static final Function BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); - private static final Function LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); + private static final Function BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT))); + private static final Function LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT))); private final TextureAtlasSprite texture; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java b/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java index 69da8f2e4..a3d5d3b17 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java @@ -52,15 +52,23 @@ public class VanillaInstances { .apply(); configure(EntityType.MINECART) - .alwaysSkipRender() + .skipRender(MinecartInstance::shouldSkipRender) .factory(MinecartInstance::new) .apply(); - configure(EntityType.HOPPER_MINECART) - .alwaysSkipRender() + configure(EntityType.COMMAND_BLOCK_MINECART) + .skipRender(MinecartInstance::shouldSkipRender) .factory(MinecartInstance::new) .apply(); configure(EntityType.FURNACE_MINECART) - .alwaysSkipRender() + .skipRender(MinecartInstance::shouldSkipRender) + .factory(MinecartInstance::new) + .apply(); + configure(EntityType.HOPPER_MINECART) + .skipRender(MinecartInstance::shouldSkipRender) + .factory(MinecartInstance::new) + .apply(); + configure(EntityType.TNT_MINECART) + .skipRender(MinecartInstance::shouldSkipRender) .factory(MinecartInstance::new) .apply(); }