mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-03 22:34:42 +01:00
Add ComputerCraft integration to Creative Motors
- Add CC {get,set}GeneratedSpeed() function get/set motor speed
This commit is contained in:
parent
f19d77c5ea
commit
6bdd9c1fe0
3 changed files with 61 additions and 1 deletions
|
@ -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<SyncedPeripheral<?>> 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)
|
||||
|
|
|
@ -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<CreativeMotorBlockEntity> {
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> cap, Direction side) {
|
||||
if (computerBehaviour.isPeripheralCap(cap))
|
||||
return computerBehaviour.getPeripheralCapability();
|
||||
return super.getCapability(cap, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCaps() {
|
||||
super.invalidateCaps();
|
||||
computerBehaviour.removePeripheral();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue