diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index dba7f7a29..a9a6b9d30 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -59,6 +59,7 @@ body: label: Mod Version description: The version of the mod you were using when the bug occured options: + - "0.6.1" - "0.6.0" - "0.5.1" - "0.5.0a" diff --git a/build.gradle b/build.gradle index 218cef6cd..422abd840 100644 --- a/build.gradle +++ b/build.gradle @@ -6,10 +6,10 @@ plugins { boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false'); -ext.buildnumber = 0 -project.buildnumber = System.getenv('BUILD_NUMBER') != null ? System.getenv('BUILD_NUMBER') : 'custom' +ext.buildNumber = System.getenv('BUILD_NUMBER') +if (buildNumber == null) buildNumber = 'custom' -version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildnumber}" : '') +version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildNumber}" : '') group = 'com.jozufozu.flywheel' archivesBaseName = 'flywheel-fabric' @@ -55,7 +55,7 @@ dependencies { // Fabric API modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" - modCompileOnly 'curse.maven:starlight-521783:3554912' + modCompileOnly 'curse.maven:starlight-521783:3599857' modCompileOnly 'maven.modrinth:iris:1.18.x-v1.1.4' modCompileOnly 'maven.modrinth:sodium:mc1.18.1-0.4.0-alpha6' diff --git a/src/main/java/com/jozufozu/flywheel/api/Material.java b/src/main/java/com/jozufozu/flywheel/api/Material.java index 252c9fb33..f6a963cf7 100644 --- a/src/main/java/com/jozufozu/flywheel/api/Material.java +++ b/src/main/java/com/jozufozu/flywheel/api/Material.java @@ -10,6 +10,7 @@ import com.jozufozu.flywheel.util.Pair; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.core.Direction; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; public interface Material { @@ -26,6 +27,10 @@ public interface Material { return model(partial, () -> new BlockModel(partial.get(), referenceState)); } + default Instancer getModel(PartialModel partial) { + return model(partial, () -> new BlockModel(partial.get(), Blocks.AIR.defaultBlockState())); + } + default Instancer getModel(PartialModel partial, BlockState referenceState, Direction dir) { return getModel(partial, referenceState, dir, ModelUtil.rotateToFace(dir)); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 7dabcd789..c68abc6fb 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -32,7 +32,7 @@ public class Backend { * (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use. */ public static String getBackendDescriptor() { - return engine == null ? "" : engine.getProperName(); + return engine == null ? "Uninitialized" : engine.getProperName(); } @Nullable @@ -77,7 +77,7 @@ public class Backend { FlwEngine preferredChoice = FlwConfig.get() .getEngine(); - boolean usingShaders = IrisShaderHandler.areShadersEnabled(); + boolean usingShaders = IrisShaderHandler.isShaderPackInUse(); boolean canUseEngine = switch (preferredChoice) { case OFF -> true; case BATCHING -> !usingShaders; diff --git a/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java b/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java index 74f1d7835..2ac8a70a9 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java +++ b/src/main/java/com/jozufozu/flywheel/backend/IrisShaderHandler.java @@ -19,10 +19,6 @@ public class IrisShaderHandler { private IrisShaderHandler() { } - public static boolean areShadersEnabled() { - return HANDLER.areShadersEnabled(); - } - public static boolean isShaderPackInUse() { return HANDLER.isShaderPackInUse(); } @@ -32,10 +28,6 @@ public class IrisShaderHandler { } private interface InternalHandler { - default boolean areShadersEnabled() { - return false; - }; - default boolean isShaderPackInUse() { return false; }; @@ -46,11 +38,6 @@ public class IrisShaderHandler { } private static class InternalHandlerImpl implements InternalHandler { - @Override - public boolean areShadersEnabled() { - return IrisApi.getInstance().getConfig().areShadersEnabled(); - }; - @Override public boolean isShaderPackInUse() { return IrisApi.getInstance().isShaderPackInUse(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java index 02ec9ceac..23d248b8a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceWorld.java @@ -12,6 +12,7 @@ import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.RenderLayerEvent; +import com.jozufozu.flywheel.util.ClientLevelExtension; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -130,7 +131,8 @@ public class InstanceWorld { public void loadEntities(ClientLevel world) { // Block entities are loaded while chunks are baked. // Entities are loaded with the world, so when chunks are reloaded they need to be re-added. - world.entitiesForRendering() + ClientLevelExtension.cast(world) + .flywheel$getAllLoadedEntities() .forEach(entityInstanceManager::add); } diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java index 3829a1a84..03fc53174 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/FlatLit.java @@ -2,6 +2,10 @@ package com.jozufozu.flywheel.core.materials; import com.jozufozu.flywheel.api.InstanceData; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.LightLayer; + /** * An interface that implementors of {@link InstanceData} should also implement * if they wish to make use of Flywheel's provided light update methods. @@ -25,5 +29,10 @@ public interface FlatLit> { */ D setSkyLight(int skyLight); + default D updateLight(BlockAndTintGetter level, BlockPos pos) { + return setBlockLight(level.getBrightness(LightLayer.BLOCK, pos)) + .setSkyLight(level.getBrightness(LightLayer.SKY, pos)); + } + int getPackedLight(); } 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 203ad0b79..10eafd1c4 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java @@ -1,7 +1,7 @@ package com.jozufozu.flywheel.core.model; import com.jozufozu.flywheel.api.vertex.VertexList; -import com.jozufozu.flywheel.util.RenderMath; +import com.jozufozu.flywheel.util.DiffuseLightCalculator; import com.jozufozu.flywheel.util.transform.Transform; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -47,7 +47,9 @@ public class ModelTransformer { normalMat = params.normal.copy(); } - int vertexCount = reader.getVertexCount(); + final DiffuseLightCalculator diffuseCalculator = DiffuseLightCalculator.forCurrentLevel(); + + final int vertexCount = reader.getVertexCount(); for (int i = 0; i < vertexCount; i++) { float x = reader.getX(i); float y = reader.getY(i); @@ -67,23 +69,26 @@ public class ModelTransformer { float ny = normal.y(); float nz = normal.z(); + byte r, g, b, a; if (params.useParamColor) { - if (context.outputColorDiffuse) { - float instanceDiffuse = RenderMath.diffuseLight(nx, ny, nz); - int colorR = transformColor(params.r, instanceDiffuse); - int colorG = transformColor(params.g, instanceDiffuse); - int colorB = transformColor(params.b, instanceDiffuse); - builder.color(colorR, colorG, colorB, params.a); - } else { - builder.color(params.r, params.g, params.b, params.a); - } + r = (byte) params.r; + g = (byte) params.g; + b = (byte) params.b; + a = (byte) params.a; } else { - if (context.outputColorDiffuse) { - int d = RenderMath.unb(RenderMath.diffuseLight(nx, ny, nz)); - builder.color(d, d, d, 0xFF); - } else { - builder.color(reader.getR(i), reader.getG(i), reader.getB(i), reader.getA(i)); - } + r = reader.getR(i); + g = reader.getG(i); + b = reader.getB(i); + a = reader.getA(i); + } + if (context.outputColorDiffuse) { + float instanceDiffuse = diffuseCalculator.getDiffuse(nx, ny, nz); + int colorR = transformColor(r, instanceDiffuse); + int colorG = transformColor(g, instanceDiffuse); + int colorB = transformColor(b, instanceDiffuse); + builder.color(colorR, colorG, colorB, a); + } else { + builder.color(r, g, b, a); } //builder.color(Math.max(0, (int) (nx * 255)), Math.max(0, (int) (ny * 255)), Math.max(0, (int) (nz * 255)), 0xFF); @@ -117,6 +122,10 @@ public class ModelTransformer { return "ModelTransformer[" + model + ']'; } + public static int transformColor(byte component, float scale) { + return Mth.clamp((int) (Byte.toUnsignedInt(component) * scale), 0, 255); + } + public static int transformColor(int component, float scale) { return Mth.clamp((int) (component * scale), 0, 255); } @@ -136,7 +145,6 @@ public class ModelTransformer { * Do we need to bake diffuse lighting into the output colors? */ public boolean outputColorDiffuse = true; - } public static class Params implements Transform { diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java index a779ba944..9e711d61a 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java @@ -1,6 +1,5 @@ package com.jozufozu.flywheel.core.model; -import java.util.Arrays; import java.util.Collection; import java.util.Random; import java.util.function.Supplier; @@ -10,7 +9,6 @@ import com.jozufozu.flywheel.fabric.model.CullingBakedModel; import com.jozufozu.flywheel.fabric.model.DefaultLayerFilteringBakedModel; import com.jozufozu.flywheel.fabric.model.FabricModelUtil; import com.jozufozu.flywheel.fabric.model.LayerFilteringBakedModel; -import com.jozufozu.flywheel.util.Lazy; import com.jozufozu.flywheel.util.transform.TransformStack; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.DefaultVertexFormat; @@ -20,7 +18,7 @@ import com.mojang.blaze3d.vertex.VertexFormat; import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.block.BlockModelShaper; +import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.renderer.block.ModelBlockRenderer; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.BakedModel; @@ -32,17 +30,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; public class ModelUtil { - private static final Lazy MODEL_RENDERER = Lazy.of(() -> new ModelBlockRenderer(Minecraft.getInstance().getBlockColors())); - - // DOWN, UP, NORTH, SOUTH, WEST, EAST, null - private static final Direction[] CULL_FACES; - - static { - Direction[] directions = Direction.values(); - - CULL_FACES = Arrays.copyOf(directions, directions.length + 1); - } - public static BufferBuilder getBufferBuilder(BakedModel model, BlockState referenceState, PoseStack ms) { ModelBlockRenderer blockRenderer = Minecraft.getInstance().getBlockRenderer().getModelRenderer(); BufferBuilder builder = new BufferBuilder(512); @@ -55,8 +42,8 @@ public class ModelUtil { } public static BufferBuilder getBufferBuilderFromTemplate(BlockAndTintGetter renderWorld, RenderType layer, Collection blocks) { - ModelBlockRenderer modelRenderer = MODEL_RENDERER.get(); - BlockModelShaper blockModels = Minecraft.getInstance().getModelManager().getBlockModelShaper(); + BlockRenderDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer(); + ModelBlockRenderer modelRenderer = dispatcher.getModelRenderer(); PoseStack ms = new PoseStack(); Random random = new Random(); @@ -70,7 +57,7 @@ public class ModelUtil { if (state.getRenderShape() != RenderShape.MODEL) continue; - BakedModel model = blockModels.getBlockModel(state); + BakedModel model = dispatcher.getBlockModel(state); if (((FabricBakedModel) model).isVanillaAdapter()) { if (!FabricModelUtil.doesLayerMatch(state, layer)) { continue; diff --git a/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java deleted file mode 100644 index ed1a41e6e..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/CancelEntityRenderMixin.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.jozufozu.flywheel.mixin; - -import java.util.ArrayList; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Group; -import org.spongepowered.asm.mixin.injection.Redirect; - -import com.google.common.collect.Lists; -import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; - -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.world.entity.Entity; - -@Mixin(LevelRenderer.class) -public class CancelEntityRenderMixin { - - // TODO: Don't use redirect - @Group(name = "entityFilter", min = 1, max = 1) - @Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;entitiesForRendering()Ljava/lang/Iterable;")) - private Iterable filterEntities(ClientLevel world) { - Iterable entities = world.entitiesForRendering(); - if (Backend.isOn()) { - ArrayList filtered = Lists.newArrayList(entities); - - filtered.removeIf(InstancedRenderRegistry::shouldSkipRender); - - return filtered; - } - return entities; - } - -// @Group(name = "entityFilter") -// @Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ClassInstanceMultiMap;iterator()Ljava/util/Iterator;")) -// private Iterator filterEntitiesOF(ClassInstanceMultiMap classInheritanceMultiMap) { -// if (Backend.getInstance() -// .canUseInstancing()) { -// -// ArrayList filtered = Lists.newArrayList(classInheritanceMultiMap); -// -// InstancedRenderRegistry r = InstancedRenderRegistry.getInstance(); -// filtered.removeIf(r::shouldSkipRender); -// -// return filtered.iterator(); -// } -// return classInheritanceMultiMap.iterator(); -// } -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ClientLevelMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/ClientLevelMixin.java new file mode 100644 index 000000000..ce1a9c161 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/ClientLevelMixin.java @@ -0,0 +1,42 @@ +package com.jozufozu.flywheel.mixin; + +import java.util.ArrayList; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.google.common.collect.Lists; +import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; +import com.jozufozu.flywheel.util.ClientLevelExtension; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.entity.LevelEntityGetter; + +@Mixin(ClientLevel.class) +public abstract class ClientLevelMixin implements ClientLevelExtension { + + @Shadow + protected abstract LevelEntityGetter getEntities(); + + @Override + public Iterable flywheel$getAllLoadedEntities() { + return getEntities().getAll(); + } + + @Inject(method = "entitiesForRendering", at = @At("RETURN"), cancellable = true) + private void filterEntities(CallbackInfoReturnable> cir) { + if (Backend.isOn()) { + Iterable entities = cir.getReturnValue(); + ArrayList filtered = Lists.newArrayList(entities); + + filtered.removeIf(InstancedRenderRegistry::shouldSkipRender); + + cir.setReturnValue(filtered); + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/util/ClientLevelExtension.java b/src/main/java/com/jozufozu/flywheel/util/ClientLevelExtension.java new file mode 100644 index 000000000..c4bb29bba --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/util/ClientLevelExtension.java @@ -0,0 +1,22 @@ +package com.jozufozu.flywheel.util; + +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.world.entity.Entity; + +public interface ClientLevelExtension { + + /** + * Get an iterator over all entities in this level. + * + *

+ * Normally, this would be accomplished by {@link ClientLevel#entitiesForRendering()}, but the output of that + * method is filtered of entities that are rendered by flywheel. This interface provides a workaround. + *

+ * @return An iterator over all entities in the level, including entities that are rendered by flywheel. + */ + Iterable flywheel$getAllLoadedEntities(); + + static ClientLevelExtension cast(ClientLevel level) { + return (ClientLevelExtension) level; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/util/DiffuseLightCalculator.java b/src/main/java/com/jozufozu/flywheel/util/DiffuseLightCalculator.java new file mode 100644 index 000000000..4fc5eeaf4 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/util/DiffuseLightCalculator.java @@ -0,0 +1,19 @@ +package com.jozufozu.flywheel.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; + +public interface DiffuseLightCalculator { + DiffuseLightCalculator DEFAULT = RenderMath::diffuseLight; + DiffuseLightCalculator NETHER = RenderMath::diffuseLightNether; + + static DiffuseLightCalculator forCurrentLevel() { + return forLevel(Minecraft.getInstance().level); + } + + static DiffuseLightCalculator forLevel(ClientLevel level) { + return level.effects().constantAmbientLight() ? NETHER : DEFAULT; + } + + float getDiffuse(float normalX, float normalY, float normalZ); +} diff --git a/src/main/java/com/jozufozu/flywheel/util/RenderMath.java b/src/main/java/com/jozufozu/flywheel/util/RenderMath.java index 3491e9319..9244d91f4 100644 --- a/src/main/java/com/jozufozu/flywheel/util/RenderMath.java +++ b/src/main/java/com/jozufozu/flywheel/util/RenderMath.java @@ -71,4 +71,8 @@ public class RenderMath { public static float diffuseLight(float x, float y, float z) { return Math.min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f); } + + public static float diffuseLightNether(float x, float y, float z) { + return Math.min(x * x * 0.6f + y * y * 0.9f + z * z * 0.8f, 1f); + } } diff --git a/src/main/java/com/jozufozu/flywheel/util/box/GridAlignedBB.java b/src/main/java/com/jozufozu/flywheel/util/box/GridAlignedBB.java index fa6925a36..279669f11 100644 --- a/src/main/java/com/jozufozu/flywheel/util/box/GridAlignedBB.java +++ b/src/main/java/com/jozufozu/flywheel/util/box/GridAlignedBB.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.util.box; +import java.util.Collection; + import com.jozufozu.flywheel.util.RenderMath; import net.minecraft.core.BlockPos; @@ -61,7 +63,28 @@ public class GridAlignedBB implements ImmutableBox { return new GridAlignedBB(startX, 0, startZ, startX + 16, 256, startZ + 16); } - public void fixMinMax() { + public static ImmutableBox containingAll(Collection positions) { + if (positions.isEmpty()) { + return new GridAlignedBB(); + } + int minX = Integer.MAX_VALUE; + int minY = Integer.MAX_VALUE; + int minZ = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int maxY = Integer.MIN_VALUE; + int maxZ = Integer.MIN_VALUE; + for (BlockPos pos : positions) { + minX = Math.min(minX, pos.getX()); + minY = Math.min(minY, pos.getY()); + minZ = Math.min(minZ, pos.getZ()); + maxX = Math.max(maxX, pos.getX()); + maxY = Math.max(maxY, pos.getY()); + maxZ = Math.max(maxZ, pos.getZ()); + } + return new GridAlignedBB(minX, minY, minZ, maxX, maxY, maxZ); + } + + public void fixMinMax() { int minX = Math.min(this.minX, this.maxX); int minY = Math.min(this.minY, this.maxY); int minZ = Math.min(this.minZ, this.maxZ); diff --git a/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java b/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java deleted file mode 100644 index 8a354c80a..000000000 --- a/src/main/java/com/jozufozu/flywheel/util/transform/MatrixTransformStack.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.jozufozu.flywheel.util.transform; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; -import com.mojang.math.Quaternion; - -public class MatrixTransformStack implements TransformStack { - - private final PoseStack internal; - - public MatrixTransformStack() { - this(new PoseStack()); - } - - public MatrixTransformStack(PoseStack internal) { - this.internal = internal; - } - - public PoseStack unwrap() { - return internal; - } - - public MatrixTransformStack setIdentity() { - if (internal.clear()) { - PoseStack.Pose last = internal.last(); - - last.normal() - .setIdentity(); - last.pose() - .setIdentity(); - } else { - internal.popPose(); - internal.pushPose(); - } - - return this; - } - - @Override - public TransformStack translate(double x, double y, double z) { - internal.translate(x, y, z); - return this; - } - - @Override - public TransformStack multiply(Quaternion quaternion) { - internal.mulPose(quaternion); - return this; - } - - @Override - public TransformStack scale(float factorX, float factorY, float factorZ) { - internal.scale(factorX, factorY, factorZ); - return this; - } - - @Override - public TransformStack pushPose() { - internal.pushPose(); - return this; - } - - @Override - public TransformStack popPose() { - internal.popPose(); - return this; - } - - @Override - public TransformStack mulPose(Matrix4f pose) { - internal.last().pose().multiply(pose); - return this; - } - - @Override - public TransformStack mulNormal(Matrix3f normal) { - internal.last().normal().mul(normal); - return this; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index c4d06994a..c094eaf25 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -9,7 +9,8 @@ import com.jozufozu.flywheel.core.hardcoded.ModelPart; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.core.model.Model; import com.jozufozu.flywheel.util.AnimationTickHolder; -import com.jozufozu.flywheel.util.transform.MatrixTransformStack; +import com.jozufozu.flywheel.util.transform.TransformStack; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector3f; import net.minecraft.client.renderer.RenderType; @@ -25,7 +26,7 @@ public class MinecartInstance extends EntityInstance private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); - MatrixTransformStack stack = new MatrixTransformStack(); + private final PoseStack stack = new PoseStack(); private final ModelData body; private ModelData contents; @@ -53,11 +54,12 @@ public class MinecartInstance extends EntityInstance @Override public void beginFrame() { + TransformStack tstack = TransformStack.cast(stack); stack.setIdentity(); float pt = AnimationTickHolder.getPartialTicks(); Vec3i originCoordinate = materialManager.getOriginCoordinate(); - stack.translate( + tstack.translate( Mth.lerp(pt, entity.xOld, entity.getX()) - originCoordinate.getX(), Mth.lerp(pt, entity.yOld, entity.getY()) - originCoordinate.getY(), Mth.lerp(pt, entity.zOld, entity.getZ()) - originCoordinate.getZ()); @@ -69,8 +71,8 @@ public class MinecartInstance extends EntityInstance float f = (((float)(i >> 16 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F; float f1 = (((float)(i >> 20 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F; float f2 = (((float)(i >> 24 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F; - stack.translate(f, f1, f2); - stack.nudge(entity.getId()); + tstack.translate(f, f1, f2); + tstack.nudge(entity.getId()); double d0 = Mth.lerp(pt, entity.xOld, entity.getX()); double d1 = Mth.lerp(pt, entity.yOld, entity.getY()); double d2 = Mth.lerp(pt, entity.zOld, entity.getZ()); @@ -87,7 +89,7 @@ public class MinecartInstance extends EntityInstance vector3d2 = vector3d; } - stack.translate(vector3d.x - d0, (vector3d1.y + vector3d2.y) / 2.0D - d1, vector3d.z - d2); + tstack.translate(vector3d.x - d0, (vector3d1.y + vector3d2.y) / 2.0D - d1, vector3d.z - d2); Vec3 vector3d3 = vector3d2.add(-vector3d1.x, -vector3d1.y, -vector3d1.z); if (vector3d3.length() != 0.0D) { vector3d3 = vector3d3.normalize(); @@ -96,9 +98,9 @@ public class MinecartInstance extends EntityInstance } } - stack.translate(0.0D, 0.375D, 0.0D); - stack.multiply(Vector3f.YP.rotationDegrees(180 - yaw)); - stack.multiply(Vector3f.ZP.rotationDegrees(-f3)); + tstack.translate(0.0D, 0.375D, 0.0D); + tstack.multiply(Vector3f.YP.rotationDegrees(180 - yaw)); + tstack.multiply(Vector3f.ZP.rotationDegrees(-f3)); float f5 = (float)entity.getHurtTime() - pt; float f6 = entity.getDamage() - pt; if (f6 < 0) { @@ -106,20 +108,20 @@ public class MinecartInstance extends EntityInstance } if (f5 > 0) { - stack.multiply(Vector3f.XP.rotationDegrees(Mth.sin(f5) * f5 * f6 / 10 * (float)entity.getHurtDir())); + tstack.multiply(Vector3f.XP.rotationDegrees(Mth.sin(f5) * f5 * f6 / 10 * (float)entity.getHurtDir())); } int j = entity.getDisplayOffset(); if (contents != null) { - stack.pushPose(); - stack.scale(0.75F); - stack.translate(-0.5D, (float)(j - 8) / 16, 0.5D); - stack.multiply(Vector3f.YP.rotationDegrees(90)); - contents.setTransform(stack.unwrap()); - stack.popPose(); + tstack.pushPose(); + tstack.scale(0.75F); + tstack.translate(-0.5D, (float)(j - 8) / 16, 0.5D); + tstack.multiply(Vector3f.YP.rotationDegrees(90)); + contents.setTransform(stack); + tstack.popPose(); } - body.setTransform(stack.unwrap()); + body.setTransform(stack); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java index 167b2367a..a55e62eb8 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxInstance.java @@ -7,7 +7,8 @@ import com.jozufozu.flywheel.core.Materials; import com.jozufozu.flywheel.core.hardcoded.ModelPart; import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.util.AnimationTickHolder; -import com.jozufozu.flywheel.util.transform.MatrixTransformStack; +import com.jozufozu.flywheel.util.transform.TransformStack; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Quaternion; import com.mojang.math.Vector3f; @@ -25,7 +26,7 @@ public class ShulkerBoxInstance extends BlockEntityInstance