diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 2951cb835..f65fa76ea 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.components.clock.CuckooClockTile 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.HandCrankInstance; import com.simibubi.create.content.contraptions.components.crank.HandCrankRenderer; import com.simibubi.create.content.contraptions.components.crank.HandCrankTileEntity; import com.simibubi.create.content.contraptions.components.crusher.CrushingWheelControllerTileEntity; @@ -119,9 +120,9 @@ public class AllTileEntities { // Schematics public static final TileEntityEntry SCHEMATICANNON = Create.registrate() .tileEntity("schematicannon", SchematicannonTileEntity::new) + .instance(() -> SchematicannonInstance::new) .validBlocks(AllBlocks.SCHEMATICANNON) .renderer(() -> SchematicannonRenderer::new) - .onRegister(SchematicannonInstance::register) .register(); public static final TileEntityEntry SCHEMATIC_TABLE = Create.registrate() @@ -132,44 +133,44 @@ public class AllTileEntities { // Kinetics public static final TileEntityEntry SIMPLE_KINETIC = Create.registrate() .tileEntity("simple_kinetic", SimpleKineticTileEntity::new) + .instance(() -> SingleRotatingInstance::new) .validBlocks(AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL) .renderer(() -> KineticTileEntityRenderer::new) - .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry MOTOR = Create.registrate() .tileEntity("motor", CreativeMotorTileEntity::new) + .instance(() -> HalfShaftInstance::new) .validBlocks(AllBlocks.CREATIVE_MOTOR) .renderer(() -> CreativeMotorRenderer::new) - .onRegister(HalfShaftInstance::register) .register(); public static final TileEntityEntry GEARBOX = Create.registrate() .tileEntity("gearbox", GearboxTileEntity::new) + .instance(() -> GearboxInstance::new) .validBlocks(AllBlocks.GEARBOX) .renderer(() -> GearboxRenderer::new) - .onRegister(GearboxInstance::register) .register(); public static final TileEntityEntry ENCASED_SHAFT = Create.registrate() .tileEntity("encased_shaft", EncasedShaftTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.ANDESITE_ENCASED_SHAFT, AllBlocks.BRASS_ENCASED_SHAFT, AllBlocks.ENCASED_CHAIN_DRIVE) .renderer(() -> EncasedShaftRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ADJUSTABLE_PULLEY = Create.registrate() .tileEntity("adjustable_pulley", AdjustablePulleyTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.ADJUSTABLE_CHAIN_GEARSHIFT) .renderer(() -> EncasedShaftRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ENCASED_FAN = Create.registrate() .tileEntity("encased_fan", EncasedFanTileEntity::new) + .instance(() -> FanInstance::new) .validBlocks(AllBlocks.ENCASED_FAN) .renderer(() -> EncasedFanRenderer::new) - .onRegister(FanInstance::register) .register(); public static final TileEntityEntry NOZZLE = Create.registrate() @@ -180,59 +181,59 @@ public class AllTileEntities { public static final TileEntityEntry CLUTCH = Create.registrate() .tileEntity("clutch", ClutchTileEntity::new) + .instance(() -> SplitShaftInstance::new) .validBlocks(AllBlocks.CLUTCH) .renderer(() -> SplitShaftRenderer::new) - .onRegister(SplitShaftInstance::register) .register(); public static final TileEntityEntry GEARSHIFT = Create.registrate() .tileEntity("gearshift", GearshiftTileEntity::new) + .instance(() -> SplitShaftInstance::new) .validBlocks(AllBlocks.GEARSHIFT) .renderer(() -> SplitShaftRenderer::new) - .onRegister(SplitShaftInstance::register) .register(); public static final TileEntityEntry TURNTABLE = Create.registrate() .tileEntity("turntable", TurntableTileEntity::new) + .instance(() -> SingleRotatingInstance::new) .validBlocks(AllBlocks.TURNTABLE) .renderer(() -> KineticTileEntityRenderer::new) - .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry HAND_CRANK = Create.registrate() .tileEntity("hand_crank", HandCrankTileEntity::new) + .instance(() -> HandCrankInstance::new) .validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE) .validBlocks(AllBlocks.DYED_VALVE_HANDLES) .renderer(() -> HandCrankRenderer::new) - .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry CUCKOO_CLOCK = Create.registrate() .tileEntity("cuckoo_clock", CuckooClockTileEntity::new) + .instance(() -> HorizontalHalfShaftInstance::new) .validBlocks(AllBlocks.CUCKOO_CLOCK, AllBlocks.MYSTERIOUS_CUCKOO_CLOCK) .renderer(() -> CuckooClockRenderer::new) - .onRegister(HorizontalHalfShaftInstance::register) .register(); public static final TileEntityEntry GANTRY_SHAFT = Create.registrate() .tileEntity("gantry_shaft", GantryShaftTileEntity::new) + .instance(() -> SingleRotatingInstance::new) .validBlocks(AllBlocks.GANTRY_SHAFT) .renderer(() -> KineticTileEntityRenderer::new) - .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry GANTRY_PINION = Create.registrate() .tileEntity("gantry_pinion", GantryCarriageTileEntity::new) + .instance(() -> GantryCarriageInstance::new) .validBlocks(AllBlocks.GANTRY_CARRIAGE) .renderer(() -> GantryCarriageRenderer::new) - .onRegister(GantryCarriageInstance::register) .register(); public static final TileEntityEntry MECHANICAL_PUMP = Create.registrate() .tileEntity("mechanical_pump", PumpTileEntity::new) + .instance(() -> PumpCogInstance::new) .validBlocks(AllBlocks.MECHANICAL_PUMP) .renderer(() -> PumpRenderer::new) - .onRegister(PumpCogInstance::register) .register(); public static final TileEntityEntry SMART_FLUID_PIPE = Create.registrate() @@ -259,9 +260,9 @@ public class AllTileEntities { public static final TileEntityEntry FLUID_VALVE = Create.registrate() .tileEntity("fluid_valve", FluidValveTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.FLUID_VALVE) .renderer(() -> FluidValveRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry FLUID_TANK = Create.registrate() @@ -278,9 +279,9 @@ public class AllTileEntities { public static final TileEntityEntry HOSE_PULLEY = Create.registrate() .tileEntity("hose_pulley", HosePulleyTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.HOSE_PULLEY) .renderer(() -> HosePulleyRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry SPOUT = Create.registrate() @@ -297,9 +298,9 @@ public class AllTileEntities { public static final TileEntityEntry BELT = Create.registrate() .tileEntity("belt", BeltTileEntity::new) + .instance(() -> BeltInstance::new) .validBlocks(AllBlocks.BELT) .renderer(() -> BeltRenderer::new) - .onRegister(BeltInstance::register) .register(); public static final TileEntityEntry CHUTE = Create.registrate() @@ -316,58 +317,58 @@ public class AllTileEntities { public static final TileEntityEntry ANDESITE_TUNNEL = Create.registrate() .tileEntity("andesite_tunnel", BeltTunnelTileEntity::new) + .instance(() -> BeltTunnelInstance::new) .validBlocks(AllBlocks.ANDESITE_TUNNEL) .renderer(() -> BeltTunnelRenderer::new) - .onRegister(BeltTunnelInstance::register) .register(); public static final TileEntityEntry BRASS_TUNNEL = Create.registrate() .tileEntity("brass_tunnel", BrassTunnelTileEntity::new) + .instance(() -> BeltTunnelInstance::new) .validBlocks(AllBlocks.BRASS_TUNNEL) .renderer(() -> BeltTunnelRenderer::new) - .onRegister(BeltTunnelInstance::register) .register(); public static final TileEntityEntry MECHANICAL_ARM = Create.registrate() .tileEntity("mechanical_arm", ArmTileEntity::new) + .instance(() -> ArmInstance::new) .validBlocks(AllBlocks.MECHANICAL_ARM) .renderer(() -> ArmRenderer::new) - .onRegister((type) -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ArmInstance.register(type)))//ArmInstance line 142 -> Minecraft.getInstance().world causes ClientWorld to get loaded on the server .register(); public static final TileEntityEntry MECHANICAL_PISTON = Create.registrate() .tileEntity("mechanical_piston", MechanicalPistonTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.MECHANICAL_PISTON, AllBlocks.STICKY_MECHANICAL_PISTON) .renderer(() -> MechanicalPistonRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry WINDMILL_BEARING = Create.registrate() .tileEntity("windmill_bearing", WindmillBearingTileEntity::new) + .instance(() -> BackHalfShaftInstance::new) .validBlocks(AllBlocks.WINDMILL_BEARING) .renderer(() -> BearingRenderer::new) - .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry MECHANICAL_BEARING = Create.registrate() .tileEntity("mechanical_bearing", MechanicalBearingTileEntity::new) + .instance(() -> BackHalfShaftInstance::new) .validBlocks(AllBlocks.MECHANICAL_BEARING) .renderer(() -> BearingRenderer::new) - .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry CLOCKWORK_BEARING = Create.registrate() .tileEntity("clockwork_bearing", ClockworkBearingTileEntity::new) + .instance(() -> BackHalfShaftInstance::new) .validBlocks(AllBlocks.CLOCKWORK_BEARING) .renderer(() -> BearingRenderer::new) - .onRegister(BackHalfShaftInstance::register) .register(); public static final TileEntityEntry ROPE_PULLEY = Create.registrate() .tileEntity("rope_pulley", PulleyTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.ROPE_PULLEY) .renderer(() -> PulleyRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry CHASSIS = Create.registrate() @@ -378,23 +379,23 @@ public class AllTileEntities { public static final TileEntityEntry STICKER = Create.registrate() .tileEntity("sticker", StickerTileEntity::new) + .instance(() -> StickerInstance::new) .validBlocks(AllBlocks.STICKER) .renderer(() -> StickerRenderer::new) - .onRegister(StickerInstance::register) .register(); public static final TileEntityEntry DRILL = Create.registrate() .tileEntity("drill", DrillTileEntity::new) + .instance(() -> DrillInstance::new) .validBlocks(AllBlocks.MECHANICAL_DRILL) .renderer(() -> DrillRenderer::new) - .onRegister(DrillInstance::register) .register(); public static final TileEntityEntry SAW = Create.registrate() .tileEntity("saw", SawTileEntity::new) + .instance(() -> SawInstance::new) .validBlocks(AllBlocks.MECHANICAL_SAW) .renderer(() -> SawRenderer::new) - .onRegister(SawInstance::register) .register(); public static final TileEntityEntry HARVESTER = Create.registrate() @@ -418,30 +419,30 @@ public class AllTileEntities { public static final TileEntityEntry FLYWHEEL = Create.registrate() .tileEntity("flywheel", FlywheelTileEntity::new) + .instance(() -> FlyWheelInstance::new) .validBlocks(AllBlocks.FLYWHEEL) .renderer(() -> FlywheelRenderer::new) - .onRegister(FlyWheelInstance::register) .register(); public static final TileEntityEntry FURNACE_ENGINE = Create.registrate() .tileEntity("furnace_engine", FurnaceEngineTileEntity::new) + .instance(() -> EngineInstance::new) .validBlocks(AllBlocks.FURNACE_ENGINE) .renderer(() -> EngineRenderer::new) - .onRegister(EngineInstance::register) .register(); public static final TileEntityEntry MILLSTONE = Create.registrate() .tileEntity("millstone", MillstoneTileEntity::new) + .instance(() -> MillStoneCogInstance::new) .validBlocks(AllBlocks.MILLSTONE) .renderer(() -> MillstoneRenderer::new) - .onRegister(MillStoneCogInstance::register) .register(); public static final TileEntityEntry CRUSHING_WHEEL = Create.registrate() .tileEntity("crushing_wheel", CrushingWheelTileEntity::new) + .instance(() -> SingleRotatingInstance::new) .validBlocks(AllBlocks.CRUSHING_WHEEL) .renderer(() -> KineticTileEntityRenderer::new) - .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry CRUSHING_WHEEL_CONTROLLER = @@ -453,30 +454,30 @@ public class AllTileEntities { public static final TileEntityEntry WATER_WHEEL = Create.registrate() .tileEntity("water_wheel", WaterWheelTileEntity::new) + .instance(() -> SingleRotatingInstance::new) .validBlocks(AllBlocks.WATER_WHEEL) .renderer(() -> KineticTileEntityRenderer::new) - .onRegister(SingleRotatingInstance::register) .register(); public static final TileEntityEntry MECHANICAL_PRESS = Create.registrate() .tileEntity("mechanical_press", MechanicalPressTileEntity::new) + .instance(() -> PressInstance::new) .validBlocks(AllBlocks.MECHANICAL_PRESS) .renderer(() -> MechanicalPressRenderer::new) - .onRegister(PressInstance::register) .register(); public static final TileEntityEntry MECHANICAL_MIXER = Create.registrate() .tileEntity("mechanical_mixer", MechanicalMixerTileEntity::new) + .instance(() -> MixerInstance::new) .validBlocks(AllBlocks.MECHANICAL_MIXER) .renderer(() -> MechanicalMixerRenderer::new) - .onRegister(MixerInstance::register) .register(); public static final TileEntityEntry DEPLOYER = Create.registrate() .tileEntity("deployer", DeployerTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.DEPLOYER) .renderer(() -> DeployerRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry BASIN = Create.registrate() @@ -493,41 +494,42 @@ public class AllTileEntities { public static final TileEntityEntry MECHANICAL_CRAFTER = Create.registrate() .tileEntity("mechanical_crafter", MechanicalCrafterTileEntity::new) + .instance(() -> MechanicalCrafterInstance::new) .validBlocks(AllBlocks.MECHANICAL_CRAFTER) .renderer(() -> MechanicalCrafterRenderer::new) - .onRegister(MechanicalCrafterInstance::register) .register(); public static final TileEntityEntry SEQUENCED_GEARSHIFT = Create.registrate() .tileEntity("sequenced_gearshift", SequencedGearshiftTileEntity::new) + .instance(() -> SplitShaftInstance::new) .validBlocks(AllBlocks.SEQUENCED_GEARSHIFT) .renderer(() -> SplitShaftRenderer::new) - .onRegister(SplitShaftInstance::register) .register(); public static final TileEntityEntry ROTATION_SPEED_CONTROLLER = Create.registrate() .tileEntity("rotation_speed_controller", SpeedControllerTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.ROTATION_SPEED_CONTROLLER) .renderer(() -> SpeedControllerRenderer::new) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry SPEEDOMETER = Create.registrate() .tileEntity("speedometer", SpeedGaugeTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.SPEEDOMETER) .renderer(() -> GaugeRenderer::speed) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry STRESSOMETER = Create.registrate() .tileEntity("stressometer", StressGaugeTileEntity::new) + .instance(() -> ShaftInstance::new) .validBlocks(AllBlocks.STRESSOMETER) .renderer(() -> GaugeRenderer::stress) - .onRegister(ShaftInstance::register) .register(); public static final TileEntityEntry ANALOG_LEVER = Create.registrate() .tileEntity("analog_lever", AnalogLeverTileEntity::new) + .instance(() -> AnalogLeverInstance::new) .validBlocks(AllBlocks.ANALOG_LEVER) .renderer(() -> AnalogLeverRenderer::new) .register(); @@ -577,10 +579,10 @@ public class AllTileEntities { public static final TileEntityEntry FUNNEL = Create.registrate() .tileEntity("funnel", FunnelTileEntity::new) + .instance(() -> FunnelInstance::new) .validBlocks(AllBlocks.BRASS_FUNNEL, AllBlocks.BRASS_BELT_FUNNEL, AllBlocks.ANDESITE_FUNNEL, AllBlocks.ANDESITE_BELT_FUNNEL) .renderer(() -> FunnelRenderer::new) - .onRegister(FunnelInstance::register) .register(); public static final TileEntityEntry CONTENT_OBSERVER = Create.registrate() 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 909b380bc..8538b3411 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 @@ -10,11 +10,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class BackHalfShaftInstance extends HalfShaftInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, BackHalfShaftInstance::new)); - } - 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 6e70b9780..6002f3140 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 @@ -12,11 +12,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class HalfShaftInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new)); - } - 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 958305113..af5bfec0f 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 @@ -10,10 +10,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class HorizontalHalfShaftInstance extends HalfShaftInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new)); - } 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 dd59c1a1c..b0b2d51f6 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 @@ -80,9 +80,6 @@ public abstract class KineticTileEntity extends SmartTileEntity } super.initialize(); - - if (world != null && world.isRemote) - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); } @Override @@ -551,11 +548,6 @@ public abstract class KineticTileEntity extends SmartTileEntity } } - @Override - public void onChunkLightUpdate() { - CreateClient.kineticRenderer.onLightUpdate(this); - } - protected AxisAlignedBB cachedBoundingBox; @OnlyIn(Dist.CLIENT) public AxisAlignedBB getRenderBoundingBox() { 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 9c7e9ebee..66ae7c750 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 @@ -10,10 +10,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class ShaftlessCogInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, ShaftlessCogInstance::new)); - } 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 10f342f0a..a84f620b6 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 @@ -14,10 +14,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class SingleRotatingInstance extends KineticTileInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, SingleRotatingInstance::new)); - } protected InstanceKey rotatingModelKey; 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 e19a70e74..72b85d279 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 @@ -17,9 +17,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class DrillInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, DrillInstance::new)); } public DrillInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java index 9ea1408a7..37f2f9743 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceTileEntity.java @@ -6,7 +6,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Con import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundNBT; 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 index 5313cdbef..3cdf21954 100644 --- 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 @@ -18,10 +18,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class MechanicalCrafterInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, MechanicalCrafterInstance::new)); - } public MechanicalCrafterInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java new file mode 100644 index 000000000..cb5240516 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java @@ -0,0 +1,78 @@ +package com.simibubi.create.content.contraptions.components.crank; + +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.content.logistics.block.redstone.AnalogLeverInstance; +import com.simibubi.create.content.logistics.block.redstone.AnalogLeverTileEntity; +import com.simibubi.create.foundation.render.backend.RenderMaterials; +import com.simibubi.create.foundation.render.backend.instancing.*; +import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.MatrixStacker; +import net.minecraft.block.Block; +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 HandCrankInstance extends SingleRotatingInstance implements ITickableInstance { + + private InstanceKey crank; + private Direction facing; + + public HandCrankInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + super.init(); + + Block block = lastState.getBlock(); + AllBlockPartials renderedHandle = null; + if (block instanceof HandCrankBlock) + renderedHandle = ((HandCrankBlock) block).getRenderedHandle(); + if (renderedHandle == null) + return; + + facing = lastState.get(BlockStateProperties.FACING); + InstancedModel model = renderedHandle.renderOnDirectionalSouthModel(modelManager, lastState, facing.getOpposite()); + crank = model.createInstance(); + + updateLight(); + } + + @Override + public void tick() { + if (crank == null) return; + + HandCrankTileEntity crankTile = (HandCrankTileEntity) tile; + + Direction.Axis axis = facing.getAxis(); + float angle = (crankTile.independentAngle + AnimationTickHolder.getPartialTicks() * crankTile.chasingVelocity) / 360; + + MatrixStack ms = new MatrixStack(); + MatrixStacker.of(ms) + .translate(getFloatingPos()) + .centre() + .rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis), angle) + .unCentre(); + + crank.getInstance().setTransformNoCopy(ms); + } + + @Override + public void remove() { + super.remove(); + if (crank != null) crank.delete(); + } + + @Override + public void updateLight() { + super.updateLight(); + if (crank != null) relight(pos, crank.getInstance()); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java index ea2fbbda4..cf56281a5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankRenderer.java @@ -8,6 +8,7 @@ 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 net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -26,6 +27,8 @@ public class HandCrankRenderer extends KineticTileEntityRenderer { int light, int overlay) { super.renderSafe(te, partialTicks, ms, buffer, light, overlay); + if (FastRenderDispatcher.available(te.getWorld())) return; + BlockState state = te.getBlockState(); Block block = state.getBlock(); AllBlockPartials renderedHandle = null; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index 5e2aa0f7c..77f819913 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -20,10 +20,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class FanInstance extends KineticTileInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, FanInstance::new)); - } protected InstanceKey shaft; protected InstanceKey fan; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index 267e05572..0e8ff918d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -30,10 +30,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class FlyWheelInstance extends KineticTileInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, FlyWheelInstance::new)); - } protected Direction facing; protected boolean connectedLeft; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java index dcffdd401..297016881 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java @@ -20,10 +20,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class EngineInstance extends TileEntityInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, EngineInstance::new)); - } protected InstanceKey frame; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java index b14e7e47e..c2004404a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineTileEntity.java @@ -104,16 +104,4 @@ public class EngineTileEntity extends SmartTileEntity implements IInstanceRender poweredWheel.setRotation(appliedSpeed, appliedCapacity); } - @Override - public void onChunkLightUpdate() { - CreateClient.kineticRenderer.onLightUpdate(this); - } - - @Override - public void initialize() { - super.initialize(); - - DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); - } - } 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 8bc4b2541..64f667c1b 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 @@ -13,9 +13,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class MillStoneCogInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, MillStoneCogInstance::new)); } public MillStoneCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java index 4beadc933..0f49c8eb6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java @@ -21,10 +21,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class MixerInstance extends ShaftlessCogInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, MixerInstance::new)); - } private InstanceKey mixerHead; private InstanceKey mixerPole; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java index 53084bef4..8c4c1b89e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java @@ -18,10 +18,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class PressInstance extends ShaftInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, PressInstance::new)); - } private InstanceKey pressHead; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java index 5771f4ec5..7cff62d3a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -17,10 +17,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class SawInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, SawInstance::new)); - } public SawInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java index 4f5becd7c..b8ea44bf2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java @@ -16,10 +16,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class StickerInstance extends TileEntityInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, StickerInstance::new)); - } float lastOffset = Float.NaN; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java index 8d0886951..7a706797d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerTileEntity.java @@ -10,8 +10,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.glu import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -43,7 +43,6 @@ public class StickerTileEntity extends SmartTileEntity implements IInstanceRende if (!world.isRemote) return; piston.startWithValue(isBlockStateExtended() ? 1 : 0); - CreateClient.kineticRenderer.add(this); } public boolean isBlockStateExtended() { @@ -94,8 +93,4 @@ public class StickerTileEntity extends SmartTileEntity implements IInstanceRende 0.35F, attach ? 0.75F : 0.2f); } - @Override - public void onChunkLightUpdate() { - CreateClient.kineticRenderer.onLightUpdate(this); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java index c6d2b13a3..0d86bdd9a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java @@ -23,10 +23,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class GantryCarriageInstance extends ShaftInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, GantryCarriageInstance::new)); - } private InstanceKey gantryCogs; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java index efded06cf..507eefc09 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PipeConnection.java @@ -10,7 +10,7 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.Minecraft; 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 e4b699c89..b65306165 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 @@ -13,10 +13,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class PumpCogInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, PumpCogInstance::new)); - } public PumpCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java index 821d5f4ca..c57d228e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpTileEntity.java @@ -19,8 +19,8 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import com.simibubi.create.foundation.utility.Pair; import net.minecraft.block.BlockState; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java index 5745d4c1d..0fd820231 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/HosePulleyTileEntity.java @@ -6,7 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.ServerSpeedProvider; import net.minecraft.nbt.CompoundNBT; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveTileEntity.java index 72e0d86bf..90ac9dd51 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveTileEntity.java @@ -6,8 +6,8 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.fluids.pipes.StraightPipeTileEntity.StraightPipeFluidTransportBehaviour; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import net.minecraft.block.BlockState; import net.minecraft.nbt.CompoundNBT; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/TransparentStraightPipeRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/TransparentStraightPipeRenderer.java index 243cc52d7..5fc575317 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/TransparentStraightPipeRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/TransparentStraightPipeRenderer.java @@ -7,7 +7,7 @@ import com.simibubi.create.foundation.fluid.FluidRenderer; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java index 726f9fdc0..541ecbb6e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntity.java @@ -30,8 +30,8 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.IntAttached; import com.simibubi.create.foundation.utility.Iterate; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java index c422b9699..611c523be 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java @@ -10,8 +10,8 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; 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 50b15124a..c318d18ed 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 @@ -26,10 +26,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class BeltInstance extends KineticTileInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, BeltInstance::new)); - } private boolean upward; private boolean diagonal; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index a55c23825..49f3725d2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -23,6 +23,7 @@ import com.simibubi.create.content.contraptions.relays.belt.transport.ItemHandle import com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack; import com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelTileEntity; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; +import com.simibubi.create.foundation.render.backend.light.ILightListener; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour; @@ -56,7 +57,7 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; -public class BeltTileEntity extends KineticTileEntity { +public class BeltTileEntity extends KineticTileEntity implements ILightListener { public Map passengers; public Optional color; @@ -515,7 +516,6 @@ public class BeltTileEntity extends KineticTileEntity { @Override public void onChunkLightUpdate() { - super.onChunkLightUpdate(); updateLight(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java index 5902bb44a..864c58572 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/transport/BeltMovementHandler.java @@ -133,11 +133,12 @@ public class BeltMovementHandler { movement = movement.add(0, -Math.abs(axis.getCoordinate(movement.x, movement.y, movement.z)), 0); Vec3d centering = new Vec3d(centeringDirection).scale(diffCenter * Math.min(Math.abs(movementSpeed), .1f) * 4); - movement = movement.add(centering); - float step = entityIn.stepHeight; - if (!isPlayer) + + if (!isPlayer) { + movement = movement.add(centering); entityIn.stepHeight = 1; + } // Entity Collisions if (Math.abs(movementSpeed) < .5f) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index de4093d09..9805e7f05 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -12,11 +12,6 @@ import net.minecraftforge.fml.DistExecutor; public class ShaftInstance extends SingleRotatingInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, ShaftInstance::new)); - } - public ShaftInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); } 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 be7574bbc..8547400b6 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 @@ -19,10 +19,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class SplitShaftInstance extends KineticTileInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, SplitShaftInstance::new)); - } protected ArrayList> keys; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index 9be02d612..60c4ec81f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -21,10 +21,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; public class GearboxInstance extends KineticTileInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, GearboxInstance::new)); - } protected EnumMap> keys; protected Direction sourceFacing; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java index b22a8437c..31b3dd558 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java @@ -18,10 +18,7 @@ import java.util.EnumMap; import java.util.Map; public class BeltTunnelInstance extends TileEntityInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, BeltTunnelInstance::new)); - } + private Map>> tunnelFlaps; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java index c6e805287..943b9eb69 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java @@ -154,8 +154,6 @@ public class BeltTunnelTileEntity extends SmartTileEntity implements IInstanceRe public void initialize() { super.initialize(); updateTunnelConnections(); - if (world != null && world.isRemote) - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); } @Override @@ -198,9 +196,4 @@ public class BeltTunnelTileEntity extends SmartTileEntity implements IInstanceRe } return this.cap.cast(); } - - @Override - public void onChunkLightUpdate() { - CreateClient.kineticRenderer.onLightUpdate(this); - } } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java index ca6283483..693e045b7 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java @@ -14,10 +14,6 @@ import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; public class FunnelInstance extends TileEntityInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, FunnelInstance::new)); - } private ArrayList> flaps; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java index c4d0516a1..63cf669d5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java @@ -386,16 +386,4 @@ public class FunnelTileEntity extends SmartTileEntity implements IHaveHoveringIn TooltipHelper.addHint(tooltip, "hint.horizontal_funnel"); return true; } - - @Override - public void initialize() { - super.initialize(); - if (world != null && world.isRemote) - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); - } - - @Override - public void onChunkLightUpdate() { - CreateClient.kineticRenderer.onLightUpdate(this); - } } 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 e4e00e69c..c8a527490 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 @@ -29,10 +29,7 @@ import java.util.ArrayList; import java.util.stream.Stream; public class ArmInstance extends SingleRotatingInstance implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, ArmInstance::new)); - } + private InstanceKey base; private InstanceKey lowerBody; private InstanceKey upperBody; @@ -67,6 +64,7 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst clawGrips = Lists.newArrayList(clawGrip1, clawGrip2); models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2); + firstTick = true; tick(); updateLight(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index f7f6fb803..ab7aaf009 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -77,12 +77,16 @@ public class ArmTileEntity extends KineticTileEntity { interactionPointTag = new ListNBT(); heldItem = ItemStack.EMPTY; phase = Phase.SEARCH_INPUTS; - baseAngle = new InterpolatedAngle(); - lowerArmAngle = new InterpolatedAngle(); - upperArmAngle = new InterpolatedAngle(); - headAngle = new InterpolatedAngle(); - clawAngle = new InterpolatedAngle(); previousTarget = ArmAngleTarget.NO_TARGET; + baseAngle = new InterpolatedAngle(); + baseAngle.set(previousTarget.baseAngle); + lowerArmAngle = new InterpolatedAngle(); + lowerArmAngle.set(previousTarget.lowerArmAngle); + upperArmAngle = new InterpolatedAngle(); + upperArmAngle.set(previousTarget.upperArmAngle); + headAngle = new InterpolatedAngle(); + headAngle.set(previousTarget.headAngle); + clawAngle = new InterpolatedAngle(); previousBaseAngle = previousTarget.baseAngle; updateInteractionPoints = true; redstoneLocked = false; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java new file mode 100644 index 000000000..b14a2cef2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java @@ -0,0 +1,93 @@ +package com.simibubi.create.content.logistics.block.redstone; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.components.flywheel.FlyWheelInstance; +import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; +import com.simibubi.create.foundation.render.backend.RenderMaterials; +import com.simibubi.create.foundation.render.backend.instancing.*; +import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; +import net.minecraft.state.properties.AttachFace; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +public class AnalogLeverInstance extends TileEntityInstance implements ITickableInstance { + + protected InstanceKey handle; + protected InstanceKey indicator; + + private float rX; + private float rY; + + public AnalogLeverInstance(InstancedTileRenderer modelManager, AnalogLeverTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); + + handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, lastState).createInstance(); + indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, lastState).createInstance(); + + AttachFace face = lastState.get(AnalogLeverBlock.FACE); + rX = face == AttachFace.FLOOR ? 0 : face == AttachFace.WALL ? 90 : 180; + rY = AngleHelper.horizontalAngle(lastState.get(AnalogLeverBlock.HORIZONTAL_FACING)); + + setupModel(); + updateLight(); + } + + @Override + public void tick() { + if (!tile.clientState.settled()) + setupModel(); + } + + protected void setupModel() { + MatrixStack ms = new MatrixStack(); + MatrixStacker msr = MatrixStacker.of(ms); + + msr.translate(getFloatingPos()); + transform(msr); + + float state = tile.clientState.get(AnimationTickHolder.getPartialTicks()); + + int color = ColorHelper.mixColors(0x2C0300, 0xCD0000, state / 15f); + indicator.getInstance() + .setTransform(ms) + .setColor(color); + + float angle = (float) ((state / 15) * 90 / 180 * Math.PI); + msr.translate(1 / 2f, 1 / 16f, 1 / 2f) + .rotate(Direction.EAST, angle) + .translate(-1 / 2f, -1 / 16f, -1 / 2f); + + handle.getInstance() + .setTransformNoCopy(ms); + } + + @Override + public void remove() { + handle.delete(); + indicator.delete(); + } + + @Override + public void updateLight() { + relight(pos, handle.getInstance(), indicator.getInstance()); + } + + private void transform(MatrixStacker msr) { + msr.centre() + .rotate(Direction.UP, (float) (rY / 180 * Math.PI)) + .rotate(Direction.EAST, (float) (rX / 180 * Math.PI)) + .unCentre(); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java index 7ed7acc93..cbde2d0e5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.ColorHelper; @@ -25,6 +26,9 @@ public class AnalogLeverRenderer extends SafeTileEntityRenderer implements ITickableInstance { - public static void register(TileEntityType type) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> - InstancedTileRenderRegistry.instance.register(type, SchematicannonInstance::new)); - } private InstanceKey connector; private InstanceKey pipe; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java index b6da0bd34..77b8d69f4 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonTileEntity.java @@ -937,18 +937,6 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC findInventories(); } - @Override - public void initialize() { - super.initialize(); - - DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); - } - - @Override - public void onChunkLightUpdate() { - CreateClient.kineticRenderer.onLightUpdate(this); - } - @Override public boolean shouldRenderAsTE() { return true; diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java index e3e37f4f4..e2c2f97be 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java @@ -19,10 +19,7 @@ import com.simibubi.create.foundation.block.connected.CTModel; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; import com.simibubi.create.foundation.block.render.CustomRenderedItemModel; import com.tterrag.registrate.AbstractRegistrate; -import com.tterrag.registrate.builders.BlockBuilder; -import com.tterrag.registrate.builders.Builder; -import com.tterrag.registrate.builders.FluidBuilder; -import com.tterrag.registrate.builders.ItemBuilder; +import com.tterrag.registrate.builders.*; import com.tterrag.registrate.util.NonNullLazyValue; import com.tterrag.registrate.util.entry.RegistryEntry; import com.tterrag.registrate.util.nullness.NonNullBiFunction; @@ -38,6 +35,8 @@ import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.IItemProvider; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -109,6 +108,17 @@ public class CreateRegistrate extends AbstractRegistrate { .collect(Collectors.toList()); } + public CreateTileEntityBuilder tileEntity(String name, NonNullFunction, ? extends T> factory) { + return this.tileEntity(this.self(), name, (NonNullFunction)factory); + } + + @Override + public CreateTileEntityBuilder tileEntity(P parent, String name, NonNullFunction, ? extends T> factory) { + return (CreateTileEntityBuilder) this.entry(name, (callback) -> { + return CreateTileEntityBuilder.create(this, parent, name, callback, factory); + }); + } + /* Palettes */ public BlockBuilder baseBlock(String name, diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java b/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java new file mode 100644 index 000000000..c4aaba34a --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java @@ -0,0 +1,57 @@ +package com.simibubi.create.foundation.data; + +import com.simibubi.create.CreateClient; +import com.simibubi.create.content.logistics.block.redstone.AnalogLeverInstance; +import com.simibubi.create.foundation.render.backend.instancing.IRendererFactory; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; +import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.builders.BuilderCallback; +import com.tterrag.registrate.builders.TileEntityBuilder; +import com.tterrag.registrate.util.OneTimeEventReceiver; +import com.tterrag.registrate.util.nullness.NonNullFunction; +import com.tterrag.registrate.util.nullness.NonNullSupplier; +import net.minecraft.client.renderer.tileentity.TileEntityRenderer; +import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; + +import javax.annotation.Nullable; +import java.util.function.Function; + +public class CreateTileEntityBuilder extends TileEntityBuilder { + + @Nullable + private NonNullSupplier> instanceFactory; + + public static TileEntityBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, NonNullFunction, ? extends T> factory) { + return new CreateTileEntityBuilder<>(owner, parent, name, callback, factory); + } + + protected CreateTileEntityBuilder(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, NonNullFunction, ? extends T> factory) { + super(owner, parent, name, callback, factory); + } + + public CreateTileEntityBuilder instance(NonNullSupplier> instanceFactory) { + if (this.instanceFactory == null) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> this::registerInstance); + } + + this.instanceFactory = instanceFactory; + + return this; + } + + protected void registerInstance() { + OneTimeEventReceiver.addModListener(FMLClientSetupEvent.class, ($) -> { + NonNullSupplier> instanceFactory = this.instanceFactory; + if (instanceFactory != null) { + InstancedTileRenderRegistry.instance.register(getEntry(), instanceFactory.get()); + } + + }); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java index fd3982b1b..1ce2335c8 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java @@ -11,7 +11,7 @@ import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java b/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java index dbecc7e51..af19f8fda 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ScreenOpener.java @@ -8,7 +8,7 @@ import java.util.Optional; import javax.annotation.Nullable; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/AddRemoveTileMixin.java similarity index 81% rename from src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/AddRemoveTileMixin.java index 355f9426a..d20b076ec 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/OnRemoveTileMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/AddRemoveTileMixin.java @@ -6,6 +6,7 @@ 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.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import com.simibubi.create.CreateClient; @@ -18,7 +19,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) @Mixin(World.class) -public class OnRemoveTileMixin { +public class AddRemoveTileMixin { @Shadow @Final public boolean isRemote; @@ -31,4 +32,9 @@ public class OnRemoveTileMixin { private void onRemoveTile(BlockPos pos, CallbackInfo ci, TileEntity te) { if (isRemote) CreateClient.kineticRenderer.remove(te); } + + @Inject(at = @At("TAIL"), method = "addTileEntity") + private void onAddTile(TileEntity te, CallbackInfoReturnable cir) { + if (isRemote) CreateClient.kineticRenderer.queueAdd(te); + } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java index e2b97b148..1636c95bb 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java @@ -2,6 +2,7 @@ package com.simibubi.create.foundation.mixin; import java.util.Map; +import com.simibubi.create.CreateClient; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -42,10 +43,12 @@ public abstract class LightUpdateMixin extends AbstractChunkProvider { .entrySet() .stream() .filter(entry -> SectionPos.toChunk(entry.getKey().getY()) == sectionY) - .map(Map.Entry::getValue) - .filter(tile -> tile instanceof ILightListener) - .map(tile -> (ILightListener) tile) - .forEach(ILightListener::onChunkLightUpdate); + .map(Map.Entry::getValue).forEach(tile -> { + CreateClient.kineticRenderer.onLightUpdate(tile); + + if (tile instanceof ILightListener) + ((ILightListener) tile).onChunkLightUpdate(); + }); } ContraptionRenderDispatcher.notifyLightUpdate((ILightReader) thi.getWorld(), type, pos); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java index dd2863865..a1b43fe7f 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundHandler; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java index 592e50574..b513d40cc 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderScene.java @@ -26,7 +26,7 @@ import com.simibubi.create.foundation.ponder.elements.WorldSectionElement; import com.simibubi.create.foundation.ponder.instructions.HideAllInstruction; import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.VecHelper; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java index 2f1abec45..d992305cf 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderTooltipHandler.java @@ -7,10 +7,9 @@ import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.ponder.content.PonderIndexScreen; import com.simibubi.create.foundation.ponder.content.PonderTagScreen; -import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Lang; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java index 07f36ba04..f4f9d5d38 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java @@ -27,8 +27,8 @@ import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.foundation.utility.Pointing; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedOverlayElement.java b/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedOverlayElement.java index ef2950bf0..8f2fc1375 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedOverlayElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedOverlayElement.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.ponder.elements; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.ponder.PonderUI; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; public abstract class AnimatedOverlayElement extends PonderOverlayElement { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedSceneElement.java b/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedSceneElement.java index 4c98c08aa..dbfb882d7 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedSceneElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/elements/AnimatedSceneElement.java @@ -2,7 +2,7 @@ package com.simibubi.create.foundation.ponder.elements; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.ponder.PonderWorld; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.client.renderer.IRenderTypeBuffer; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/instructions/RotateSceneInstruction.java b/src/main/java/com/simibubi/create/foundation/ponder/instructions/RotateSceneInstruction.java index 04c49d793..9edec76fc 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/instructions/RotateSceneInstruction.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/instructions/RotateSceneInstruction.java @@ -3,7 +3,7 @@ package com.simibubi.create.foundation.ponder.instructions; import com.simibubi.create.foundation.ponder.PonderInstruction; import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.ponder.PonderScene.SceneTransform; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; public class RotateSceneInstruction extends PonderInstruction { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java b/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java index defd97deb..c60da8df9 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java @@ -8,7 +8,7 @@ import com.simibubi.create.foundation.gui.IScreenRenderable; import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; import com.simibubi.create.foundation.ponder.PonderUI; import com.simibubi.create.foundation.utility.ColorHelper; -import com.simibubi.create.foundation.utility.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java index a1558446f..05f3f35b5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IInstanceRendered.java @@ -1,8 +1,6 @@ package com.simibubi.create.foundation.render.backend.instancing; -import com.simibubi.create.foundation.render.backend.light.ILightListener; - -public interface IInstanceRendered extends ILightListener { +public interface IInstanceRendered { default boolean shouldRenderAsTE() { return false; } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index ef3a3aeea..21131fe32 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -19,6 +19,8 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.World; public abstract class InstancedTileRenderer

{ + protected ArrayList queuedAdditions = new ArrayList<>(64); + protected Map> instances = new HashMap<>(); protected Map tickableInstances = new HashMap<>(); @@ -44,6 +46,8 @@ public abstract class InstancedTileRenderer

{ } public void beginFrame(double cameraX, double cameraY, double cameraZ) { + queuedAdditions.forEach(this::add); + queuedAdditions.clear(); tickableInstances.values().forEach(ITickableInstance::tick); } @@ -112,6 +116,12 @@ public abstract class InstancedTileRenderer

{ } } + public void queueAdd(T tile) { + if (!Backend.canUseInstancing()) return; + + queuedAdditions.add(tile); + } + public void update(T tile) { if (!Backend.canUseInstancing()) return; diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java index 32537476e..4e029f184 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java @@ -1,8 +1,10 @@ package com.simibubi.create.foundation.render.backend.instancing; +import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.LightType; import net.minecraft.world.World; public abstract class TileEntityInstance { @@ -57,4 +59,14 @@ public abstract class TileEntityInstance { public BlockPos getFloatingPos() { return pos.subtract(modelManager.getOriginCoordinate()); } + + protected void relight(BlockPos pos, ModelData... models) { + relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models); + } + + protected void relight(int block, int sky, ModelData... models) { + for (ModelData model : models) { + model.setBlockLight(block).setSkyLight(sky); + } + } } diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java index cabc60556..8775f16d3 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/fluid/SmartFluidTankBehaviour.java @@ -9,8 +9,8 @@ import com.simibubi.create.foundation.fluid.SmartFluidTank; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType; -import com.simibubi.create.foundation.utility.LerpedFloat; -import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; +import com.simibubi.create.foundation.utility.animation.LerpedFloat; +import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser; import com.simibubi.create.foundation.utility.NBTHelper; import net.minecraft.nbt.CompoundNBT; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/scrollvalue/ScrollValueHandler.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/scrollvalue/ScrollValueHandler.java index 53b75af03..52b6ddf8e 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/scrollvalue/ScrollValueHandler.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/scrollvalue/ScrollValueHandler.java @@ -7,7 +7,7 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour.StepContext; -import com.simibubi.create.foundation.utility.PhysicalFloat; +import com.simibubi.create.foundation.utility.animation.PhysicalFloat; import net.minecraft.client.Minecraft; import net.minecraft.client.world.ClientWorld; import net.minecraft.util.math.BlockPos; @@ -24,7 +24,7 @@ public class ScrollValueHandler { private static float lastPassiveScroll = 0.0f; private static float passiveScroll = 0.0f; private static float passiveScrollDirection = 1f; - private static final PhysicalFloat wrenchCog = PhysicalFloat.create().withDrag(0.7); + private static final PhysicalFloat wrenchCog = PhysicalFloat.create().withDrag(0.3); @OnlyIn(Dist.CLIENT) public static boolean onScroll(double delta) { @@ -43,8 +43,8 @@ public class ScrollValueHandler { if (!mc.player.isAllowEdit()) return false; - passiveScrollDirection = (float) delta; - wrenchCog.bump(3, delta * 10); + passiveScrollDirection = (float) -delta; + wrenchCog.bump(3, -delta * 10); if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getHeldItemMainhand())) return false; diff --git a/src/main/java/com/simibubi/create/foundation/utility/PhysicalFloat.java b/src/main/java/com/simibubi/create/foundation/utility/PhysicalFloat.java deleted file mode 100644 index 6328db6c2..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/PhysicalFloat.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.simibubi.create.foundation.utility; - -import net.minecraft.util.math.MathHelper; - -import java.util.ArrayList; - -public class PhysicalFloat { - - float previousValue; - float value; - - float speed; - - private final ArrayList forces = new ArrayList<>(); - - public static PhysicalFloat create() { - return new PhysicalFloat(); - } - - public PhysicalFloat startAt(double value) { - previousValue = this.value = (float) value; - return this; - } - - public PhysicalFloat withDrag(double drag) { - return addForce(new DragForce((float) drag)); - } - - public PhysicalFloat zeroing(double g) { - return addForce(new ZeroingForce((float) g)); - } - - public void tick() { - previousValue = value; - - for (Force force : forces) - speed = force.apply(speed, value); - - forces.removeIf(Force::finished); - - value += speed; - } - - public PhysicalFloat addForce(Force f) { - forces.add(f); - return this; - } - - public PhysicalFloat bump(double force) { - return addForce(new Impulse((float) force)); - } - - public PhysicalFloat bump(int time, double force) { - return addForce(new ForceOverTime(time, (float) force)); - } - - public float getValue() { - return getValue(1); - } - - public float getValue(float partialTicks) { - return MathHelper.lerp(partialTicks, previousValue, value); - } - - public interface Force { - - float apply(float speed, float value); - - boolean finished(); - } - - public static class DragForce implements Force { - final float dragFactor; - - public DragForce(float dragFactor) { - this.dragFactor = dragFactor; - } - - @Override - public float apply(float speed, float value) { - return speed * dragFactor; - } - - @Override - public boolean finished() { - return false; - } - } - - public static class ZeroingForce implements Force { - final float g; - - public ZeroingForce(float g) { - this.g = g; - } - - @Override - public float apply(float speed, float value) { - return speed - MathHelper.clamp(g * Math.signum(value), -speed, speed); - } - - @Override - public boolean finished() { - return false; - } - } - - public static class Impulse implements Force { - - float force; - - public Impulse(float force) { - this.force = force; - } - - @Override - public float apply(float speed, float value) { - return speed + force; - } - - @Override - public boolean finished() { - return true; - } - } - - public static class ForceOverTime implements Force { - int timeRemaining; - float accel; - - public ForceOverTime(int time, float totalAcceleration) { - this.timeRemaining = time; - this.accel = totalAcceleration / (float) time; - } - - @Override - public float apply(float speed, float value) { - timeRemaining--; - return speed + accel; - } - - @Override - public boolean finished() { - return timeRemaining <= 0; - } - } -} diff --git a/src/main/java/com/simibubi/create/foundation/utility/animation/Force.java b/src/main/java/com/simibubi/create/foundation/utility/animation/Force.java new file mode 100644 index 000000000..23e7d0080 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/Force.java @@ -0,0 +1,84 @@ +package com.simibubi.create.foundation.utility.animation; + +public interface Force { + + float get(float mass, float value, float speed); + + boolean finished(); + + class Drag implements Force { + final float dragFactor; + + public Drag(float dragFactor) { + this.dragFactor = dragFactor; + } + + @Override + public float get(float mass, float value, float speed) { + return -speed * dragFactor; + } + + @Override + public boolean finished() { + return false; + } + } + + class Zeroing implements Force { + final float g; + + public Zeroing(float g) { + this.g = g / 20; + } + + @Override + public float get(float mass, float value, float speed) { + return -Math.signum(value) * g * mass; + } + + @Override + public boolean finished() { + return false; + } + } + + class Impulse implements Force { + + float force; + + public Impulse(float force) { + this.force = force; + } + + @Override + public float get(float mass, float value, float speed) { + return force; + } + + @Override + public boolean finished() { + return true; + } + } + + class OverTime implements Force { + int timeRemaining; + float f; + + public OverTime(int time, float totalAcceleration) { + this.timeRemaining = time; + this.f = totalAcceleration / (float) time; + } + + @Override + public float get(float mass, float value, float speed) { + timeRemaining--; + return f; + } + + @Override + public boolean finished() { + return timeRemaining <= 0; + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/LerpedFloat.java b/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/utility/LerpedFloat.java rename to src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java index 4c7b4fec4..b0f22f545 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/LerpedFloat.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java @@ -1,5 +1,6 @@ -package com.simibubi.create.foundation.utility; +package com.simibubi.create.foundation.utility.animation; +import com.simibubi.create.foundation.utility.AngleHelper; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.MathHelper; diff --git a/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java b/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java new file mode 100644 index 000000000..a710d8525 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java @@ -0,0 +1,80 @@ +package com.simibubi.create.foundation.utility.animation; + +import net.minecraft.util.math.MathHelper; + +import java.util.ArrayList; + +public class PhysicalFloat { + + float previousValue; + float value; + + float previousSpeed; + float speed; + + float mass; + + private final ArrayList forces = new ArrayList<>(); + + public static PhysicalFloat create() { + return new PhysicalFloat(1); + } + + public static PhysicalFloat create(float mass) { + return new PhysicalFloat(mass); + } + + public PhysicalFloat(float mass) { + this.mass = mass; + } + + public PhysicalFloat startAt(double value) { + previousValue = this.value = (float) value; + return this; + } + + public PhysicalFloat withDrag(double drag) { + return addForce(new Force.Drag((float) drag)); + } + + public PhysicalFloat zeroing(double g) { + return addForce(new Force.Zeroing((float) g)); + } + + public void tick() { + previousSpeed = speed; + previousValue = value; + + float totalImpulse = 0; + for (Force force : forces) + totalImpulse += force.get(mass, value, speed) / mass; + + speed += totalImpulse; + + forces.removeIf(Force::finished); + + value += speed; + } + + public PhysicalFloat addForce(Force f) { + forces.add(f); + return this; + } + + public PhysicalFloat bump(double force) { + return addForce(new Force.Impulse((float) force)); + } + + public PhysicalFloat bump(int time, double force) { + return addForce(new Force.OverTime(time, (float) force)); + } + + public float getValue() { + return getValue(1); + } + + public float getValue(float partialTicks) { + return MathHelper.lerp(partialTicks, previousValue, value); + } + +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 6956226de..37137f8a6 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -4,7 +4,7 @@ "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", "client": [ - "OnRemoveTileMixin", + "AddRemoveTileMixin", "ShaderCloseMixin", "CancelTileEntityRenderMixin", "LightUpdateMixin",