From e690f2b8ac9e8fa1325b17487ce78276c13182fe Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 27 Jan 2021 14:03:18 -0800 Subject: [PATCH] okay you can use it now fixed a lighting bug (with a hack, again) everything now uses the new api (kinetic components on contraptions are slightly broken) --- .../com/simibubi/create/AllBlockPartials.java | 10 +- .../com/simibubi/create/AllTileEntities.java | 32 +++-- .../com/simibubi/create/CreateClient.java | 6 +- .../base/BackHalfShaftInstance.java | 9 +- .../contraptions/base/HalfShaftInstance.java | 9 +- .../base/HorizontalHalfShaftInstance.java | 9 +- .../contraptions/base/KineticTileEntity.java | 4 +- .../base/KineticTileEntityRenderer.java | 5 +- .../base/KineticTileInstance.java | 35 ++---- .../base/ShaftlessCogInstance.java | 9 +- .../base/SingleRotatingInstance.java | 15 ++- .../components/actors/DrillInstance.java | 10 +- .../crafter/MechanicalCrafterInstance.java | 46 +++++++ .../components/deployer/DeployerRenderer.java | 5 +- .../components/fan/FanInstance.java | 117 ++++++++++++++++++ .../millstone/MillStoneCogInstance.java | 10 +- .../press/MechanicalPressRenderer.java | 5 + .../components/saw/SawInstance.java | 35 ++++++ .../components/saw/SawRenderer.java | 5 +- .../contraptions/fluids/PumpCogInstance.java | 9 +- .../advanced/SpeedControllerRenderer.java | 5 +- .../relays/belt/BeltInstance.java | 13 +- .../relays/belt/BeltRenderer.java | 9 +- ...gShaftInstance.java => ShaftInstance.java} | 13 +- .../relays/encased/SplitShaftInstance.java | 11 +- .../relays/gearbox/GearboxInstance.java | 13 +- .../block/mechanicalArm/ArmInstance.java | 13 +- .../simibubi/create/events/ClientEvents.java | 1 + .../foundation/mixin/OnRemoveTileMixin.java | 32 +++++ .../render/FastRenderDispatcher.java | 37 +++--- ...atcher.java => InstancedTileRenderer.java} | 26 ++-- .../ContraptionKineticRenderer.java | 4 +- .../contraption/RenderedContraption.java | 14 +-- .../IInstancedTileEntityRenderer.java | 10 -- .../render/instancing/IRendererFactory.java | 4 +- .../render/instancing/InstanceContext.java | 27 +--- .../render/instancing/InstancedModel.java | 5 +- .../InstancedTileRenderRegistry.java | 4 +- .../render/instancing/TileEntityInstance.java | 14 ++- .../foundation/render/light/LightVolume.java | 10 +- src/main/resources/create.mixins.json | 2 +- 41 files changed, 431 insertions(+), 221 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java rename src/main/java/com/simibubi/create/content/contraptions/relays/encased/{SingleRotatingShaftInstance.java => ShaftInstance.java} (61%) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java rename src/main/java/com/simibubi/create/foundation/render/{InstancedTileRenderDispatcher.java => InstancedTileRenderer.java} (77%) delete mode 100644 src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java diff --git a/src/main/java/com/simibubi/create/AllBlockPartials.java b/src/main/java/com/simibubi/create/AllBlockPartials.java index bc0c28e66..d156c584b 100644 --- a/src/main/java/com/simibubi/create/AllBlockPartials.java +++ b/src/main/java/com/simibubi/create/AllBlockPartials.java @@ -5,7 +5,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes; import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.AngleHelper; @@ -227,7 +227,7 @@ public class AllBlockPartials { return ctx.getRotating().getModel(this, referenceState); } - public InstancedModel renderOnRotating(InstancedTileRenderDispatcher ctx, BlockState referenceState) { + public InstancedModel renderOnRotating(InstancedTileRenderer ctx, BlockState referenceState) { return ctx.get(KineticRenderMaterials.ROTATING).getModel(this, referenceState); } @@ -236,7 +236,7 @@ public class AllBlockPartials { return ctx.getBelts().getModel(this, referenceState); } - public InstancedModel renderOnBelt(InstancedTileRenderDispatcher ctx, BlockState referenceState) { + public InstancedModel renderOnBelt(InstancedTileRenderer ctx, BlockState referenceState) { return ctx.get(KineticRenderMaterials.BELTS).getModel(this, referenceState); } @@ -246,7 +246,7 @@ public class AllBlockPartials { return renderOnDirectionalSouthRotating(ctx, referenceState, facing); } - public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderDispatcher dispatcher, BlockState referenceState) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState) { Direction facing = referenceState.get(FACING); return renderOnDirectionalSouthRotating(dispatcher, referenceState, facing); } @@ -256,7 +256,7 @@ public class AllBlockPartials { return renderOnDirectionalSouthRotating(ctx.getKinetics(), referenceState, facing); } - public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderDispatcher dispatcher, BlockState referenceState, Direction facing) { + public InstancedModel renderOnDirectionalSouthRotating(InstancedTileRenderer dispatcher, BlockState referenceState, Direction facing) { Supplier ms = () -> { MatrixStack stack = new MatrixStack(); MatrixStacker.of(stack) diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 8900b34c5..8fb212476 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -4,6 +4,7 @@ import com.simibubi.create.content.contraptions.base.*; import com.simibubi.create.content.contraptions.components.actors.*; import com.simibubi.create.content.contraptions.components.clock.CuckooClockRenderer; import com.simibubi.create.content.contraptions.components.clock.CuckooClockTileEntity; +import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterInstance; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterRenderer; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity; import com.simibubi.create.content.contraptions.components.crank.HandCrankRenderer; @@ -14,6 +15,7 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerRend import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity; import com.simibubi.create.content.contraptions.components.fan.EncasedFanRenderer; import com.simibubi.create.content.contraptions.components.fan.EncasedFanTileEntity; +import com.simibubi.create.content.contraptions.components.fan.FanInstance; import com.simibubi.create.content.contraptions.components.fan.NozzleTileEntity; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; @@ -28,6 +30,7 @@ import com.simibubi.create.content.contraptions.components.motor.CreativeMotorRe import com.simibubi.create.content.contraptions.components.motor.CreativeMotorTileEntity; import com.simibubi.create.content.contraptions.components.press.MechanicalPressRenderer; import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity; +import com.simibubi.create.content.contraptions.components.saw.SawInstance; import com.simibubi.create.content.contraptions.components.saw.SawRenderer; import com.simibubi.create.content.contraptions.components.saw.SawTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.BearingRenderer; @@ -133,20 +136,21 @@ public class AllTileEntities { .tileEntity("encased_shaft", EncasedShaftTileEntity::new) .validBlocks(AllBlocks.ANDESITE_ENCASED_SHAFT, AllBlocks.BRASS_ENCASED_SHAFT, AllBlocks.ENCASED_CHAIN_DRIVE) .renderer(() -> EncasedShaftRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ADJUSTABLE_PULLEY = Create.registrate() .tileEntity("adjustable_pulley", AdjustablePulleyTileEntity::new) .validBlocks(AllBlocks.ADJUSTABLE_CHAIN_GEARSHIFT) .renderer(() -> EncasedShaftRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ENCASED_FAN = Create.registrate() .tileEntity("encased_fan", EncasedFanTileEntity::new) .validBlocks(AllBlocks.ENCASED_FAN) .renderer(() -> EncasedFanRenderer::new) + .onRegister(FanInstance::register) .register(); public static final TileEntityEntry NOZZLE = Create.registrate() @@ -173,6 +177,7 @@ public class AllTileEntities { .tileEntity("turntable", TurntableTileEntity::new) .validBlocks(AllBlocks.TURNTABLE) .renderer(() -> KineticTileEntityRenderer::new) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry HAND_CRANK = Create.registrate() @@ -180,7 +185,7 @@ public class AllTileEntities { .validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE) .validBlocks(AllBlocks.DYED_VALVE_HANDLES) .renderer(() -> HandCrankRenderer::new) - .onRegister(BackHalfShaftInstance::register) + .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry CUCKOO_CLOCK = Create.registrate() @@ -223,7 +228,7 @@ public class AllTileEntities { .tileEntity("fluid_valve", FluidValveTileEntity::new) .validBlocks(AllBlocks.FLUID_VALVE) .renderer(() -> FluidValveRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry FLUID_TANK = Create.registrate() @@ -242,7 +247,7 @@ public class AllTileEntities { .tileEntity("hose_pulley", HosePulleyTileEntity::new) .validBlocks(AllBlocks.HOSE_PULLEY) .renderer(() -> HosePulleyRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry SPOUT = Create.registrate() @@ -293,7 +298,7 @@ public class AllTileEntities { .tileEntity("mechanical_piston", MechanicalPistonTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PISTON, AllBlocks.STICKY_MECHANICAL_PISTON) .renderer(() -> MechanicalPistonRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry WINDMILL_BEARING = Create.registrate() @@ -321,7 +326,7 @@ public class AllTileEntities { .tileEntity("rope_pulley", PulleyTileEntity::new) .validBlocks(AllBlocks.ROPE_PULLEY) .renderer(() -> PulleyRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry CHASSIS = Create.registrate() @@ -341,6 +346,7 @@ public class AllTileEntities { .tileEntity("saw", SawTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_SAW) .renderer(() -> SawRenderer::new) + .onRegister(SawInstance::register) .register(); public static final TileEntityEntry HARVESTER = Create.registrate() @@ -407,7 +413,7 @@ public class AllTileEntities { .tileEntity("mechanical_press", MechanicalPressTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_PRESS) .renderer(() -> MechanicalPressRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_MIXER = Create.registrate() @@ -421,7 +427,7 @@ public class AllTileEntities { .tileEntity("deployer", DeployerTileEntity::new) .validBlocks(AllBlocks.DEPLOYER) .renderer(() -> DeployerRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry BASIN = Create.registrate() @@ -440,7 +446,7 @@ public class AllTileEntities { .tileEntity("mechanical_crafter", MechanicalCrafterTileEntity::new) .validBlocks(AllBlocks.MECHANICAL_CRAFTER) .renderer(() -> MechanicalCrafterRenderer::new) - .onRegister(ShaftlessCogInstance::register) + .onRegister(MechanicalCrafterInstance::register) .register(); public static final TileEntityEntry SEQUENCED_GEARSHIFT = Create.registrate() @@ -454,21 +460,21 @@ public class AllTileEntities { .tileEntity("rotation_speed_controller", SpeedControllerTileEntity::new) .validBlocks(AllBlocks.ROTATION_SPEED_CONTROLLER) .renderer(() -> SpeedControllerRenderer::new) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry SPEEDOMETER = Create.registrate() .tileEntity("speedometer", SpeedGaugeTileEntity::new) .validBlocks(AllBlocks.SPEEDOMETER) .renderer(() -> GaugeRenderer::speed) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry STRESSOMETER = Create.registrate() .tileEntity("stressometer", StressGaugeTileEntity::new) .validBlocks(AllBlocks.STRESSOMETER) .renderer(() -> GaugeRenderer::stress) - .onRegister(SingleRotatingShaftInstance::register) + .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ANALOG_LEVER = Create.registrate() diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index ca0dcbdec..561107461 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -11,7 +11,7 @@ import com.simibubi.create.foundation.block.render.CustomBlockModels; import com.simibubi.create.foundation.block.render.SpriteShifter; import com.simibubi.create.foundation.item.CustomItemModels; import com.simibubi.create.foundation.item.CustomRenderedItems; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.SuperByteBufferCache; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; @@ -44,7 +44,7 @@ public class CreateClient { public static SchematicHandler schematicHandler; public static SchematicAndQuillHandler schematicAndQuillHandler; public static SuperByteBufferCache bufferCache; - public static InstancedTileRenderDispatcher kineticRenderer; + public static InstancedTileRenderer kineticRenderer; public static final Outliner outliner = new Outliner(); private static CustomBlockModels customBlockModels; @@ -72,7 +72,7 @@ public class CreateClient { bufferCache.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE); bufferCache.registerCompartment(ContraptionRenderer.CONTRAPTION, 20); - kineticRenderer = new InstancedTileRenderDispatcher(); + kineticRenderer = new InstancedTileRenderer(); AllKeys.register(); AllContainerTypes.registerScreenFactories(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java index 6538232d7..b386cc41d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java @@ -1,17 +1,20 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class BackHalfShaftInstance extends HalfShaftInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, BackHalfShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, BackHalfShaftInstance::new)); } - public BackHalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public BackHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } 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 57611c092..81950b2ec 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 @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -9,13 +9,16 @@ import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class HalfShaftInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new)); } - public HalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index a4f9d2471..e9ddd647f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -1,17 +1,20 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class HorizontalHalfShaftInstance extends HalfShaftInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new)); } - public HorizontalHalfShaftInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index d7973d1cb..baae13d13 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -472,9 +472,7 @@ public abstract class KineticTileEntity extends SmartTileEntity @Override public void requestModelDataUpdate() { super.requestModelDataUpdate(); - if (this.removed) { - FastRenderDispatcher.enqueueRemove(this); - } else { + if (!this.removed) { FastRenderDispatcher.enqueueUpdate(this); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java index 903b92b72..f1015dd48 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntityRenderer.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -26,7 +25,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber(value = Dist.CLIENT) -public class KineticTileEntityRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class KineticTileEntityRenderer extends SafeTileEntityRenderer { public static final Compartment KINETIC_TILE = new Compartment<>(); public static boolean rainbowMode = false; @@ -45,12 +44,10 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer(te)); } - @Override public void addInstanceData(InstanceContext ctx) { renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - @Override public void markForRebuild(InstanceContext ctx) { getRotatedModel(ctx).clearInstanceData(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index ccfd9515f..ece5c0594 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -3,54 +3,46 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.*; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; -import net.minecraft.world.World; import java.util.function.Consumer; public abstract class KineticTileInstance extends TileEntityInstance { - public KineticTileInstance(InstancedTileRenderDispatcher modelManager, T tile) { + public KineticTileInstance(InstancedTileRenderer modelManager, T tile) { super(modelManager, tile); } - protected void updateRotation(InstanceKey key, Direction.Axis axis) { + protected final void updateRotation(InstanceKey key, Direction.Axis axis) { key.modifyInstance(data -> { - final BlockPos pos = tile.getPos(); - data.setRotationalSpeed(tile.getSpeed()) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(axis); }); } protected final Consumer setupFunc(float speed, Direction.Axis axis) { return data -> { - final BlockPos pos = tile.getPos(); - - data.setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, tile.getPos())) - .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, tile.getPos())) + data.setBlockLight(tile.getWorld().getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(tile.getWorld().getLightLevel(LightType.SKY, pos)) .setTileEntity(tile) .setRotationalSpeed(speed) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(axis); }; } protected final void relight(KineticData data) { - World world = tile.getWorld(); - - data.setBlockLight(world.getLightLevel(LightType.BLOCK, tile.getPos())) - .setSkyLight(world.getLightLevel(LightType.SKY, tile.getPos())); + data.setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) + .setSkyLight(world.getLightLevel(LightType.SKY, pos)); } - protected static float getRotationOffsetForPosition(KineticTileEntity te, final BlockPos pos, final Direction.Axis axis) { - float offset = CogWheelBlock.isLargeCog(te.getBlockState()) ? 11.25f : 0; + protected float getRotationOffset(final Direction.Axis axis) { + float offset = CogWheelBlock.isLargeCog(lastState) ? 11.25f : 0; double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY()) + ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2; if (d == 0) { @@ -64,9 +56,8 @@ public abstract class KineticTileInstance extends T .with(ShaftBlock.AXIS, axis); } - public static Direction.Axis getRotationAxisOf(KineticTileEntity te) { - return ((IRotate) te.getBlockState() - .getBlock()).getRotationAxis(te.getBlockState()); + public Direction.Axis getRotationAxis() { + return ((IRotate) lastState.getBlock()).getRotationAxis(lastState); } protected final RenderMaterial> rotatingMaterial() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java index d6f318f3f..e4d47c08b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -1,18 +1,21 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class ShaftlessCogInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, ShaftlessCogInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, ShaftlessCogInstance::new)); } - public ShaftlessCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public ShaftlessCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index 9e1732cd2..374c2207f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; @@ -8,29 +8,32 @@ import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import static com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer.KINETIC_TILE; public class SingleRotatingInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, SingleRotatingInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, SingleRotatingInstance::new)); } protected InstanceKey rotatingModelKey; - public SingleRotatingInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public SingleRotatingInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected void init() { - Direction.Axis axis = ((IRotate) tile.getBlockState().getBlock()).getRotationAxis(tile.getBlockState()); + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); rotatingModelKey = getModel().setupInstance(setupFunc(tile.getSpeed(), axis)); } @Override public void onUpdate() { - Direction.Axis axis = ((IRotate) tile.getBlockState().getBlock()).getRotationAxis(tile.getBlockState()); + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); updateRotation(rotatingModelKey, axis); } @@ -46,7 +49,7 @@ public class SingleRotatingInstance extends KineticTileInstance getModel() { 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 2082919b6..77b5779fb 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 @@ -3,18 +3,20 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class DrillInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, DrillInstance::new); - } + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, DrillInstance::new)); } - public DrillInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public DrillInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java new file mode 100644 index 000000000..fa8dec58c --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -0,0 +1,46 @@ +package com.simibubi.create.content.contraptions.components.crafter; + +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.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import java.util.function.Supplier; + +public class MechanicalCrafterInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, MechanicalCrafterInstance::new)); + } + + public MechanicalCrafterInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + Direction facing = lastState.get(MechanicalCrafterBlock.HORIZONTAL_FACING); + + Supplier ms = () -> { + MatrixStack stack = new MatrixStack(); + MatrixStacker.of(stack) + .centre() + .rotateZ(90) + .rotateY(AngleHelper.horizontalAngle(facing)) + .rotateX(AngleHelper.verticalAngle(facing)) + .unCentre(); + return stack; + }; + return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, lastState, facing, ms); + } +} 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 a81162e17..d3aa7b2e7 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 @@ -9,7 +9,6 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerTile import com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.State; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; @@ -33,7 +32,7 @@ import net.minecraft.world.World; import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; -public class DeployerRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class DeployerRenderer extends SafeTileEntityRenderer { public DeployerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -53,12 +52,10 @@ public class DeployerRenderer extends SafeTileEntityRenderer } - @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntityRenderer.renderRotatingKineticBlock(ctx, getRenderedBlockState(ctx.te)); } - @Override public void markForRebuild(InstanceContext ctx) { KineticTileEntityRenderer.markForRebuild(ctx, getRenderedBlockState(ctx.te)); } 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 new file mode 100644 index 000000000..8872229d2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -0,0 +1,117 @@ +package com.simibubi.create.content.contraptions.components.fan; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.base.IRotate; +import com.simibubi.create.content.contraptions.base.KineticTileInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstanceKey; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.LightType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import static net.minecraft.state.properties.BlockStateProperties.FACING; + +public class FanInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, FanInstance::new)); + } + + protected InstanceKey shaft; + protected InstanceKey fan; + + public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + final Direction direction = lastState.get(FACING); + final Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + + InstancedModel shaftHalf = + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); + InstancedModel fanInner = + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); + + shaft = shaftHalf.setupInstance(data -> { + BlockPos behind = pos.offset(direction.getOpposite()); + int blockLight = world.getLightLevel(LightType.BLOCK, behind); + int skyLight = world.getLightLevel(LightType.SKY, behind); + + data.setRotationalSpeed(tile.getSpeed()) + .setRotationOffset(getRotationOffset(axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setTileEntity(tile) + .setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + fan = fanInner.setupInstance(data -> { + BlockPos inFront = pos.offset(direction); + int blockLight = world.getLightLevel(LightType.BLOCK, inFront); + int skyLight = world.getLightLevel(LightType.SKY, inFront); + + data.setRotationalSpeed(getFanSpeed()) + .setRotationOffset(getRotationOffset(axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) + .setTileEntity(tile) + .setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + } + + private float getFanSpeed() { + float speed = tile.getSpeed() * 5; + if (speed > 0) + speed = MathHelper.clamp(speed, 80, 64 * 20); + if (speed < 0) + speed = MathHelper.clamp(speed, -64 * 20, -80); + return speed; + } + + @Override + protected void onUpdate() { + Direction.Axis axis = lastState.get(FACING).getAxis(); + updateRotation(shaft, axis); + + fan.modifyInstance(data -> { + data.setRotationalSpeed(getFanSpeed()) + .setRotationOffset(getRotationOffset(axis)) + .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); + }); + } + + @Override + public void updateLight() { + final Direction direction = lastState.get(FACING); + + shaft.modifyInstance(data -> { + BlockPos behind = pos.offset(direction.getOpposite()); + int blockLight = world.getLightLevel(LightType.BLOCK, behind); + int skyLight = world.getLightLevel(LightType.SKY, behind); + data.setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + fan.modifyInstance(data -> { + BlockPos inFront = pos.offset(direction); + int blockLight = world.getLightLevel(LightType.BLOCK, inFront); + int skyLight = world.getLightLevel(LightType.SKY, inFront); + data.setBlockLight(blockLight) + .setSkyLight(skyLight); + }); + } + + @Override + public void remove() { + shaft.delete(); + fan.delete(); + shaft = fan = null; + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java index 03c408569..bd663dc70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -3,18 +3,20 @@ package com.simibubi.create.content.contraptions.components.millstone; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class MillStoneCogInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, MillStoneCogInstance::new); - } + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, MillStoneCogInstance::new)); } - public MillStoneCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public MillStoneCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } 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 58a7a6c83..60f7d437f 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 @@ -19,6 +19,11 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer { super(dispatcher); } + @Override + public boolean isGlobalRenderer(KineticTileEntity tile) { + return true; + } + @Override protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { 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 new file mode 100644 index 000000000..5b5175ad1 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -0,0 +1,35 @@ +package com.simibubi.create.content.contraptions.components.saw; + +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.base.SingleRotatingInstance; +import com.simibubi.create.foundation.render.InstancedTileRenderer; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; +import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Rotation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import static net.minecraft.state.properties.BlockStateProperties.FACING; + +public class SawInstance extends SingleRotatingInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, SawInstance::new)); + } + + public SawInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected InstancedModel getModel() { + if (lastState.get(FACING).getAxis().isHorizontal()) + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180)); + else + return rotatingMaterial().getModel(KineticTileEntityRenderer.KINETIC_TILE, shaft(getRotationAxis())); + } +} 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 d357081eb..217be3457 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 @@ -6,7 +6,6 @@ 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.SuperByteBuffer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -32,7 +31,7 @@ import net.minecraft.util.math.Vec3d; import static net.minecraft.state.properties.BlockStateProperties.FACING; -public class SawRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class SawRenderer extends SafeTileEntityRenderer { public SawRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -47,12 +46,10 @@ public class SawRenderer extends SafeTileEntityRenderer implement } - @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - @Override public void markForRebuild(InstanceContext ctx) { getRotatedModel(ctx).clearInstanceData(); } 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 cd8558bd0..2c23dd4e8 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 @@ -3,18 +3,21 @@ package com.simibubi.create.content.contraptions.fluids; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class PumpCogInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, PumpCogInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, PumpCogInstance::new)); } - public PumpCogInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public PumpCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java index 5ae680b64..caee82b16 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/SpeedControllerRenderer.java @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.relays.advanced; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; -import com.simibubi.create.foundation.render.instancing.IInstancedTileEntityRenderer; import com.simibubi.create.foundation.render.instancing.InstanceContext; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.RotatingData; @@ -10,7 +9,7 @@ import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRendere import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -public class SpeedControllerRenderer extends SmartTileEntityRenderer implements IInstancedTileEntityRenderer { +public class SpeedControllerRenderer extends SmartTileEntityRenderer { public SpeedControllerRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -23,12 +22,10 @@ public class SpeedControllerRenderer extends SmartTileEntityRenderer(tileEntityIn)); } - @Override public void addInstanceData(InstanceContext ctx) { KineticTileEntityRenderer.renderRotatingBuffer(ctx, getRotatedModel(ctx)); } - @Override public void markForRebuild(InstanceContext ctx) { getRotatedModel(ctx).clearInstanceData(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index f76a5b502..345fd0d30 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.*; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -14,6 +14,8 @@ import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; import java.util.function.Consumer; @@ -21,7 +23,8 @@ import java.util.function.Supplier; public class BeltInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, BeltInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, BeltInstance::new)); } private boolean upward; @@ -35,7 +38,7 @@ public class BeltInstance extends KineticTileInstance { protected ArrayList> keys; protected InstanceKey pulleyKey; - public BeltInstance(InstancedTileRenderDispatcher modelManager, BeltTileEntity tile) { + public BeltInstance(InstancedTileRenderer modelManager, BeltTileEntity tile) { super(modelManager, tile); } @@ -75,7 +78,7 @@ public class BeltInstance extends KineticTileInstance { if (tile.hasPulley()) { InstancedModel pulleyModel = getPulleyModel(blockState); - pulleyKey = pulleyModel.setupInstance(setupFunc(tile.getSpeed(), getRotationAxisOf(tile))); + pulleyKey = pulleyModel.setupInstance(setupFunc(tile.getSpeed(), getRotationAxis())); } } @@ -86,7 +89,7 @@ public class BeltInstance extends KineticTileInstance { } if (pulleyKey != null) { - updateRotation(pulleyKey, getRotationAxisOf(tile)); + updateRotation(pulleyKey, getRotationAxis()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index c598fe765..984fc6b49 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -8,7 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.ShadowRenderHelper; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.instancing.BeltData; +import com.simibubi.create.foundation.render.instancing.InstanceContext; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.RotatingData; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -31,7 +34,7 @@ import net.minecraft.world.LightType; import java.util.Random; import java.util.function.Supplier; -public class BeltRenderer extends SafeTileEntityRenderer implements IInstancedTileEntityRenderer { +public class BeltRenderer extends SafeTileEntityRenderer { public BeltRenderer(TileEntityRendererDispatcher dispatcher) { super(dispatcher); @@ -54,7 +57,6 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme return te.isController(); } - @Override public void addInstanceData(InstanceContext ctx) { BeltTileEntity te = ctx.te; BlockState blockState = te.getBlockState(); @@ -146,7 +148,6 @@ public class BeltRenderer extends SafeTileEntityRenderer impleme } } - @Override public void markForRebuild(InstanceContext ctx) { BeltTileEntity te = ctx.te; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java similarity index 61% rename from src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java rename to src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index 89a661795..e563df129 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SingleRotatingShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -2,24 +2,27 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; -public class SingleRotatingShaftInstance extends SingleRotatingInstance { +public class ShaftInstance extends SingleRotatingInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, SingleRotatingShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, ShaftInstance::new)); } - public SingleRotatingShaftInstance(InstancedTileRenderDispatcher dispatcher, KineticTileEntity tile) { + public ShaftInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); } @Override protected BlockState getRenderedBlockState() { - return shaft(getRotationAxisOf(tile)); + return shaft(getRotationAxis()); } } 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 077b9b091..15d3d2771 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 @@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.relays.encased; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstanceKey; import com.simibubi.create.foundation.render.instancing.InstancedModel; import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; @@ -14,17 +14,20 @@ import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; public class SplitShaftInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, SplitShaftInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, SplitShaftInstance::new)); } protected ArrayList> keys; - public SplitShaftInstance(InstancedTileRenderDispatcher modelManager, SplitShaftTileEntity tile) { + public SplitShaftInstance(InstancedTileRenderer modelManager, SplitShaftTileEntity tile) { super(modelManager, tile); } @@ -80,7 +83,7 @@ public class SplitShaftInstance extends KineticTileInstance { public static void register(TileEntityType type) { - InstancedTileRenderRegistry.instance.register(type, GearboxInstance::new); + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, GearboxInstance::new)); } protected EnumMap> keys; protected Direction sourceFacing; - public GearboxInstance(InstancedTileRenderDispatcher modelManager, GearboxTileEntity tile) { + public GearboxInstance(InstancedTileRenderer modelManager, GearboxTileEntity tile) { super(modelManager, tile); } @@ -54,7 +57,7 @@ public class GearboxInstance extends KineticTileInstance { data.setBlockLight(blockLight) .setSkyLight(skyLight) .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setTileEntity(tile); }); @@ -93,7 +96,7 @@ public class GearboxInstance extends KineticTileInstance { Direction.Axis axis = direction.getAxis(); data.setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffsetForPosition(tile, pos, axis)) + .setRotationOffset(getRotationOffset(axis)) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); }); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 0d931d6c1..82655699c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -3,12 +3,21 @@ package com.simibubi.create.content.logistics.block.mechanicalArm; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.instancing.RotatingData; +import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; public class ArmInstance extends SingleRotatingInstance { - public ArmInstance(InstancedTileRenderDispatcher modelManager, KineticTileEntity tile) { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, ArmInstance::new)); + } + + public ArmInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index d0bd82064..fe626d735 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -50,6 +50,7 @@ import net.minecraftforge.client.event.EntityViewRenderEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.event.TickEvent.RenderTickEvent; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java new file mode 100644 index 000000000..5970e3dfe --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java @@ -0,0 +1,32 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@OnlyIn(Dist.CLIENT) +@Mixin(World.class) +public class OnRemoveTileMixin { + + @Shadow @Final public boolean isRemote; + + /** + * JUSTIFICATION: This method is called whenever a tile entity is removed due + * to a change in block state, even on the client. By hooking into this method, + * we gain easy access to the information while having no impact on performance. + */ + @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;"), method = "removeTileEntity", locals = LocalCapture.CAPTURE_FAILHARD) + private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { + if (isRemote) FastRenderDispatcher.enqueueRemove(te); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 20386c6f3..64e66bee0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -5,6 +5,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.render.contraption.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; +import com.simibubi.create.foundation.render.instancing.TileEntityInstance; import com.simibubi.create.foundation.render.light.ILightListener; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.WorldAttached; @@ -25,13 +26,17 @@ import net.minecraft.world.LightType; import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL11; +import javax.annotation.Nullable; import java.util.Map; +import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.function.Consumer; public class FastRenderDispatcher { - public static WorldAttached> addedTiles = new WorldAttached<>(ConcurrentLinkedQueue::new); - public static WorldAttached> removedTiles = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached> queuedUpdates = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached> queuedRemovals = new WorldAttached<>(ConcurrentLinkedQueue::new); + public static WorldAttached>> addedLastTick = new WorldAttached<>(ConcurrentLinkedQueue::new); private static Matrix4f projectionMatrixThisFrame = null; @@ -40,34 +45,28 @@ public class FastRenderDispatcher { } public static void enqueueUpdate(TileEntity te) { - addedTiles.get(te.getWorld()).add(te); + queuedUpdates.get(te.getWorld()).add(te); } public static void enqueueRemove(TileEntity te) { - removedTiles.get(te.getWorld()).add(te); + queuedRemovals.get(te.getWorld()).add(te); } public static void tick() { ClientWorld world = Minecraft.getInstance().world; - ConcurrentLinkedQueue added = addedTiles.get(world); + runQueue(addedLastTick.get(world), TileEntityInstance::updateLight); + runQueue(queuedUpdates.get(world), CreateClient.kineticRenderer::update); + runQueue(queuedRemovals.get(world), CreateClient.kineticRenderer::remove); + } - if (added != null) { - while (!added.isEmpty()) { - TileEntity te = added.poll(); + private static void runQueue(@Nullable Queue q, Consumer action) { + if (q == null) return; - CreateClient.kineticRenderer.update(te); - } - } + while (!q.isEmpty()) { + T t = q.poll(); - ConcurrentLinkedQueue removed = removedTiles.get(world); - - if (removed != null) { - while (!removed.isEmpty()) { - TileEntity te = removed.poll(); - - CreateClient.kineticRenderer.remove(te); - } + action.accept(t); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java similarity index 77% rename from src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java rename to src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java index b1eb363e3..6b86af49b 100644 --- a/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/InstancedTileRenderer.java @@ -1,6 +1,5 @@ package com.simibubi.create.foundation.render; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; import com.simibubi.create.foundation.render.gl.shader.Shader; import com.simibubi.create.foundation.render.gl.shader.ShaderCallback; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; @@ -13,12 +12,12 @@ import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; -public class InstancedTileRenderDispatcher { +public class InstancedTileRenderer { protected Map> renderers = new HashMap<>(); protected Map, RenderMaterial> materials = new HashMap<>(); - public InstancedTileRenderDispatcher() { + public InstancedTileRenderer() { registerMaterials(); } @@ -40,7 +39,10 @@ public class InstancedTileRenderDispatcher { } else { TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); - renderers.put(tile, renderer); + if (renderer != null) { + FastRenderDispatcher.addedLastTick.get(tile.getWorld()).add(renderer); + renderers.put(tile, renderer); + } return renderer; } @@ -75,25 +77,11 @@ public class InstancedTileRenderDispatcher { } } - public void addInstancedData(RenderedContraption c, T te, IInstancedTileEntityRenderer renderer) { - renderer.addInstanceData(new InstanceContext.Contraption<>(te, c)); - } - - /** - * This function should be called after building instances. - * It must be called either on the render thread before committing to rendering, or in a place where there are - * guaranteed to be no race conditions with the render thread, i.e. when constructing a FastContraptionRenderer. - */ - public void markAllDirty() { - for (RenderMaterial material : materials.values()) { - material.runOnAll(InstancedModel::markDirty); - } - } - public void invalidate() { for (RenderMaterial material : materials.values()) { material.delete(); } + renderers.clear(); } public void render(RenderType layer, Matrix4f projection, Matrix4f view) { diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java index f5761bedd..7b77398f7 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/ContraptionKineticRenderer.java @@ -1,6 +1,6 @@ package com.simibubi.create.foundation.render.contraption; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import com.simibubi.create.foundation.render.gl.shader.Shader; import com.simibubi.create.foundation.render.instancing.BeltModel; import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; @@ -8,7 +8,7 @@ import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.RotatingModel; import com.simibubi.create.foundation.render.instancing.actors.RotatingActorModel; -public class ContraptionKineticRenderer extends InstancedTileRenderDispatcher { +public class ContraptionKineticRenderer extends InstancedTileRenderer { @Override public void registerMaterials() { diff --git a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java index aac348e79..80122a1e4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/foundation/render/contraption/RenderedContraption.java @@ -7,14 +7,15 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.gl.shader.ShaderHelper; -import com.simibubi.create.foundation.render.instancing.*; +import com.simibubi.create.foundation.render.instancing.IInstanceRendered; +import com.simibubi.create.foundation.render.instancing.InstancedModel; +import com.simibubi.create.foundation.render.instancing.KineticRenderMaterials; +import com.simibubi.create.foundation.render.instancing.RenderMaterial; import com.simibubi.create.foundation.render.instancing.actors.StaticRotatingActorData; import com.simibubi.create.foundation.render.light.ContraptionLighter; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.Matrix4f; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; @@ -44,7 +45,6 @@ public class RenderedContraption { buildLayers(contraption); buildInstancedTiles(contraption); buildActors(contraption); - kinetics.markAllDirty(); } public int getEntityId() { @@ -91,11 +91,7 @@ public class RenderedContraption { if (!tileEntities.isEmpty()) { for (TileEntity te : tileEntities) { if (te instanceof IInstanceRendered) { - TileEntityRenderer renderer = TileEntityRendererDispatcher.instance.getRenderer(te); - - if (renderer instanceof IInstancedTileEntityRenderer) { - kinetics.addInstancedData(this, te, (IInstancedTileEntityRenderer) renderer); - } + kinetics.getRenderer(te); // this is enough to instantiate the model instance } } } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java deleted file mode 100644 index 4b9ccaa1b..000000000 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IInstancedTileEntityRenderer.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.simibubi.create.foundation.render.instancing; - -import net.minecraft.tileentity.TileEntity; - -public interface IInstancedTileEntityRenderer { - - void addInstanceData(InstanceContext ctx); - - void markForRebuild(InstanceContext ctx); -} diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java index 2ad3a86bd..263b4af17 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/IRendererFactory.java @@ -1,9 +1,9 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; @FunctionalInterface public interface IRendererFactory { - TileEntityInstance create(InstancedTileRenderDispatcher manager, T te); + TileEntityInstance create(InstancedTileRenderer manager, T te); } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java index 711d2a393..1d1ef8c3f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstanceContext.java @@ -1,8 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.simibubi.create.CreateClient; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; -import com.simibubi.create.foundation.render.contraption.RenderedContraption; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; @Deprecated @@ -22,30 +21,10 @@ public abstract class InstanceContext { return getKinetics().get(KineticRenderMaterials.BELTS); } - public abstract InstancedTileRenderDispatcher getKinetics(); + public abstract InstancedTileRenderer getKinetics(); public abstract boolean checkWorldLight(); - public static class Contraption extends InstanceContext { - - public final RenderedContraption c; - - public Contraption(T te, RenderedContraption c) { - super(te); - this.c = c; - } - - @Override - public InstancedTileRenderDispatcher getKinetics() { - return c.kinetics; - } - - @Override - public boolean checkWorldLight() { - return false; - } - } - public static class World extends InstanceContext { public World(T te) { @@ -53,7 +32,7 @@ public abstract class InstanceContext { } @Override - public InstancedTileRenderDispatcher getKinetics() { + public InstancedTileRenderer getKinetics() { return CreateClient.kineticRenderer; } diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index edd1ed544..19063df7f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -5,10 +5,7 @@ import com.simibubi.create.foundation.render.BufferedModel; import com.simibubi.create.foundation.render.RenderMath; import com.simibubi.create.foundation.render.gl.GlBuffer; import net.minecraft.client.renderer.BufferBuilder; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GL31; -import org.lwjgl.opengl.GL33; +import org.lwjgl.opengl.*; import java.nio.ByteBuffer; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java index 71cd04266..64c0012db 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedTileRenderRegistry.java @@ -1,7 +1,7 @@ package com.simibubi.create.foundation.render.instancing; import com.google.common.collect.Maps; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; @@ -19,7 +19,7 @@ public class InstancedTileRenderRegistry { @SuppressWarnings("unchecked") @Nullable - public TileEntityInstance create(InstancedTileRenderDispatcher manager, T tile) { + public TileEntityInstance create(InstancedTileRenderer manager, T tile) { TileEntityType type = tile.getType(); IRendererFactory factory = (IRendererFactory) this.renderers.get(type); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java index 2bd228c58..1d1762e3a 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/TileEntityInstance.java @@ -1,18 +1,24 @@ package com.simibubi.create.foundation.render.instancing; -import com.simibubi.create.foundation.render.InstancedTileRenderDispatcher; +import com.simibubi.create.foundation.render.InstancedTileRenderer; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public abstract class TileEntityInstance { - protected final InstancedTileRenderDispatcher modelManager; + protected final InstancedTileRenderer modelManager; protected final T tile; + protected final World world; + protected final BlockPos pos; protected BlockState lastState; - public TileEntityInstance(InstancedTileRenderDispatcher modelManager, T tile) { + public TileEntityInstance(InstancedTileRenderer modelManager, T tile) { this.modelManager = modelManager; this.tile = tile; + this.world = tile.getWorld(); + this.pos = tile.getPos(); this.lastState = tile.getBlockState(); init(); } @@ -25,8 +31,8 @@ public abstract class TileEntityInstance { onUpdate(); } else { remove(); - init(); lastState = currentState; + init(); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java index 027e9bfd4..bbf69d51f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/light/LightVolume.java @@ -10,12 +10,7 @@ import org.lwjgl.opengl.*; import org.lwjgl.system.MemoryUtil; import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicBoolean; -// TODO: Don't immediately destroy light volumes. -// There's a high chance that a contraption will stop and soon after start again. -// By caching lightvolumes based on their volumes/locations, we can save having -// to reread all the lighting data in those cases. public class LightVolume { private GridAlignedBB sampleVolume; @@ -31,7 +26,7 @@ public class LightVolume { setSampleVolume(sampleVolume); this.glTexture = new GlTexture(GL20.GL_TEXTURE_3D); - this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: maybe figure out how to pack light coords into a single byte + this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); } private void setSampleVolume(GridAlignedBB sampleVolume) { @@ -225,10 +220,7 @@ public class LightVolume { int sizeX = textureVolume.sizeX(); int sizeY = textureVolume.sizeY(); int sizeZ = textureVolume.sizeZ(); - if (sizeX * sizeY * sizeZ * 2 > lightData.capacity()) - throw new IllegalStateException("Volume too big for buffer"); - lightData.rewind(); GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); bufferDirty = false; } diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index beb9f49c8..ae2f46a98 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -7,5 +7,5 @@ "injectors": { "defaultRequire": 1 }, - "minVersion": "0.8" + "minVersion": "0.8", "mixins": ["OnRemoveTileMixin"] } \ No newline at end of file