diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index cbeb1f51b..9a6671797 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -122,10 +122,7 @@ import com.simibubi.create.content.logistics.block.chute.ChuteRenderer; import com.simibubi.create.content.logistics.block.chute.ChuteTileEntity; import com.simibubi.create.content.logistics.block.chute.SmartChuteRenderer; import com.simibubi.create.content.logistics.block.chute.SmartChuteTileEntity; -import com.simibubi.create.content.logistics.block.depot.DepotRenderer; -import com.simibubi.create.content.logistics.block.depot.DepotTileEntity; -import com.simibubi.create.content.logistics.block.depot.EjectorRenderer; -import com.simibubi.create.content.logistics.block.depot.EjectorTileEntity; +import com.simibubi.create.content.logistics.block.depot.*; import com.simibubi.create.content.logistics.block.diodes.AdjustablePulseRepeaterTileEntity; import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterInstance; import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterRenderer; @@ -617,7 +614,7 @@ public class AllTileEntities { public static final TileEntityEntry WEIGHTED_EJECTOR = Create.registrate() .tileEntity("weighted_ejector", EjectorTileEntity::new) - .instance(() -> ShaftInstance::new) + .instance(() -> EjectorInstance::new) .validBlocks(AllBlocks.WEIGHTED_EJECTOR) .renderer(() -> EjectorRenderer::new) .register(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java new file mode 100644 index 000000000..bb269009c --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java @@ -0,0 +1,60 @@ +package com.simibubi.create.content.logistics.block.depot; + +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.relays.encased.ShaftInstance; +import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; +import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.MatrixStacker; + +public class EjectorInstance extends ShaftInstance implements IDynamicInstance { + + protected final EjectorTileEntity tile; + + protected final InstanceKey plate; + + public EjectorInstance(InstancedTileRenderer dispatcher, EjectorTileEntity tile) { + super(dispatcher, tile); + this.tile = tile; + + plate = getTransformMaterial().getModel(AllBlockPartials.EJECTOR_TOP, blockState).createInstance(); + + pivotPlate(); + updateLight(); + } + + @Override + public void beginFrame() { + + if (tile.lidProgress.settled()) return; + + pivotPlate(); + } + + private void pivotPlate() { + float lidProgress = tile.getLidProgress(AnimationTickHolder.getPartialTicks()); + float angle = lidProgress * 70; + + MatrixStack ms = new MatrixStack(); + + EjectorRenderer.applyLidAngle(tile, angle, MatrixStacker.of(ms).translate(getInstancePosition())); + + plate.getInstance().setTransform(ms); + } + + @Override + public void updateLight() { + super.updateLight(); + relight(pos, plate.getInstance()); + } + + @Override + public void remove() { + super.remove(); + plate.delete(); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java index 1d0438af6..29eaeb995 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorRenderer.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.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.IntAttached; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -22,6 +23,8 @@ import net.minecraft.util.math.Vec3d; public class EjectorRenderer extends KineticTileEntityRenderer { + static final Vec3d pivot = VecHelper.voxelSpace(0, 11.25, 0.75); + public EjectorRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); } @@ -37,15 +40,16 @@ public class EjectorRenderer extends KineticTileEntityRenderer { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); EjectorTileEntity ejector = (EjectorTileEntity) te; - SuperByteBuffer model = AllBlockPartials.EJECTOR_TOP.renderOn(te.getBlockState()); IVertexBuilder vertexBuilder = buffer.getBuffer(RenderType.getSolid()); - Vec3d rotationOffset = VecHelper.voxelSpace(0, 11.25, 0.75); float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks); float angle = lidProgress * 70; - applyLidAngle(te, rotationOffset, angle, model.matrixStacker()); - model.light(light) - .renderInto(ms, vertexBuilder); + if (!FastRenderDispatcher.available(te.getWorld())) { + SuperByteBuffer model = AllBlockPartials.EJECTOR_TOP.renderOn(te.getBlockState()); + applyLidAngle(te, angle, model.matrixStacker()); + model.light(light) + .renderInto(ms, vertexBuilder); + } MatrixStacker msr = MatrixStacker.of(ms); @@ -70,7 +74,7 @@ public class EjectorRenderer extends KineticTileEntityRenderer { return; ms.push(); - applyLidAngle(te, rotationOffset, angle, msr); + applyLidAngle(te, angle, msr); msr.centre() .rotateY(-180 - AngleHelper.horizontalAngle(te.getBlockState() .get(EjectorBlock.HORIZONTAL_FACING))) @@ -79,7 +83,11 @@ public class EjectorRenderer extends KineticTileEntityRenderer { ms.pop(); } - protected void applyLidAngle(KineticTileEntity te, Vec3d rotationOffset, float angle, MatrixStacker matrixStacker) { + static void applyLidAngle(KineticTileEntity te, float angle, MatrixStacker matrixStacker) { + applyLidAngle(te, pivot, angle, matrixStacker); + } + + static void applyLidAngle(KineticTileEntity te, Vec3d rotationOffset, float angle, MatrixStacker matrixStacker) { matrixStacker.centre() .rotateY(180 + AngleHelper.horizontalAngle(te.getBlockState() .get(EjectorBlock.HORIZONTAL_FACING))) diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/BehaviourType.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/BehaviourType.java index 8b3f90827..d9fc571a8 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/BehaviourType.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/BehaviourType.java @@ -18,4 +18,8 @@ public class BehaviourType { return name; } + @Override + public int hashCode() { + return super.hashCode() * 31 * 493286711; // Better hash table distribution + } }