mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-03 14:24:42 +01:00
Emit ComputerCraft events from Speedometers/Stressometers
- Emit CC event `overstressed` from Stressometers - Emit CC event `stress_change` from Stressometers - 2 arguments: stress (SU), capacity (SU) - Emit CC event `speed_change` from Speedometers - 1 argument: speed (RPM)
This commit is contained in:
parent
86fa50ca73
commit
c0a276acf7
6 changed files with 50 additions and 0 deletions
|
@ -0,0 +1,17 @@
|
|||
package com.simibubi.create.compat.computercraft.events;
|
||||
|
||||
public class KineticsChangeEvent implements ComputerEvent {
|
||||
|
||||
public float speed;
|
||||
public float capacity;
|
||||
public float stress;
|
||||
public boolean overStressed;
|
||||
|
||||
public KineticsChangeEvent(float speed, float capacity, float stress, boolean overStressed) {
|
||||
this.speed = speed;
|
||||
this.capacity = capacity;
|
||||
this.stress = stress;
|
||||
this.overStressed = overStressed;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,9 @@ package com.simibubi.create.compat.computercraft.implementation.peripherals;
|
|||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
import com.simibubi.create.compat.computercraft.events.ComputerEvent;
|
||||
import com.simibubi.create.compat.computercraft.events.KineticsChangeEvent;
|
||||
import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
|
@ -17,6 +20,13 @@ public class SpeedGaugePeripheral extends SyncedPeripheral<SpeedGaugeBlockEntity
|
|||
return this.blockEntity.getSpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareComputerEvent(@NotNull ComputerEvent event) {
|
||||
if (event instanceof KineticsChangeEvent kce) {
|
||||
queueEvent("speed_change", kce.overStressed ? 0 : kce.speed);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getType() {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.simibubi.create.compat.computercraft.implementation.peripherals;
|
||||
|
||||
import com.simibubi.create.compat.computercraft.events.ComputerEvent;
|
||||
import com.simibubi.create.compat.computercraft.events.KineticsChangeEvent;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity;
|
||||
|
@ -22,6 +25,16 @@ public class StressGaugePeripheral extends SyncedPeripheral<StressGaugeBlockEnti
|
|||
return this.blockEntity.getNetworkCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareComputerEvent(@NotNull ComputerEvent event) {
|
||||
if (event instanceof KineticsChangeEvent kce) {
|
||||
if (kce.overStressed)
|
||||
queueEvent("overstressed");
|
||||
else
|
||||
queueEvent("stress_change", kce.stress, kce.capacity);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getType() {
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.simibubi.create.Create;
|
|||
import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation;
|
||||
import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation;
|
||||
import com.simibubi.create.api.stress.BlockStressValues;
|
||||
import com.simibubi.create.compat.computercraft.events.KineticsChangeEvent;
|
||||
import com.simibubi.create.content.kinetics.KineticNetwork;
|
||||
import com.simibubi.create.content.kinetics.RotationPropagator;
|
||||
import com.simibubi.create.content.kinetics.base.IRotate.SpeedLevel;
|
||||
|
@ -164,6 +165,10 @@ public class KineticBlockEntity extends SmartBlockEntity implements IHaveGoggleI
|
|||
}
|
||||
}
|
||||
|
||||
protected KineticsChangeEvent makeComputerKineticsChangeEvent() {
|
||||
return new KineticsChangeEvent(speed, capacity, stress, overStressed);
|
||||
}
|
||||
|
||||
protected Block getStressConfigKey() {
|
||||
return getBlockState().getBlock();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public class SpeedGaugeBlockEntity extends GaugeBlockEntity {
|
|||
@Override
|
||||
public void onSpeedChanged(float prevSpeed) {
|
||||
super.onSpeedChanged(prevSpeed);
|
||||
if (computerBehaviour.hasAttachedComputer())
|
||||
computerBehaviour.prepareComputerEvent(makeComputerKineticsChangeEvent());
|
||||
float speed = Math.abs(getSpeed());
|
||||
|
||||
dialTarget = getDialTarget(speed);
|
||||
|
|
|
@ -48,6 +48,9 @@ public class StressGaugeBlockEntity extends GaugeBlockEntity {
|
|||
public void updateFromNetwork(float maxStress, float currentStress, int networkSize) {
|
||||
super.updateFromNetwork(maxStress, currentStress, networkSize);
|
||||
|
||||
if (computerBehaviour.hasAttachedComputer())
|
||||
computerBehaviour.prepareComputerEvent(makeComputerKineticsChangeEvent());
|
||||
|
||||
if (!StressImpact.isEnabled())
|
||||
dialTarget = 0;
|
||||
else if (isOverStressed())
|
||||
|
|
Loading…
Add table
Reference in a new issue