diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java index cba6cce050..a4faf85691 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/ComputerBehaviour.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull; import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; import com.simibubi.create.compat.computercraft.events.ComputerEvent; +import com.simibubi.create.compat.computercraft.implementation.peripherals.CreativeMotorPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.DisplayLinkPeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.NixieTubePeripheral; import com.simibubi.create.compat.computercraft.implementation.peripherals.SequencedGearshiftPeripheral; @@ -17,6 +18,7 @@ import com.simibubi.create.compat.computercraft.implementation.peripherals.Synce import com.simibubi.create.compat.computercraft.implementation.peripherals.TrackObserverPeripheral; import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; +import com.simibubi.create.content.kinetics.motor.CreativeMotorBlockEntity; import com.simibubi.create.content.kinetics.speedController.SpeedControllerBlockEntity; import com.simibubi.create.content.kinetics.transmission.sequencer.SequencedGearshiftBlockEntity; import com.simibubi.create.content.redstone.displayLink.DisplayLinkBlockEntity; @@ -50,6 +52,8 @@ public class ComputerBehaviour extends AbstractComputerBehaviour { public static NonNullSupplier> getPeripheralFor(SmartBlockEntity be) { if (be instanceof SpeedControllerBlockEntity scbe) return () -> new SpeedControllerPeripheral(scbe, scbe.targetSpeed); + if (be instanceof CreativeMotorBlockEntity cmbe) + return () -> new CreativeMotorPeripheral(cmbe, cmbe.generatedSpeed); if (be instanceof DisplayLinkBlockEntity dlbe) return () -> new DisplayLinkPeripheral(dlbe); if (be instanceof NixieTubeBlockEntity ntbe) diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/CreativeMotorPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/CreativeMotorPeripheral.java new file mode 100644 index 0000000000..b64d7c4542 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/CreativeMotorPeripheral.java @@ -0,0 +1,35 @@ +package com.simibubi.create.compat.computercraft.implementation.peripherals; + +import org.jetbrains.annotations.NotNull; + +import com.simibubi.create.content.kinetics.motor.CreativeMotorBlockEntity; +import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour; + +import dan200.computercraft.api.lua.LuaFunction; + +public class CreativeMotorPeripheral extends SyncedPeripheral { + + private final ScrollValueBehaviour generatedSpeed; + + public CreativeMotorPeripheral(CreativeMotorBlockEntity blockEntity, ScrollValueBehaviour generatedSpeed) { + super(blockEntity); + this.generatedSpeed = generatedSpeed; + } + + @LuaFunction(mainThread = true) + public final void setGeneratedSpeed(int speed) { + this.generatedSpeed.setValue(speed); + } + + @LuaFunction + public final float getGeneratedSpeed() { + return this.generatedSpeed.getValue(); + } + + @NotNull + @Override + public String getType() { + return "Create_CreativeMotor"; + } + +} diff --git a/src/main/java/com/simibubi/create/content/kinetics/motor/CreativeMotorBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/motor/CreativeMotorBlockEntity.java index cdd04d0d41..c0a507523d 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/motor/CreativeMotorBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/motor/CreativeMotorBlockEntity.java @@ -2,8 +2,12 @@ package com.simibubi.create.content.kinetics.motor; import java.util.List; +import org.jetbrains.annotations.NotNull; + import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; +import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour; +import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity; import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform; @@ -20,13 +24,16 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.util.LazyOptional; public class CreativeMotorBlockEntity extends GeneratingKineticBlockEntity { public static final int DEFAULT_SPEED = 16; public static final int MAX_SPEED = 256; - protected ScrollValueBehaviour generatedSpeed; + public ScrollValueBehaviour generatedSpeed; + public AbstractComputerBehaviour computerBehaviour; public CreativeMotorBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); @@ -42,6 +49,7 @@ public class CreativeMotorBlockEntity extends GeneratingKineticBlockEntity { generatedSpeed.value = DEFAULT_SPEED; generatedSpeed.withCallback(i -> this.updateGeneratedRotation()); behaviours.add(generatedSpeed); + behaviours.add(computerBehaviour = ComputerCraftProxy.behaviour(this)); } @Override @@ -94,4 +102,17 @@ public class CreativeMotorBlockEntity extends GeneratingKineticBlockEntity { } + @Override + public @NotNull LazyOptional getCapability(@NotNull Capability cap, Direction side) { + if (computerBehaviour.isPeripheralCap(cap)) + return computerBehaviour.getPeripheralCapability(); + return super.getCapability(cap, side); + } + + @Override + public void invalidateCaps() { + super.invalidateCaps(); + computerBehaviour.removePeripheral(); + } + }