diff --git a/gradle.properties b/gradle.properties index 984e19f84..dff493265 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ cursegradle_version = 1.4.0 # dependency versions registrate_version = 1.0.10 -flywheel_version = 1.16-0.2.0.41 +flywheel_version = 1.16-0.2.3.44 jei_version = 7.7.1.116 # curseforge information diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java index 3a81d4509..7270d25ec 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillRenderer.java @@ -44,7 +44,7 @@ public class DrillRenderer extends KineticTileEntityRenderer { float time = AnimationTickHolder.getRenderTime() / 20; float angle = (float) (((time * speed) % 360)); - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); MatrixTransformStack.of(m) .centre() @@ -55,9 +55,9 @@ public class DrillRenderer extends KineticTileEntityRenderer { superBuffer .transform(m) - .light(matrices.entityMatrix, + .light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.solid())); + .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); m.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java index 79eee6a0a..0aac5f333 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterRenderer.java @@ -52,13 +52,13 @@ public class HarvesterRenderer extends SafeTileEntityRenderer sbb.light(matrices.entityMatrix, + render(blockState, lit, progress, matrices.getModel(), sbb -> sbb.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, vb)); + .renderInto(matrices.getViewProjection(), vb)); } private static void render(BlockState blockState, boolean lit, float progress, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java index 72b799cb3..c639e1bf4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerRenderer.java @@ -181,7 +181,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer Vector3d offset = Vector3d.atLowerCornerOf(blockState.getValue(FACING) .getNormal()).scale(factor); - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); m.translate(offset.x, offset.y, offset.z); @@ -190,10 +190,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer pole = transform(world, pole, blockState, pos, true); hand = transform(world, hand, blockState, pos, false); - pole.light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, builder); - hand.light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, builder); + pole.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) + .renderInto(matrices.getViewProjection(), builder); + hand.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) + .renderInto(matrices.getViewProjection(), builder); m.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java index 91e468f99..4f52cd5d8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawRenderer.java @@ -192,7 +192,7 @@ public class SawRenderer extends SafeTileEntityRenderer { superBuffer = PartialBufferer.get(AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE, state); } - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); MatrixTransformStack.of(m) .centre() @@ -205,8 +205,8 @@ public class SawRenderer extends SafeTileEntityRenderer { .unCentre(); superBuffer.transform(m) - .light(matrices.entityMatrix, ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.cutoutMipped())); + .light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) + .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.cutoutMipped())); m.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java index 57e249dcf..8be7f7b41 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntityRenderer.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -39,7 +38,7 @@ public class ContraptionEntityRenderer exte Contraption contraption = entity.getContraption(); if (contraption != null) { - ContraptionRenderDispatcher.render(entity, contraption, buffers); + ContraptionRenderDispatcher.renderFromEntity(entity, contraption, buffers); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index 82ae9b925..2e03a363e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -53,14 +53,14 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { orientation = rotation; - superBuffer.transform(matrices.contraptionStack); + superBuffer.transform(matrices.getModel()); superBuffer.rotateCentered(orientation); // render superBuffer - .light(matrices.entityMatrix, + .light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)) - .renderInto(matrices.entityStack, buffer.getBuffer(RenderType.solid())); + .renderInto(matrices.getViewProjection(), buffer.getBuffer(RenderType.solid())); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java index 202d5dddf..f2c43dfeb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMatrices.java @@ -6,9 +6,16 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Matrix3f; import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3d; +/** + * LIFETIME: one frame + * + *

+ * ContraptionMatrices must be re-created per-contraption per-frame + *

+ */ public class ContraptionMatrices { /** @@ -16,47 +23,68 @@ public class ContraptionMatrices { */ public static final ContraptionMatrices EMPTY = new ContraptionMatrices(); - public final MatrixStack entityStack; - public final MatrixStack contraptionStack; - public final MatrixStack finalStack; - public final Matrix4f entityMatrix; - public final Matrix4f lightMatrix; + private final MatrixStack modelViewProjection; + private final MatrixStack viewProjection; + private final MatrixStack model; + private final Matrix4f world; + private final Matrix4f light; private ContraptionMatrices() { - this.entityStack = this.contraptionStack = this.finalStack = new MatrixStack(); - this.entityMatrix = new Matrix4f(); - this.lightMatrix = new Matrix4f(); + this.viewProjection = this.model = this.modelViewProjection = new MatrixStack(); + this.world = new Matrix4f(); + this.light = new Matrix4f(); } - public ContraptionMatrices(MatrixStack entityStack, AbstractContraptionEntity entity) { - this.entityStack = copyStack(entityStack); - this.contraptionStack = new MatrixStack(); + public ContraptionMatrices(MatrixStack viewProjection, AbstractContraptionEntity entity) { + this.viewProjection = copyStack(viewProjection); float partialTicks = AnimationTickHolder.getPartialTicks(); - entity.doLocalTransforms(partialTicks, new MatrixStack[] { this.contraptionStack }); + this.model = creatModelMatrix(entity, partialTicks); - entityMatrix = translateTo(entity, partialTicks); + world = translateTo(entity, partialTicks); - lightMatrix = entityMatrix.copy(); - lightMatrix.multiply(contraptionStack.last().pose()); + light = getWorld().copy(); + getLight().multiply(this.getModel() + .last().pose()); - finalStack = copyStack(entityStack); - transform(finalStack, contraptionStack); + modelViewProjection = copyStack(viewProjection); + transform(getModelViewProjection(), this.getModel()); } - public MatrixStack getFinalStack() { - return finalStack; + public MatrixStack getModelViewProjection() { + return modelViewProjection; } - public Matrix4f getFinalModel() { - return finalStack.last().pose(); + public MatrixStack getViewProjection() { + return viewProjection; } - public Matrix3f getFinalNormal() { - return finalStack.last().normal(); + public MatrixStack getModel() { + return model; } - public Matrix4f getFinalLight() { - return lightMatrix; + public Matrix4f getWorld() { + return world; + } + + public Matrix4f getLight() { + return light; + } + + public static Matrix4f createModelViewPartial(AbstractContraptionEntity entity, float pt, Vector3d cameraPos) { + float x = (float) (MathHelper.lerp(pt, entity.xOld, entity.getX()) - cameraPos.x); + float y = (float) (MathHelper.lerp(pt, entity.yOld, entity.getY()) - cameraPos.y); + float z = (float) (MathHelper.lerp(pt, entity.zOld, entity.getZ()) - cameraPos.z); + Matrix4f mat = Matrix4f.createTranslateMatrix(x, y, z); + Matrix4f modelMatrix = creatModelMatrix(entity, pt).last().pose(); + + mat.multiply(modelMatrix); + return mat; + } + + public static MatrixStack creatModelMatrix(AbstractContraptionEntity entity, float partialTicks) { + MatrixStack model = new MatrixStack(); + entity.doLocalTransforms(partialTicks, new MatrixStack[] { model}); + return model; } public static Matrix4f translateTo(Entity entity, float partialTicks) { @@ -82,9 +110,4 @@ public class ContraptionMatrices { return cms; } - - public Matrix4f contraptionPose() { - return contraptionStack.last() - .pose(); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 2d98ca770..ddcadab07 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -71,13 +71,24 @@ public class ContraptionRenderDispatcher { reset(); } - public static void render(AbstractContraptionEntity entity, Contraption contraption, IRenderTypeBuffer buffers) { + public static void renderFromEntity(AbstractContraptionEntity entity, Contraption contraption, IRenderTypeBuffer buffers) { World world = entity.level; ContraptionRenderInfo renderInfo = WORLDS.get(world) .getRenderInfo(contraption); + ContraptionMatrices matrices = renderInfo.getMatrices(); - renderDynamic(world, renderInfo.renderWorld, contraption, renderInfo.getMatrices(), buffers); + // something went wrong with the other rendering + if (matrices == null) return; + + PlacementSimulationWorld renderWorld = renderInfo.renderWorld; + + renderTileEntities(world, renderWorld, contraption, matrices, buffers); + + if (buffers instanceof IRenderTypeBuffer.Impl) + ((IRenderTypeBuffer.Impl) buffers).endBatch(); + + renderActors(world, renderWorld, contraption, matrices, buffers); } public static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) { @@ -96,18 +107,10 @@ public class ContraptionRenderDispatcher { return renderWorld; } - public static void renderDynamic(World world, PlacementSimulationWorld renderWorld, Contraption c, - ContraptionMatrices matrices, IRenderTypeBuffer buffer) { - renderTileEntities(world, renderWorld, c, matrices, buffer); - if (buffer instanceof IRenderTypeBuffer.Impl) - ((IRenderTypeBuffer.Impl) buffer).endBatch(); - renderActors(world, renderWorld, c, matrices, buffer); - } - public static void renderTileEntities(World world, PlacementSimulationWorld renderWorld, Contraption c, ContraptionMatrices matrices, IRenderTypeBuffer buffer) { TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, - matrices.getFinalStack(), matrices.getFinalLight(), buffer); + matrices.getModelViewProjection(), matrices.getLight(), buffer); } protected static void renderActors(World world, PlacementSimulationWorld renderWorld, Contraption c, @@ -120,7 +123,7 @@ public class ContraptionRenderDispatcher { context.world = world; Template.BlockInfo blockInfo = actor.getLeft(); - MatrixStack m = matrices.contraptionStack; + MatrixStack m = matrices.getModel(); m.pushPose(); MatrixTransformStack.of(m) .translate(blockInfo.pos); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java index db8c3e764..1000aeed2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderInfo.java @@ -1,6 +1,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; +import javax.annotation.Nullable; + import com.jozufozu.flywheel.event.BeginFrameEvent; +import com.jozufozu.flywheel.event.RenderLayerEvent; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -30,29 +34,41 @@ public class ContraptionRenderInfo { } public void beginFrame(BeginFrameEvent event) { + matrices = null; + AbstractContraptionEntity entity = contraption.entity; visible = event.getClippingHelper().isVisible(entity.getBoundingBoxForCulling().inflate(2)); - - event.getStack().pushPose(); - - Vector3d cameraPos = event.getInfo() - .getPosition(); - double x = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.xOld, entity.getX()) - cameraPos.x; - double y = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.yOld, entity.getY()) - cameraPos.y; - double z = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.zOld, entity.getZ()) - cameraPos.z; - - event.getStack().translate(x, y, z); - - matrices = new ContraptionMatrices(event.getStack(), entity); - - event.getStack().popPose(); } public boolean isVisible() { return visible && contraption.entity.isAlive(); } + /** + * Need to call this during RenderLayerEvent. + */ + public void setupMatrices(MatrixStack viewProjection, double camX, double camY, double camZ) { + if (matrices == null) { + AbstractContraptionEntity entity = contraption.entity; + + viewProjection.pushPose(); + + double x = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.xOld, entity.getX()) - camX; + double y = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.yOld, entity.getY()) - camY; + double z = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), entity.zOld, entity.getZ()) - camZ; + + viewProjection.translate(x, y, z); + + matrices = new ContraptionMatrices(viewProjection, entity); + + viewProjection.popPose(); + } + } + + /** + * If #setupMatrices is called correctly, this will not return null + */ public ContraptionMatrices getMatrices() { return matrices; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java index 8d94a681a..735d569f1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java @@ -29,7 +29,11 @@ public abstract class ContraptionRenderManager this.world = (World) world; } - public abstract void renderLayer(RenderLayerEvent event); + public void renderLayer(RenderLayerEvent event) { + for (C c : visible) { + c.setupMatrices(event.stack, event.camX, event.camY, event.camZ); + } + } protected abstract C create(Contraption c); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index 3aff78682..efd42ad70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -38,6 +38,8 @@ public class FlwContraptionManager extends ContraptionRenderManager renderLayers = new HashMap<>(); - private Matrix4f model; + private Matrix4f modelViewPartial; private AxisAlignedBB lightBox; public RenderedContraption(Contraption contraption, PlacementSimulationWorld renderWorld) { @@ -78,26 +77,17 @@ public class RenderedContraption extends ContraptionRenderInfo { kinetics.beginFrame(event.getInfo()); - AbstractContraptionEntity entity = contraption.entity; - float pt = AnimationTickHolder.getPartialTicks(); - AxisAlignedBB lightBox = GridAlignedBB.toAABB(lighter.lightVolume.getTextureVolume()); + Vector3d cameraPos = event.getCameraPos(); - Vector3d cameraPos = event.getInfo() - .getPosition(); + modelViewPartial = ContraptionMatrices.createModelViewPartial(contraption.entity, AnimationTickHolder.getPartialTicks(), cameraPos); - float x = (float) (MathHelper.lerp(pt, entity.xOld, entity.getX()) - cameraPos.x); - float y = (float) (MathHelper.lerp(pt, entity.yOld, entity.getY()) - cameraPos.y); - float z = (float) (MathHelper.lerp(pt, entity.zOld, entity.getZ()) - cameraPos.z); - model = Matrix4f.createTranslateMatrix(x, y, z); - - model.multiply(getMatrices().contraptionPose()); - - this.lightBox = lightBox.move(-cameraPos.x, -cameraPos.y, -cameraPos.z); + lightBox = GridAlignedBB.toAABB(lighter.lightVolume.getTextureVolume()) + .move(-cameraPos.x, -cameraPos.y, -cameraPos.z); } void setup(ContraptionProgram shader) { - if (model == null || lightBox == null) return; - shader.bind(model, lightBox); + if (modelViewPartial == null || lightBox == null) return; + shader.bind(modelViewPartial, lightBox); lighter.lightVolume.bind(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java index 94f0fec6d..4c68ea22c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/SBBContraptionManager.java @@ -21,6 +21,7 @@ public class SBBContraptionManager extends ContraptionRenderManager renderContraptionLayerSBB(event, info)); } @@ -38,12 +39,12 @@ public class SBBContraptionManager extends ContraptionRenderManager buildStructureBuffer(renderInfo.renderWorld, renderInfo.contraption, layer)); if (!contraptionBuffer.isEmpty()) { - ContraptionMatrices matrices = renderInfo.getMatrices(); - contraptionBuffer.transform(matrices.contraptionStack) - .light(matrices.entityMatrix) + + contraptionBuffer.transform(matrices.getModel()) + .light(matrices.getWorld()) .hybridLight() - .renderInto(matrices.entityStack, event.buffers.bufferSource() + .renderInto(matrices.getViewProjection(), event.buffers.bufferSource() .getBuffer(layer)); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index c932c8408..4f944f0a4 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -32,6 +32,6 @@ Technology that empowers the player.''' [[dependencies.create]] modId="flywheel" mandatory=true - versionRange="[1.16-0.2,1.16-0.3)" + versionRange="[1.16-0.2.3,1.16-0.3)" ordering="AFTER" side="CLIENT"