From e33ab160ac50f705eff9e6153a71bff9b6a6a2df Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 28 Apr 2021 22:47:51 -0700 Subject: [PATCH] Start to cleanup the AllBlockPartials methods --- .../com/simibubi/create/AllBlockPartials.java | 66 ------------------ .../contraptions/base/HalfShaftInstance.java | 6 +- .../components/actors/DrillInstance.java | 4 +- .../components/actors/DrillRenderer.java | 19 +++--- .../components/actors/HarvesterRenderer.java | 15 ++-- .../PortableStorageInterfaceRenderer.java | 13 ++-- .../components/clock/CuckooClockRenderer.java | 25 +++---- .../crafter/MechanicalCrafterRenderer.java | 9 +-- .../components/crank/HandCrankInstance.java | 25 +++---- .../components/crank/HandCrankRenderer.java | 5 +- .../components/deployer/DeployerRenderer.java | 16 ++--- .../components/fan/EncasedFanRenderer.java | 11 +-- .../components/fan/FanInstance.java | 16 ++--- .../components/flywheel/FlyWheelInstance.java | 27 ++++---- .../components/flywheel/FlywheelRenderer.java | 30 ++++---- .../flywheel/engine/EngineRenderer.java | 13 ++-- .../mixer/MechanicalMixerRenderer.java | 17 ++--- .../motor/CreativeMotorRenderer.java | 3 +- .../press/MechanicalPressRenderer.java | 7 +- .../components/saw/SawInstance.java | 4 +- .../components/saw/SawRenderer.java | 21 +++--- .../bearing/BearingRenderer.java | 17 ++--- .../StabilizedBearingMovementBehaviour.java | 3 +- .../chassis/StickerRenderer.java | 9 +-- .../gantry/GantryCarriageRenderer.java | 19 +++--- .../pulley/AbstractPulleyRenderer.java | 12 ++-- .../pulley/HosePulleyInstance.java | 2 +- .../pulley/RopePulleyInstance.java | 2 +- .../train/CouplingRenderer.java | 27 ++++---- .../contraptions/fluids/PumpCogInstance.java | 8 ++- .../contraptions/fluids/PumpRenderer.java | 21 +++--- .../fluids/actors/HosePulleyRenderer.java | 5 +- .../fluids/actors/SpoutRenderer.java | 7 +- .../fluids/pipes/FluidValveRenderer.java | 3 +- .../burner/BlazeBurnerRenderer.java | 5 +- .../advanced/SpeedControllerRenderer.java | 5 +- .../relays/belt/BeltRenderer.java | 30 ++++---- .../relays/encased/SplitShaftInstance.java | 8 +-- .../relays/encased/SplitShaftRenderer.java | 3 +- .../relays/gauge/GaugeRenderer.java | 13 ++-- .../relays/gearbox/GearboxInstance.java | 22 +++--- .../relays/gearbox/GearboxRenderer.java | 3 +- .../belts/tunnel/BeltTunnelRenderer.java | 3 +- .../block/depot/EjectorRenderer.java | 5 +- .../diodes/AdjustableRepeaterRenderer.java | 3 +- .../block/funnel/FunnelRenderer.java | 10 +-- .../block/mechanicalArm/ArmRenderer.java | 23 ++++--- .../block/redstone/AnalogLeverRenderer.java | 15 ++-- .../block/SchematicannonRenderer.java | 7 +- .../foundation/render/PartialBufferer.java | 68 +++++++++++++++++++ .../render/SuperByteBufferCache.java | 8 +-- .../backend/instancing/RenderMaterial.java | 30 +++++--- 52 files changed, 403 insertions(+), 345 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/render/PartialBufferer.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index d6a27e9d0..d32c28e3d 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -1,26 +1,15 @@ package com.simibubi.create; -import static net.minecraft.state.properties.BlockStateProperties.FACING; -import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Supplier; -import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; -import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial; -import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; -import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; @@ -188,59 +177,4 @@ public class AllBlockPartials { return bakedModel; } - public SuperByteBuffer renderOn(BlockState referenceState) { - return CreateClient.bufferCache.renderPartial(this, referenceState); - } - - public SuperByteBuffer renderOnDirectionalSouth(BlockState referenceState) { - Direction facing = referenceState.get(FACING); - return renderOnDirectionalSouth(referenceState, facing); - } - - public SuperByteBuffer renderOnDirectional(BlockState referenceState) { - Direction facing = referenceState.get(FACING); - return renderOnDirectional(referenceState, facing); - } - - public SuperByteBuffer renderOnHorizontal(BlockState referenceState) { - Direction facing = referenceState.get(HORIZONTAL_FACING); - return renderOnDirectionalSouth(referenceState, facing); - } - - public SuperByteBuffer renderOnDirectionalSouth(BlockState referenceState, Direction facing) { - MatrixStack ms = new MatrixStack(); - // TODO 1.15 find a way to cache this model matrix computation - MatrixStacker.of(ms) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(AngleHelper.verticalAngle(facing)) - .unCentre(); - return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); - } - - public SuperByteBuffer renderOnDirectional(BlockState referenceState, Direction facing) { - MatrixStack ms = new MatrixStack(); - // TODO 1.15 find a way to cache this model matrix computation - MatrixStacker.of(ms) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) - .unCentre(); - return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms); - } - - public > M getModel(RenderMaterial mat, BlockState referenceState, - Direction facing) { - Supplier ms = () -> { - MatrixStack stack = new MatrixStack(); - MatrixStacker.of(stack) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(AngleHelper.verticalAngle(facing)) - .unCentre(); - return stack; - }; - return mat.getModel(this, referenceState, facing, ms); - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index 4b834f520..6d3664988 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -14,9 +14,9 @@ public class HalfShaftInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - Direction dir = getShaftDirection(); - return AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), blockState, dir); - } + Direction dir = getShaftDirection(); + return getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, dir); + } protected Direction getShaftDirection() { return blockState.get(BlockStateProperties.FACING); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java index ad6b2ce47..7d1bdd735 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; public class DrillInstance extends SingleRotatingInstance { @@ -20,6 +21,7 @@ public class DrillInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { BlockState referenceState = tile.getBlockState(); - return AllBlockPartials.DRILL_HEAD.getModel(getRotatingMaterial(), referenceState, referenceState.get(FACING)); + Direction facing = referenceState.get(FACING); + return getRotatingMaterial().getModel(AllBlockPartials.DRILL_HEAD, referenceState, facing); } } 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 38f940dab..288451551 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 @@ -5,6 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -25,22 +26,18 @@ public class DrillRenderer extends KineticTileEntityRenderer { @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(te.getBlockState()); - } - - protected static SuperByteBuffer getRotatingModel(BlockState state) { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouth(state); + return PartialBufferer.getDirectionalSouth(AllBlockPartials.DRILL_HEAD, te.getBlockState()); } public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { - MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal }; + MatrixStack[] matrixStacks = new MatrixStack[]{ms, msLocal}; BlockState state = context.state; - SuperByteBuffer superBuffer = AllBlockPartials.DRILL_HEAD.renderOn(state); + SuperByteBuffer superBuffer = PartialBufferer.get(AllBlockPartials.DRILL_HEAD, state); Direction facing = state.get(DrillBlock.FACING); - + float speed = (float) (context.contraption.stalled - || !VecHelper.isVecPointingTowards(context.relativeMotion, facing + || !VecHelper.isVecPointingTowards(context.relativeMotion, facing .getOpposite()) ? context.getAnimationSpeed() : 0); float time = AnimationTickHolder.getRenderTime() / 20; float angle = (float) (((time * speed) % 360)); @@ -52,11 +49,11 @@ public class DrillRenderer extends KineticTileEntityRenderer { .rotateX(AngleHelper.verticalAngle(facing)) .rotateZ(angle) .unCentre(); - + superBuffer .light(msLocal.peek() .getModel()) .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } -} \ No newline at end of file +} 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 5b50202e3..44cf29765 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 @@ -6,6 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -31,28 +32,28 @@ public class HarvesterRenderer extends SafeTileEntityRenderer modelManager, HandCrankTileEntity tile) { super(modelManager, tile); - this.tile = tile; + this.tile = tile; - Block block = blockState.getBlock(); - AllBlockPartials renderedHandle = null; - if (block instanceof HandCrankBlock) - renderedHandle = ((HandCrankBlock) block).getRenderedHandle(); - if (renderedHandle == null) - return; + Block block = blockState.getBlock(); + AllBlockPartials renderedHandle = null; + if (block instanceof HandCrankBlock) + renderedHandle = ((HandCrankBlock) block).getRenderedHandle(); + if (renderedHandle == null) + return; - facing = blockState.get(BlockStateProperties.FACING); - InstancedModel model = renderedHandle.getModel(getTransformMaterial(), blockState, facing.getOpposite()); - crank = model.createInstance(); + facing = blockState.get(BlockStateProperties.FACING); + Direction opposite = facing.getOpposite(); + InstancedModel model = getTransformMaterial().getModel(renderedHandle, blockState, opposite); + crank = model.createInstance(); - rotateCrank(); - } + rotateCrank(); + } @Override public void beginFrame() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java index 11442df9e..bbf3ec4f6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java @@ -6,6 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; @@ -38,10 +39,10 @@ public class HandCrankRenderer extends KineticTileEntityRenderer { return; Direction facing = state.get(FACING); - SuperByteBuffer handle = renderedHandle.renderOnDirectionalSouth(state, facing.getOpposite()); + SuperByteBuffer handle = PartialBufferer.getDirectionalSouth(renderedHandle, state, facing.getOpposite()); HandCrankTileEntity crank = (HandCrankTileEntity) te; kineticRotationTransform(handle, te, facing.getAxis(), - (crank.independentAngle + partialTicks * crank.chasingVelocity) / 360, light); + (crank.independentAngle + partialTicks * crank.chasingVelocity) / 360, light); handle.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } 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 d9dd683c6..84eccae4c 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 @@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; @@ -117,14 +118,13 @@ public class DeployerRenderer extends SafeTileEntityRenderer BlockPos pos = te.getPos(); Vector3d offset = getHandOffset(te, partialTicks, blockState); - SuperByteBuffer pole = AllBlockPartials.DEPLOYER_POLE.renderOn(blockState); - SuperByteBuffer hand = te.getHandPose() - .renderOn(blockState); + SuperByteBuffer pole = PartialBufferer.get(AllBlockPartials.DEPLOYER_POLE, blockState); + SuperByteBuffer hand = PartialBufferer.get(te.getHandPose(), blockState); transform(te.getWorld(), pole.translate(offset.x, offset.y, offset.z), blockState, pos, true).renderInto(ms, - vb); + vb); transform(te.getWorld(), hand.translate(offset.x, offset.y, offset.z), blockState, pos, false).renderInto(ms, - vb); + vb); } protected Vector3d getHandOffset(DeployerTileEntity te, float partialTicks, BlockState blockState) { @@ -155,7 +155,7 @@ public class DeployerRenderer extends SafeTileEntityRenderer public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, IRenderTypeBuffer buffer) { - MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal }; + MatrixStack[] matrixStacks = new MatrixStack[]{ms, msLocal}; IVertexBuilder builder = buffer.getBuffer(RenderType.getSolid()); BlockState blockState = context.state; BlockPos pos = BlockPos.ZERO; @@ -163,8 +163,8 @@ public class DeployerRenderer extends SafeTileEntityRenderer World world = context.world; AllBlockPartials handPose = getHandPose(mode); - SuperByteBuffer pole = AllBlockPartials.DEPLOYER_POLE.renderOn(blockState); - SuperByteBuffer hand = handPose.renderOn(blockState); + SuperByteBuffer pole = PartialBufferer.get(AllBlockPartials.DEPLOYER_POLE, blockState); + SuperByteBuffer hand = PartialBufferer.get(handPose, blockState); pole = transform(world, pole, blockState, pos, true); hand = transform(world, hand, blockState, pos, false); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java index cb469d615..0cf853af1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/EncasedFanRenderer.java @@ -7,6 +7,7 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -30,17 +31,17 @@ public class EncasedFanRenderer extends KineticTileEntityRenderer { if (FastRenderDispatcher.available(te.getWorld())) return; Direction direction = te.getBlockState() - .get(FACING); + .get(FACING); IVertexBuilder vb = buffer.getBuffer(RenderType.getCutoutMipped()); int lightBehind = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction.getOpposite())); int lightInFront = WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getPos().offset(direction)); - + SuperByteBuffer shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); + PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction.getOpposite()); SuperByteBuffer fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouth(te.getBlockState(), direction.getOpposite()); - + PartialBufferer.getDirectionalSouth(AllBlockPartials.ENCASED_FAN_INNER, te.getBlockState(), direction.getOpposite()); + float time = AnimationTickHolder.getRenderTime(te.getWorld()); float speed = te.getSpeed() * 5; if (speed > 0) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index 05e921f0a..2feec9410 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -19,17 +19,17 @@ public class FanInstance extends KineticTileInstance { private final Direction opposite; public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { - super(modelManager, tile); + super(modelManager, tile); - direction = blockState.get(FACING); + direction = blockState.get(FACING); - opposite = direction.getOpposite(); - shaft = AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), blockState, opposite).createInstance(); - fan = AllBlockPartials.ENCASED_FAN_INNER.getModel(getRotatingMaterial(), blockState, opposite).createInstance(); + opposite = direction.getOpposite(); + shaft = getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, opposite).createInstance(); + fan = getRotatingMaterial().getModel(AllBlockPartials.ENCASED_FAN_INNER, blockState, opposite).createInstance(); - setup(shaft); - setup(fan, getFanSpeed()); - } + setup(shaft); + setup(fan, getFanSpeed()); + } private float getFanSpeed() { float speed = tile.getSpeed() * 5; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index d01c2633f..c4a1f2385 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -46,24 +46,24 @@ public class FlyWheelInstance extends KineticTileInstance im protected float lastAngle = Float.NaN; public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { - super(modelManager, tile); + super(modelManager, tile); - facing = blockState.get(HORIZONTAL_FACING); + facing = blockState.get(HORIZONTAL_FACING); - shaft = setup(shaftModel().createInstance()); + shaft = setup(shaftModel().createInstance()); - BlockState referenceState = blockState.rotate(Rotation.CLOCKWISE_90); - wheel = AllBlockPartials.FLYWHEEL.getModel(getTransformMaterial(), referenceState, referenceState.get(HORIZONTAL_FACING)).createInstance(); + BlockState referenceState = blockState.rotate(Rotation.CLOCKWISE_90); + wheel = getTransformMaterial().getModel(AllBlockPartials.FLYWHEEL, referenceState, facing).createInstance(); - connection = FlywheelBlock.getConnection(blockState); - if (connection != null) { - connectedLeft = blockState.get(FlywheelBlock.CONNECTION) == FlywheelBlock.ConnectionState.LEFT; + connection = FlywheelBlock.getConnection(blockState); + if (connection != null) { + connectedLeft = blockState.get(FlywheelBlock.CONNECTION) == FlywheelBlock.ConnectionState.LEFT; - boolean flipAngle = connection.getAxis() == Direction.Axis.X ^ connection.getAxisDirection() == Direction.AxisDirection.NEGATIVE; + boolean flipAngle = connection.getAxis() == Direction.Axis.X ^ connection.getAxisDirection() == Direction.AxisDirection.NEGATIVE; - connectorAngleMult = flipAngle ? -1 : 1; + connectorAngleMult = flipAngle ? -1 : 1; - RenderMaterial> mat = getTransformMaterial(); + RenderMaterial> mat = getTransformMaterial(); upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); @@ -159,8 +159,9 @@ public class FlyWheelInstance extends KineticTileInstance im } protected InstancedModel shaftModel() { - return AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), blockState, facing.getOpposite()); - } + Direction opposite = facing.getOpposite(); + return getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, opposite); + } protected void transformConnector(MatrixStacker ms, boolean upper, boolean rotating, float angle, boolean flip) { float shift = upper ? 1 / 4f : -1 / 8f; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 03434b9e9..f219c4ec4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -8,6 +8,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock.ConnectionState; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AngleHelper; @@ -17,6 +18,7 @@ import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; @@ -54,33 +56,33 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { boolean flip = blockState.get(FlywheelBlock.CONNECTION) == ConnectionState.LEFT; transformConnector( - rotateToFacing(AllBlockPartials.FLYWHEEL_UPPER_ROTATING.renderOn(blockState), connection), true, true, - rotation, flip).light(light) + rotateToFacing(PartialBufferer.get(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState), connection), true, true, + rotation, flip).light(light) .renderInto(ms, vb); transformConnector( - rotateToFacing(AllBlockPartials.FLYWHEEL_LOWER_ROTATING.renderOn(blockState), connection), false, true, - rotation, flip).light(light) + rotateToFacing(PartialBufferer.get(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState), connection), false, true, + rotation, flip).light(light) .renderInto(ms, vb); - - transformConnector(rotateToFacing(AllBlockPartials.FLYWHEEL_UPPER_SLIDING.renderOn(blockState), connection), - true, false, rotation, flip).light(light) + + transformConnector(rotateToFacing(PartialBufferer.get(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, blockState), connection), + true, false, rotation, flip).light(light) .renderInto(ms, vb); - transformConnector(rotateToFacing(AllBlockPartials.FLYWHEEL_LOWER_SLIDING.renderOn(blockState), connection), - false, false, rotation, flip).light(light) + transformConnector(rotateToFacing(PartialBufferer.get(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, blockState), connection), + false, false, rotation, flip).light(light) .renderInto(ms, vb); } - SuperByteBuffer wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontal(blockState.rotate(Rotation.CLOCKWISE_90)); + SuperByteBuffer wheel = PartialBufferer.getHorizontal(AllBlockPartials.FLYWHEEL, blockState.rotate(Rotation.CLOCKWISE_90)); kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) - .getAxis(), AngleHelper.rad(angle), light); + .getAxis(), AngleHelper.rad(angle), light); wheel.renderInto(ms, vb); } @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() - .get(HORIZONTAL_FACING) - .getOpposite()); + return PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, te.getBlockState(), te.getBlockState() + .get(BlockStateProperties.HORIZONTAL_FACING) + .getOpposite()); } protected SuperByteBuffer transformConnector(SuperByteBuffer buffer, boolean upper, boolean rotating, float angle, diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java index 597895c48..c96459be9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -32,13 +33,13 @@ public class EngineRenderer extends SafeTileEntityRe AllBlockPartials frame = engineBlock.getFrameModel(); if (frame != null) { Direction facing = te.getBlockState() - .get(EngineBlock.HORIZONTAL_FACING); + .get(EngineBlock.HORIZONTAL_FACING); float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing)); - frame.renderOn(te.getBlockState()) - .rotateCentered(Direction.UP, angle) - .translate(0, 0, -1) - .light(WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getBlockState(), te.getPos())) - .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + PartialBufferer.get(frame, te.getBlockState()) + .rotateCentered(Direction.UP, angle) + .translate(0, 0, -1) + .light(WorldRenderer.getLightmapCoordinates(te.getWorld(), te.getBlockState(), te.getPos())) + .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java index 41635cb02..cf0cfe81a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MechanicalMixerRenderer.java @@ -5,6 +5,7 @@ import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -40,7 +41,7 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState); + SuperByteBuffer superBuffer = PartialBufferer.get(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState); standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos); @@ -49,16 +50,16 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer { float time = AnimationTickHolder.getRenderTime(te.getWorld()); float angle = ((time * speed * 6 / 10f) % 360) / 180 * (float) Math.PI; - SuperByteBuffer poleRender = AllBlockPartials.MECHANICAL_MIXER_POLE.renderOn(blockState); + SuperByteBuffer poleRender = PartialBufferer.get(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState); poleRender.translate(0, -renderedHeadOffset, 0) - .light(packedLightmapCoords) - .renderInto(ms, vb); + .light(packedLightmapCoords) + .renderInto(ms, vb); - SuperByteBuffer headRender = AllBlockPartials.MECHANICAL_MIXER_HEAD.renderOn(blockState); + SuperByteBuffer headRender = PartialBufferer.get(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState); headRender.rotateCentered(Direction.UP, angle) - .translate(0, -renderedHeadOffset, 0) - .light(packedLightmapCoords) - .renderInto(ms, vb); + .translate(0, -renderedHeadOffset, 0) + .light(packedLightmapCoords) + .renderInto(ms, vb); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java index 215cf1b57..e8651ecd3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/motor/CreativeMotorRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.motor; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -15,7 +16,7 @@ public class CreativeMotorRenderer extends KineticTileEntityRenderer { @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState()); + return PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java index e2aa898ad..045d4c7a3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/MechanicalPressRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; @@ -37,10 +38,10 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos); float renderedHeadOffset = ((MechanicalPressTileEntity) te).getRenderedHeadOffset(partialTicks); - SuperByteBuffer headRender = AllBlockPartials.MECHANICAL_PRESS_HEAD.renderOnHorizontal(blockState); + SuperByteBuffer headRender = PartialBufferer.getHorizontal(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState); headRender.translate(0, -renderedHeadOffset, 0) - .light(packedLightmapCoords) - .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + .light(packedLightmapCoords) + .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java index fc9494feb..a3471f32a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; import net.minecraft.util.Rotation; public class SawInstance extends SingleRotatingInstance { @@ -22,7 +23,8 @@ public class SawInstance extends SingleRotatingInstance { protected InstancedModel getModel() { if (blockState.get(FACING).getAxis().isHorizontal()) { BlockState referenceState = blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180); - return AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), referenceState, referenceState.get(FACING)); + Direction facing = referenceState.get(FACING); + return getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, referenceState, facing); } else { return getRotatingMaterial().getModel(shaft()); } 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 473879dba..99c691fdb 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 @@ -9,6 +9,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; @@ -77,13 +78,13 @@ public class SawRenderer extends SafeTileEntityRenderer { if (!blockState.get(SawBlock.AXIS_ALONG_FIRST_COORDINATE)) MatrixStacker.of(ms) - .centre() - .rotateY(90) - .unCentre(); + .centre() + .rotateY(90) + .unCentre(); } - superBuffer = partial.renderOnDirectionalSouth(blockState); + superBuffer = PartialBufferer.getDirectionalSouth(partial, blockState); superBuffer.light(light) - .renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped())); + .renderInto(ms, buffer.getBuffer(RenderType.getCutoutMipped())); ms.pop(); } @@ -140,7 +141,7 @@ public class SawRenderer extends SafeTileEntityRenderer { protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { BlockState state = te.getBlockState(); if (state.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); + return PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, state.rotate(te.getWorld(), te.getPos(), Rotation.CLOCKWISE_180)); return CreateClient.bufferCache.renderBlockIn(KineticTileEntityRenderer.KINETIC_TILE, getRenderedBlockState(te)); } @@ -171,14 +172,14 @@ public class SawRenderer extends SafeTileEntityRenderer { if (SawBlock.isHorizontal(state)) { if (shouldAnimate) - superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE.renderOn(state); + superBuffer = PartialBufferer.get(AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE, state); else - superBuffer = AllBlockPartials.SAW_BLADE_HORIZONTAL_INACTIVE.renderOn(state); + superBuffer = PartialBufferer.get(AllBlockPartials.SAW_BLADE_HORIZONTAL_INACTIVE, state); } else { if (shouldAnimate) - superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE.renderOn(state); + superBuffer = PartialBufferer.get(AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE, state); else - superBuffer = AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE.renderOn(state); + superBuffer = PartialBufferer.get(AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE, state); } for (MatrixStack m : matrixStacks) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java index 6a81320bd..d176eccbb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AngleHelper; @@ -30,27 +31,27 @@ public class BearingRenderer extends KineticTileEntityRenderer { IBearingTileEntity bearingTe = (IBearingTileEntity) te; final Direction facing = te.getBlockState() - .get(BlockStateProperties.FACING); + .get(BlockStateProperties.FACING); AllBlockPartials top = - bearingTe.isWoodenTop() ? AllBlockPartials.BEARING_TOP_WOODEN : AllBlockPartials.BEARING_TOP; - SuperByteBuffer superBuffer = top.renderOn(te.getBlockState()); + bearingTe.isWoodenTop() ? AllBlockPartials.BEARING_TOP_WOODEN : AllBlockPartials.BEARING_TOP; + SuperByteBuffer superBuffer = PartialBufferer.get(top, te.getBlockState()); float interpolatedAngle = bearingTe.getInterpolatedAngle(partialTicks - 1); kineticRotationTransform(superBuffer, te, facing.getAxis(), (float) (interpolatedAngle / 180 * Math.PI), light); if (facing.getAxis() - .isHorizontal()) + .isHorizontal()) superBuffer.rotateCentered(Direction.UP, - AngleHelper.rad(AngleHelper.horizontalAngle(facing.getOpposite()))); + AngleHelper.rad(AngleHelper.horizontalAngle(facing.getOpposite()))); superBuffer.rotateCentered(Direction.EAST, AngleHelper.rad(-90 - AngleHelper.verticalAngle(facing))); superBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), te.getBlockState() - .get(BearingBlock.FACING) - .getOpposite()); + return PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, te.getBlockState(), te.getBlockState() + .get(BearingBlock.FACING) + .getOpposite()); } } 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 4db44925a..4cab614ba 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 @@ -12,6 +12,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Ori import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -35,7 +36,7 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { Direction facing = context.state.get(BlockStateProperties.FACING); AllBlockPartials top = AllBlockPartials.BEARING_TOP; - SuperByteBuffer superBuffer = top.renderOn(context.state); + SuperByteBuffer superBuffer = PartialBufferer.get(top, context.state); float renderPartialTicks = AnimationTickHolder.getPartialTicks(); // rotate to match blockstate diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java index 83679ee68..1abccec33 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.ch import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -28,7 +29,7 @@ public class StickerRenderer extends SafeTileEntityRenderer { if (FastRenderDispatcher.available(te.getWorld())) return; BlockState state = te.getBlockState(); - SuperByteBuffer head = AllBlockPartials.STICKER_HEAD.renderOn(state); + SuperByteBuffer head = PartialBufferer.get(AllBlockPartials.STICKER_HEAD, state); float offset = te.piston.getValue(AnimationTickHolder.getPartialTicks(te.getWorld())); if (te.getWorld() != Minecraft.getInstance().world && !te.isVirtual()) @@ -36,9 +37,9 @@ public class StickerRenderer extends SafeTileEntityRenderer { Direction facing = state.get(StickerBlock.FACING); head.matrixStacker() - .nudge(te.hashCode()) - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) + .nudge(te.hashCode()) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) .rotateX(AngleHelper.verticalAngle(facing) + 90) .unCentre() .translate(0, (offset * offset) * 4 / 16f, 0); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java index 8faa4f599..72152ff04 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AngleHelper; @@ -54,16 +55,16 @@ public class GantryCarriageRenderer extends KineticTileEntityRenderer { if (facing == Direction.NORTH || facing == Direction.EAST) angleForTe *= -1; - SuperByteBuffer cogs = AllBlockPartials.GANTRY_COGS.renderOn(state); + SuperByteBuffer cogs = PartialBufferer.get(AllBlockPartials.GANTRY_COGS, state); cogs.matrixStacker() - .centre() - .rotateY(AngleHelper.horizontalAngle(facing)) - .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) - .rotateY(alongFirst ^ facing.getAxis() == Axis.Z ? 90 : 0) - .translate(0, -9 / 16f, 0) - .multiply(Vector3f.POSITIVE_X.getRadialQuaternion(-angleForTe)) - .translate(0, 9 / 16f, 0) - .unCentre(); + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) + .rotateY(alongFirst ^ facing.getAxis() == Axis.Z ? 90 : 0) + .translate(0, -9 / 16f, 0) + .multiply(Vector3f.POSITIVE_X.getRadialQuaternion(-angleForTe)) + .translate(0, 9 / 16f, 0) + .unCentre(); cogs.light(light) .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java index f707114df..3a7a2b3ff 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AngleHelper; @@ -50,16 +51,16 @@ public abstract class AbstractPulleyRenderer extends KineticTileEntityRenderer { boolean running = isRunning(te); Axis rotationAxis = ((IRotate) te.getBlockState() - .getBlock()).getRotationAxis(te.getBlockState()); + .getBlock()).getRotationAxis(te.getBlockState()); kineticRotationTransform(getRotatedCoil(te), te, rotationAxis, AngleHelper.rad(offset * 180), light) - .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); World world = te.getWorld(); BlockState blockState = te.getBlockState(); BlockPos pos = te.getPos(); - SuperByteBuffer halfMagnet = this.halfMagnet.renderOn(blockState); - SuperByteBuffer halfRope = this.halfRope.renderOn(blockState); + SuperByteBuffer halfMagnet = PartialBufferer.get(this.halfMagnet, blockState); + SuperByteBuffer halfRope = PartialBufferer.get(this.halfRope, blockState); SuperByteBuffer magnet = renderMagnet(te); SuperByteBuffer rope = renderRope(te); @@ -106,8 +107,7 @@ public abstract class AbstractPulleyRenderer extends KineticTileEntityRenderer { protected SuperByteBuffer getRotatedCoil(KineticTileEntity te) { BlockState blockState = te.getBlockState(); - return getCoil().renderOnDirectionalSouth(blockState, - Direction.getFacingFromAxis(AxisDirection.POSITIVE, getShaftAxis(te))); + return PartialBufferer.getDirectionalSouth(getCoil(), blockState, Direction.getFacingFromAxis(AxisDirection.POSITIVE, getShaftAxis(te))); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java index 8003596b2..a1adb0e43 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java @@ -28,7 +28,7 @@ public class HosePulleyInstance extends AbstractPulleyInstance { } protected InstancedModel getCoilModel() { - return AllBlockPartials.HOSE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout); + return getOrientedMaterial().getModel(AllBlockPartials.HOSE_COIL, blockState, rotatingAbout); } protected InstancedModel getHalfRopeModel() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java index 8eb8388e4..a3bf2dd82 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java @@ -29,7 +29,7 @@ public class RopePulleyInstance extends AbstractPulleyInstance { } protected InstancedModel getCoilModel() { - return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout); + return getOrientedMaterial().getModel(AllBlockPartials.ROPE_COIL, blockState, rotatingAbout); } protected InstancedModel getHalfRopeModel() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java index 9b5544c1b..0a6edeb8d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/train/CouplingRenderer.java @@ -8,6 +8,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.CreateClient; import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; @@ -36,7 +37,7 @@ public class CouplingRenderer { c -> { if (c.getFirst().hasContraptionCoupling(true)) return; - CouplingRenderer.renderCoupling(ms, buffer, c.map(MinecartController::cart)); + CouplingRenderer.renderCoupling(ms, buffer, c.map(MinecartController::cart)); }); } @@ -47,37 +48,37 @@ public class CouplingRenderer { public static void renderCoupling(MatrixStack ms, IRenderTypeBuffer buffer, Couple carts) { ClientWorld world = Minecraft.getInstance().world; - + if (carts.getFirst() == null || carts.getSecond() == null) return; - + Couple lightValues = carts.map(c -> WorldRenderer.getLightmapCoordinates(world, new BlockPos(c.getBoundingBox() .getCenter()))); Vector3d center = carts.getFirst() - .getPositionVec() - .add(carts.getSecond() - .getPositionVec()) - .scale(.5f); + .getPositionVec() + .add(carts.getSecond() + .getPositionVec()) + .scale(.5f); Couple transforms = carts.map(c -> getSuitableCartEndpoint(c, center)); BlockState renderState = Blocks.AIR.getDefaultState(); IVertexBuilder builder = buffer.getBuffer(RenderType.getSolid()); - SuperByteBuffer attachment = AllBlockPartials.COUPLING_ATTACHMENT.renderOn(renderState); - SuperByteBuffer ring = AllBlockPartials.COUPLING_RING.renderOn(renderState); - SuperByteBuffer connector = AllBlockPartials.COUPLING_CONNECTOR.renderOn(renderState); + SuperByteBuffer attachment = PartialBufferer.get(AllBlockPartials.COUPLING_ATTACHMENT, renderState); + SuperByteBuffer ring = PartialBufferer.get(AllBlockPartials.COUPLING_RING, renderState); + SuperByteBuffer connector = PartialBufferer.get(AllBlockPartials.COUPLING_CONNECTOR, renderState); Vector3d zero = Vector3d.ZERO; Vector3d firstEndpoint = transforms.getFirst() - .apply(zero); + .apply(zero); Vector3d secondEndpoint = transforms.getSecond() - .apply(zero); + .apply(zero); Vector3d endPointDiff = secondEndpoint.subtract(firstEndpoint); double connectorYaw = -Math.atan2(endPointDiff.z, endPointDiff.x) * 180.0D / Math.PI; double connectorPitch = Math.atan2(endPointDiff.y, endPointDiff.mul(1, 0, 1) - .length()) * 180 / Math.PI; + .length()) * 180 / Math.PI; MatrixStacker msr = MatrixStacker.of(ms); carts.forEachWithContext((cart, isFirst) -> { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java index 202a93992..470b5ab4e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -10,6 +10,7 @@ import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; public class PumpCogInstance extends SingleRotatingInstance { @@ -19,7 +20,8 @@ public class PumpCogInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - BlockState referenceState = tile.getBlockState(); - return AllBlockPartials.MECHANICAL_PUMP_COG.getModel(getRotatingMaterial(), referenceState, referenceState.get(FACING)); - } + BlockState referenceState = tile.getBlockState(); + Direction facing = referenceState.get(FACING); + return getRotatingMaterial().getModel(AllBlockPartials.MECHANICAL_PUMP_COG, referenceState, facing); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java index d8dd29f3d..b26a6d5a1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -34,17 +35,17 @@ public class PumpRenderer extends KineticTileEntityRenderer { float angle = MathHelper.lerp(pump.arrowDirection.getValue(partialTicks), 0, 90) - 90; for (float yRot : new float[] { 0, 90 }) { ms.push(); - SuperByteBuffer arrow = AllBlockPartials.MECHANICAL_PUMP_ARROW.renderOn(blockState); + SuperByteBuffer arrow = PartialBufferer.get(AllBlockPartials.MECHANICAL_PUMP_ARROW, blockState); Direction direction = blockState.get(PumpBlock.FACING); MatrixStacker.of(ms) - .centre() - .rotateY(AngleHelper.horizontalAngle(direction) + 180) - .rotateX(-AngleHelper.verticalAngle(direction) - 90) - .unCentre() - .translate(rotationOffset) - .rotateY(yRot) - .rotateZ(angle) - .translateBack(rotationOffset); + .centre() + .rotateY(AngleHelper.horizontalAngle(direction) + 180) + .rotateX(-AngleHelper.verticalAngle(direction) - 90) + .unCentre() + .translate(rotationOffset) + .rotateY(yRot) + .rotateZ(angle) + .translateBack(rotationOffset); arrow.light(light).renderInto(ms, buffer.getBuffer(RenderType.getSolid())); ms.pop(); } @@ -52,7 +53,7 @@ public class PumpRenderer extends KineticTileEntityRenderer { @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouth(te.getBlockState()); + return PartialBufferer.getDirectionalSouth(AllBlockPartials.MECHANICAL_PUMP_COG, te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java index c0d4091c6..d73652919 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.fluids.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.pulley.AbstractPulleyRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; @@ -29,12 +30,12 @@ public class HosePulleyRenderer extends AbstractPulleyRenderer { @Override protected SuperByteBuffer renderRope(KineticTileEntity te) { - return AllBlockPartials.HOSE.renderOn(te.getBlockState()); + return PartialBufferer.get(AllBlockPartials.HOSE, te.getBlockState()); } @Override protected SuperByteBuffer renderMagnet(KineticTileEntity te) { - return AllBlockPartials.HOSE_MAGNET.renderOn(te.getBlockState()); + return PartialBufferer.get(AllBlockPartials.HOSE_MAGNET, te.getBlockState()); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutRenderer.java index cc4eaa7a4..f4364a14e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/SpoutRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.fluids.actors; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.fluid.FluidRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour.TankSegment; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -70,9 +71,9 @@ public class SpoutRenderer extends SafeTileEntityRenderer { ms.push(); for (AllBlockPartials bit : BITS) { - bit.renderOn(te.getBlockState()) - .light(light) - .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); + PartialBufferer.get(bit, te.getBlockState()) + .light(light) + .renderInto(ms, buffer.getBuffer(RenderType.getSolid())); ms.translate(0, -3 * squeeze / 32f, 0); } ms.pop(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java index 14439f84a..3d3a02951 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AngleHelper; @@ -31,7 +32,7 @@ public class FluidValveRenderer extends KineticTileEntityRenderer { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); BlockState blockState = te.getBlockState(); - SuperByteBuffer pointer = AllBlockPartials.FLUID_VALVE_POINTER.renderOn(blockState); + SuperByteBuffer pointer = PartialBufferer.get(AllBlockPartials.FLUID_VALVE_POINTER, blockState); Direction facing = blockState.get(FluidValveBlock.FACING); if (!(te instanceof FluidValveTileEntity)) diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java index df11ef484..c12ce5b23 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.processing.burner; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; @@ -31,10 +32,10 @@ public class BlazeBurnerRenderer extends SafeTileEntityRenderer { AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - SuperByteBuffer beltBuffer = beltPartial.renderOn(blockState) - .light(light); + SuperByteBuffer beltBuffer = PartialBufferer.get(beltPartial, blockState) + .light(light); SpriteShiftEntry spriteShift = getSpriteShiftEntry(color, diagonal, bottom); @@ -127,18 +129,20 @@ public class BeltRenderer extends SafeTileEntityRenderer { } if (te.hasPulley()) { - // TODO 1.15 find a way to cache this model matrix computation - MatrixStack modelTransform = new MatrixStack(); - Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING).rotateY(); - if (sideways) dir = Direction.UP; - msr = MatrixStacker.of(modelTransform); - msr.centre(); - if (dir.getAxis() == Axis.X) msr.rotateY(90); - if (dir.getAxis() == Axis.Y) msr.rotateX(90); - msr.rotateX(90); - msr.unCentre(); + Direction dir = sideways ? Direction.UP : blockState.get(BeltBlock.HORIZONTAL_FACING).rotateY(); - SuperByteBuffer superBuffer = CreateClient.bufferCache.renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, modelTransform); + Supplier matrixStackSupplier = () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker stacker = MatrixStacker.of(stack); + stacker.centre(); + if (dir.getAxis() == Axis.X) stacker.rotateY(90); + if (dir.getAxis() == Axis.Y) stacker.rotateX(90); + stacker.rotateX(90); + stacker.unCentre(); + return stack; + }; + + SuperByteBuffer superBuffer = CreateClient.bufferCache.renderDirectionalPartial(AllBlockPartials.BELT_PULLEY, blockState, dir, matrixStackSupplier); KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 92eab7077..f317fd24d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -30,12 +30,12 @@ public class SplitShaftInstance extends KineticTileInstance half = AllBlockPartials.SHAFT_HALF.getModel(rotatingMaterial, blockState, dir); + InstancedModel half = rotatingMaterial.getModel(AllBlockPartials.SHAFT_HALF, blockState, dir); - float splitSpeed = speed * tile.getRotationSpeedModifier(dir); + float splitSpeed = speed * tile.getRotationSpeedModifier(dir); - keys.add(setup(half.createInstance(), splitSpeed)); - } + keys.add(setup(half.createInstance(), splitSpeed)); + } } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java index a1cf575af..4e35c6bdc 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftRenderer.java @@ -5,6 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -51,7 +52,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer { angle = angle / 180f * (float) Math.PI; SuperByteBuffer superByteBuffer = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); + PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction); kineticRotationTransform(superByteBuffer, te, axis, angle, light); superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java index bc89519bb..5a1d37e39 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.gauge.GaugeBlock.Type; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.Iterate; @@ -25,11 +26,11 @@ public class GaugeRenderer extends KineticTileEntityRenderer { public static GaugeRenderer speed(TileEntityRendererDispatcher dispatcher) { return new GaugeRenderer(dispatcher, Type.SPEED); } - + public static GaugeRenderer stress(TileEntityRendererDispatcher dispatcher) { return new GaugeRenderer(dispatcher, Type.STRESS); } - + protected GaugeRenderer(TileEntityRendererDispatcher dispatcher, GaugeBlock.Type type) { super(dispatcher); this.type = type; @@ -45,17 +46,17 @@ public class GaugeRenderer extends KineticTileEntityRenderer { GaugeTileEntity gaugeTE = (GaugeTileEntity) te; int lightCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), gaugeState, te.getPos()); + AllBlockPartials allBlockPartials = (type == Type.SPEED ? AllBlockPartials.GAUGE_HEAD_SPEED : AllBlockPartials.GAUGE_HEAD_STRESS); SuperByteBuffer headBuffer = - (type == Type.SPEED ? AllBlockPartials.GAUGE_HEAD_SPEED : AllBlockPartials.GAUGE_HEAD_STRESS) - .renderOn(gaugeState); - SuperByteBuffer dialBuffer = AllBlockPartials.GAUGE_DIAL.renderOn(gaugeState); + PartialBufferer.get(allBlockPartials, gaugeState); + SuperByteBuffer dialBuffer = PartialBufferer.get(AllBlockPartials.GAUGE_DIAL, gaugeState); float dialPivot = 5.75f / 16; float progress = MathHelper.lerp(partialTicks, gaugeTE.prevDialState, gaugeTE.dialState); for (Direction facing : Iterate.directions) { if (!((GaugeBlock) gaugeState.getBlock()).shouldRenderHeadOnFace(te.getWorld(), te.getPos(), gaugeState, - facing)) + facing)) continue; IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index 62a2cd6b2..a991802fa 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -36,20 +36,20 @@ public class GearboxInstance extends KineticTileInstance { RenderMaterial> rotatingMaterial = getRotatingMaterial(); for (Direction direction : Iterate.directions) { - final Direction.Axis axis = direction.getAxis(); - if (boxAxis == axis) - continue; + final Direction.Axis axis = direction.getAxis(); + if (boxAxis == axis) + continue; - InstancedModel shaft = AllBlockPartials.SHAFT_HALF.getModel(rotatingMaterial, blockState, direction); + InstancedModel shaft = rotatingMaterial.getModel(AllBlockPartials.SHAFT_HALF, blockState, direction); - RotatingData key = shaft.createInstance(); + RotatingData key = shaft.createInstance(); - key.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffset(axis)).setColor(tile) - .setPosition(getInstancePosition()) - .setBlockLight(blockLight) - .setSkyLight(skyLight); + key.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setRotationalSpeed(getSpeed(direction)) + .setRotationOffset(getRotationOffset(axis)).setColor(tile) + .setPosition(getInstancePosition()) + .setBlockLight(blockLight) + .setSkyLight(skyLight); keys.put(direction, key); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java index 45463f007..78a1206a9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -37,7 +38,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer { if (boxAxis == axis) continue; - SuperByteBuffer shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouth(te.getBlockState(), direction); + SuperByteBuffer shaft = PartialBufferer.getDirectionalSouth(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction); float offset = getRotationOffsetForPosition(te, pos, axis); float angle = (time * te.getSpeed() * 3f / 10) % 360; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java index f82be3bb1..49252ec37 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.logistics.block.belts.tunnel; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer; @@ -32,7 +33,7 @@ public class BeltTunnelRenderer extends SmartTileEntityRenderer { BlockState blockState = te.getBlockState(); IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid()); - SuperByteBuffer flapBuffer = (blockState.getBlock() instanceof FunnelBlock ? AllBlockPartials.FUNNEL_FLAP - : AllBlockPartials.BELT_FUNNEL_FLAP).renderOn(blockState); + AllBlockPartials allBlockPartials = (blockState.getBlock() instanceof FunnelBlock ? AllBlockPartials.FUNNEL_FLAP + : AllBlockPartials.BELT_FUNNEL_FLAP); + SuperByteBuffer flapBuffer = PartialBufferer.get(allBlockPartials, blockState); Vector3d pivot = VecHelper.voxelSpace(0, 10, 9.5f); MatrixStacker msr = MatrixStacker.of(ms); float horizontalAngle = AngleHelper.horizontalAngle(FunnelBlock.getFunnelFacing(blockState) - .getOpposite()); + .getOpposite()); float f = te.flap.get(partialTicks); ms.push(); msr.centre() - .rotateY(horizontalAngle) + .rotateY(horizontalAngle) .unCentre(); ms.translate(0, 0, -te.getFlapOffset()); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java index 6553f676c..2a9a72ac3 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmRenderer.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -66,7 +67,7 @@ public class ArmRenderer extends KineticTileEntityRenderer { float lowerArmAngle = arm.lowerArmAngle.get(pt) - 135; float upperArmAngle = arm.upperArmAngle.get(pt) - 90; float headAngle = arm.headAngle.get(pt); - + boolean rave = arm.phase == Phase.DANCING; float renderTick = AnimationTickHolder.getRenderTime(te.getWorld()) + (te.hashCode() % 64); if (rave) { @@ -104,21 +105,21 @@ public class ArmRenderer extends KineticTileEntityRenderer { } private void renderArm(IVertexBuilder builder, MatrixStack ms, MatrixStack msLocal, MatrixStacker msr, BlockState blockState, int color, float baseAngle, float lowerArmAngle, float upperArmAngle, float headAngle, boolean hasItem, boolean isBlockItem, int light) { - SuperByteBuffer base = AllBlockPartials.ARM_BASE.renderOn(blockState).light(light); - SuperByteBuffer lowerBody = AllBlockPartials.ARM_LOWER_BODY.renderOn(blockState).light(light); - SuperByteBuffer upperBody = AllBlockPartials.ARM_UPPER_BODY.renderOn(blockState).light(light); - SuperByteBuffer head = AllBlockPartials.ARM_HEAD.renderOn(blockState).light(light); - SuperByteBuffer claw = AllBlockPartials.ARM_CLAW_BASE.renderOn(blockState).light(light); - SuperByteBuffer clawGrip = AllBlockPartials.ARM_CLAW_GRIP.renderOn(blockState); + SuperByteBuffer base = PartialBufferer.get(AllBlockPartials.ARM_BASE, blockState).light(light); + SuperByteBuffer lowerBody = PartialBufferer.get(AllBlockPartials.ARM_LOWER_BODY, blockState).light(light); + SuperByteBuffer upperBody = PartialBufferer.get(AllBlockPartials.ARM_UPPER_BODY, blockState).light(light); + SuperByteBuffer head = PartialBufferer.get(AllBlockPartials.ARM_HEAD, blockState).light(light); + SuperByteBuffer claw = PartialBufferer.get(AllBlockPartials.ARM_CLAW_BASE, blockState).light(light); + SuperByteBuffer clawGrip = PartialBufferer.get(AllBlockPartials.ARM_CLAW_GRIP, blockState); transformBase(msr, baseAngle); base.transform(msLocal) - .renderInto(ms, builder); + .renderInto(ms, builder); transformLowerArm(msr, lowerArmAngle); lowerBody.color(color) - .transform(msLocal) - .renderInto(ms, builder); + .transform(msLocal) + .renderInto(ms, builder); transformUpperArm(msr, upperArmAngle); upperBody.color(color) @@ -182,7 +183,7 @@ public class ArmRenderer extends KineticTileEntityRenderer { @Override protected SuperByteBuffer getRotatedModel(KineticTileEntity te) { - return AllBlockPartials.ARM_COG.renderOn(te.getBlockState()); + return PartialBufferer.get(AllBlockPartials.ARM_COG, te.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java index cbde2d0e5..329760ede 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.logistics.block.redstone; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.PartialBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -36,20 +37,20 @@ public class AnalogLeverRenderer extends SafeTileEntityRenderer ms = () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) + .unCentre(); + + return stack; + }; + return CreateClient.bufferCache.renderDirectionalPartial(partial, referenceState, facing, ms); + } + + public static Supplier rotateToFace(Direction facing) { + return () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return stack; + }; + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java index 93407bc6b..2293037d2 100644 --- a/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java +++ b/src/main/java/com/simibubi/create/foundation/render/SuperByteBufferCache.java @@ -46,9 +46,9 @@ public class SuperByteBufferCache { } public SuperByteBuffer renderPartial(AllBlockPartials partial, BlockState referenceState, - MatrixStack modelTransform) { + Supplier modelTransform) { return get(Compartment.PARTIAL, partial, - () -> standardModelRender(partial.get(), referenceState, modelTransform)); + () -> standardModelRender(partial.get(), referenceState, modelTransform.get())); } public SuperByteBuffer renderDirectionalPartial(AllBlockPartials partial, BlockState referenceState, @@ -58,9 +58,9 @@ public class SuperByteBufferCache { } public SuperByteBuffer renderDirectionalPartial(AllBlockPartials partial, BlockState referenceState, Direction dir, - MatrixStack modelTransform) { + Supplier modelTransform) { return get(Compartment.DIRECTIONAL_PARTIAL, Pair.of(dir, partial), - () -> standardModelRender(partial.get(), referenceState, modelTransform)); + () -> standardModelRender(partial.get(), referenceState, modelTransform.get())); } public SuperByteBuffer renderBlockIn(Compartment compartment, BlockState toRender) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java index f2f3e1bc7..f383bad97 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java @@ -22,6 +22,8 @@ import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderCallback; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -104,8 +106,7 @@ public class RenderMaterial

buildModel(partial.get(), referenceState)); + return getModel(partial, referenceState, dir, rotateToFace(dir)); } public MODEL getModel(AllBlockPartials partial, BlockState referenceState, Direction dir, Supplier modelTransform) { @@ -132,14 +133,25 @@ public class RenderMaterial

rotateToFace(Direction facing) { + return () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return stack; + }; + } }