Instanced Ejectors and better hashing for BehaviourTypes.

This commit is contained in:
JozsefA 2021-03-25 21:27:08 -07:00
parent 718142e26f
commit 1d2b51250c
4 changed files with 81 additions and 12 deletions

View File

@ -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.ChuteTileEntity;
import com.simibubi.create.content.logistics.block.chute.SmartChuteRenderer; 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.chute.SmartChuteTileEntity;
import com.simibubi.create.content.logistics.block.depot.DepotRenderer; import com.simibubi.create.content.logistics.block.depot.*;
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.diodes.AdjustablePulseRepeaterTileEntity; 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.AdjustableRepeaterInstance;
import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterRenderer; import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterRenderer;
@ -617,7 +614,7 @@ public class AllTileEntities {
public static final TileEntityEntry<EjectorTileEntity> WEIGHTED_EJECTOR = Create.registrate() public static final TileEntityEntry<EjectorTileEntity> WEIGHTED_EJECTOR = Create.registrate()
.tileEntity("weighted_ejector", EjectorTileEntity::new) .tileEntity("weighted_ejector", EjectorTileEntity::new)
.instance(() -> ShaftInstance::new) .instance(() -> EjectorInstance::new)
.validBlocks(AllBlocks.WEIGHTED_EJECTOR) .validBlocks(AllBlocks.WEIGHTED_EJECTOR)
.renderer(() -> EjectorRenderer::new) .renderer(() -> EjectorRenderer::new)
.register(); .register();

View File

@ -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<ModelData> 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();
}
}

View File

@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.foundation.render.SuperByteBuffer; 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.AngleHelper;
import com.simibubi.create.foundation.utility.IntAttached; import com.simibubi.create.foundation.utility.IntAttached;
import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.MatrixStacker;
@ -22,6 +23,8 @@ import net.minecraft.util.math.Vec3d;
public class EjectorRenderer extends KineticTileEntityRenderer { public class EjectorRenderer extends KineticTileEntityRenderer {
static final Vec3d pivot = VecHelper.voxelSpace(0, 11.25, 0.75);
public EjectorRenderer(TileEntityRendererDispatcher dispatcher) { public EjectorRenderer(TileEntityRendererDispatcher dispatcher) {
super(dispatcher); super(dispatcher);
} }
@ -37,15 +40,16 @@ public class EjectorRenderer extends KineticTileEntityRenderer {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay); super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
EjectorTileEntity ejector = (EjectorTileEntity) te; EjectorTileEntity ejector = (EjectorTileEntity) te;
SuperByteBuffer model = AllBlockPartials.EJECTOR_TOP.renderOn(te.getBlockState());
IVertexBuilder vertexBuilder = buffer.getBuffer(RenderType.getSolid()); IVertexBuilder vertexBuilder = buffer.getBuffer(RenderType.getSolid());
Vec3d rotationOffset = VecHelper.voxelSpace(0, 11.25, 0.75);
float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks); float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks);
float angle = lidProgress * 70; float angle = lidProgress * 70;
applyLidAngle(te, rotationOffset, angle, model.matrixStacker()); if (!FastRenderDispatcher.available(te.getWorld())) {
model.light(light) SuperByteBuffer model = AllBlockPartials.EJECTOR_TOP.renderOn(te.getBlockState());
.renderInto(ms, vertexBuilder); applyLidAngle(te, angle, model.matrixStacker());
model.light(light)
.renderInto(ms, vertexBuilder);
}
MatrixStacker msr = MatrixStacker.of(ms); MatrixStacker msr = MatrixStacker.of(ms);
@ -70,7 +74,7 @@ public class EjectorRenderer extends KineticTileEntityRenderer {
return; return;
ms.push(); ms.push();
applyLidAngle(te, rotationOffset, angle, msr); applyLidAngle(te, angle, msr);
msr.centre() msr.centre()
.rotateY(-180 - AngleHelper.horizontalAngle(te.getBlockState() .rotateY(-180 - AngleHelper.horizontalAngle(te.getBlockState()
.get(EjectorBlock.HORIZONTAL_FACING))) .get(EjectorBlock.HORIZONTAL_FACING)))
@ -79,7 +83,11 @@ public class EjectorRenderer extends KineticTileEntityRenderer {
ms.pop(); 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() matrixStacker.centre()
.rotateY(180 + AngleHelper.horizontalAngle(te.getBlockState() .rotateY(180 + AngleHelper.horizontalAngle(te.getBlockState()
.get(EjectorBlock.HORIZONTAL_FACING))) .get(EjectorBlock.HORIZONTAL_FACING)))

View File

@ -18,4 +18,8 @@ public class BehaviourType<T extends TileEntityBehaviour> {
return name; return name;
} }
@Override
public int hashCode() {
return super.hashCode() * 31 * 493286711; // Better hash table distribution
}
} }