mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-03 22:34: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 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 com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity;
|
||||||
|
|
||||||
import dan200.computercraft.api.lua.LuaFunction;
|
import dan200.computercraft.api.lua.LuaFunction;
|
||||||
|
@ -17,6 +20,13 @@ public class SpeedGaugePeripheral extends SyncedPeripheral<SpeedGaugeBlockEntity
|
||||||
return this.blockEntity.getSpeed();
|
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
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.simibubi.create.compat.computercraft.implementation.peripherals;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity;
|
import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity;
|
||||||
|
@ -22,6 +25,16 @@ public class StressGaugePeripheral extends SyncedPeripheral<StressGaugeBlockEnti
|
||||||
return this.blockEntity.getNetworkCapacity();
|
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
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
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.IHaveGoggleInformation;
|
||||||
import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation;
|
import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation;
|
||||||
import com.simibubi.create.api.stress.BlockStressValues;
|
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.KineticNetwork;
|
||||||
import com.simibubi.create.content.kinetics.RotationPropagator;
|
import com.simibubi.create.content.kinetics.RotationPropagator;
|
||||||
import com.simibubi.create.content.kinetics.base.IRotate.SpeedLevel;
|
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() {
|
protected Block getStressConfigKey() {
|
||||||
return getBlockState().getBlock();
|
return getBlockState().getBlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ public class SpeedGaugeBlockEntity extends GaugeBlockEntity {
|
||||||
@Override
|
@Override
|
||||||
public void onSpeedChanged(float prevSpeed) {
|
public void onSpeedChanged(float prevSpeed) {
|
||||||
super.onSpeedChanged(prevSpeed);
|
super.onSpeedChanged(prevSpeed);
|
||||||
|
if (computerBehaviour.hasAttachedComputer())
|
||||||
|
computerBehaviour.prepareComputerEvent(makeComputerKineticsChangeEvent());
|
||||||
float speed = Math.abs(getSpeed());
|
float speed = Math.abs(getSpeed());
|
||||||
|
|
||||||
dialTarget = getDialTarget(speed);
|
dialTarget = getDialTarget(speed);
|
||||||
|
|
|
@ -48,6 +48,9 @@ public class StressGaugeBlockEntity extends GaugeBlockEntity {
|
||||||
public void updateFromNetwork(float maxStress, float currentStress, int networkSize) {
|
public void updateFromNetwork(float maxStress, float currentStress, int networkSize) {
|
||||||
super.updateFromNetwork(maxStress, currentStress, networkSize);
|
super.updateFromNetwork(maxStress, currentStress, networkSize);
|
||||||
|
|
||||||
|
if (computerBehaviour.hasAttachedComputer())
|
||||||
|
computerBehaviour.prepareComputerEvent(makeComputerKineticsChangeEvent());
|
||||||
|
|
||||||
if (!StressImpact.isEnabled())
|
if (!StressImpact.isEnabled())
|
||||||
dialTarget = 0;
|
dialTarget = 0;
|
||||||
else if (isOverStressed())
|
else if (isOverStressed())
|
||||||
|
|
Loading…
Add table
Reference in a new issue