Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ComputerCraft integrations to more devices (1.20.1 edition) #7453

Open
wants to merge 7 commits into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/generated/resources/assets/create/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,7 @@
"create.track_signal.cannot_change_mode": "Unable to switch mode of this Signal",
"create.track_signal.mode_change.cross_signal": "-> Allow passage if section fully traversable",
"create.track_signal.mode_change.entry_signal": "-> Allow passage if section unoccupied",
"create.track_signal.mode_controlled_by_computer": "Signal mode is controlled by computer",
"create.track_target.clear": "Cleared track selection",
"create.track_target.invalid": "Cannot target this track here",
"create.track_target.missing": "Right-click the targeted train track first",
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/simibubi/create/AllPartialModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public class AllPartialModels {
SIGNAL_RED_CUBE = block("track_signal/red_cube"), SIGNAL_RED_GLOW = block("track_signal/red_glow"),
SIGNAL_RED = block("track_signal/red_tube"), SIGNAL_YELLOW_CUBE = block("track_signal/yellow_cube"),
SIGNAL_YELLOW_GLOW = block("track_signal/yellow_glow"), SIGNAL_YELLOW = block("track_signal/yellow_tube"),
SIGNAL_COMPUTER_WHITE_CUBE = block("track_signal/computer_white_cube"),
SIGNAL_COMPUTER_WHITE_GLOW = block("track_signal/computer_white_glow"),
SIGNAL_COMPUTER_WHITE = block("track_signal/computer_white_tube"),
SIGNAL_COMPUTER_WHITE_BASE = block("track_signal/computer_white_tube_base"),

BLAZE_CAGE = block("blaze_burner/block"),
BLAZE_INERT = block("blaze_burner/blaze/inert"), BLAZE_SUPER_ACTIVE = block("blaze_burner/blaze/super_active"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.simibubi.create.compat.computercraft;

import org.jetbrains.annotations.NotNull;


import com.simibubi.create.compat.computercraft.events.ComputerEvent;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BehaviourType;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
Expand Down Expand Up @@ -49,6 +53,8 @@ public boolean hasAttachedComputer() {
return hasAttachedComputer;
}

public void prepareComputerEvent(@NotNull ComputerEvent event) {}

@Override
public BehaviourType<?> getType() {
return TYPE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.simibubi.create.compat.computercraft.events;

public interface ComputerEvent {}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simibubi.create.compat.computercraft.events;

import com.simibubi.create.content.trains.signal.SignalBlockEntity;

public class SignalStateChangeEvent implements ComputerEvent {

public SignalBlockEntity.SignalState state;

public SignalStateChangeEvent(SignalBlockEntity.SignalState state) {
this.state = state;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.simibubi.create.compat.computercraft.events;

import org.jetbrains.annotations.NotNull;


import com.simibubi.create.content.trains.entity.Train;

public class StationTrainPresenceEvent implements ComputerEvent {

public enum Type {
IMMINENT("train_imminent"),
ARRIVAL("train_arrival"),
DEPARTURE("train_departure");

public final String name;

Type(String name) {
this.name = name;
}
}

public Type type;
public @NotNull Train train;

public StationTrainPresenceEvent(Type type, @NotNull Train train) {
this.type = type;
this.train = train;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.simibubi.create.compat.computercraft.events;

import org.jetbrains.annotations.NotNull;


import com.simibubi.create.content.trains.entity.Train;

public class TrainPassEvent implements ComputerEvent {

public @NotNull Train train;
public boolean passing;

public TrainPassEvent(@NotNull Train train, boolean passing) {
this.train = train;
this.passing = passing;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package com.simibubi.create.compat.computercraft.implementation;

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;
import com.simibubi.create.compat.computercraft.implementation.peripherals.SignalPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedControllerPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.SpeedGaugePeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.StationPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.StickerPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.StressGaugePeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.SyncedPeripheral;
import com.simibubi.create.compat.computercraft.implementation.peripherals.TrackObserverPeripheral;
import com.simibubi.create.content.contraptions.chassis.StickerBlockEntity;
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;
import com.simibubi.create.content.redstone.nixieTube.NixieTubeBlockEntity;
import com.simibubi.create.content.trains.observer.TrackObserverBlockEntity;
import com.simibubi.create.content.trains.signal.SignalBlockEntity;
import com.simibubi.create.content.trains.station.StationBlockEntity;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;

Expand All @@ -28,27 +43,37 @@ public class ComputerBehaviour extends AbstractComputerBehaviour {
protected static final Capability<IPeripheral> PERIPHERAL_CAPABILITY =
CapabilityManager.get(new CapabilityToken<>() {
});
LazyOptional<IPeripheral> peripheral;
NonNullSupplier<IPeripheral> peripheralSupplier;
LazyOptional<SyncedPeripheral<?>> peripheral;
NonNullSupplier<SyncedPeripheral<?>> peripheralSupplier;

public ComputerBehaviour(SmartBlockEntity te) {
super(te);
this.peripheralSupplier = getPeripheralFor(te);
}

public static NonNullSupplier<IPeripheral> getPeripheralFor(SmartBlockEntity be) {
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)
return () -> new NixieTubePeripheral(ntbe);
if (be instanceof SequencedGearshiftBlockEntity sgbe)
return () -> new SequencedGearshiftPeripheral(sgbe);
if (be instanceof SignalBlockEntity sbe)
return () -> new SignalPeripheral(sbe);
if (be instanceof SpeedGaugeBlockEntity sgbe)
return () -> new SpeedGaugePeripheral(sgbe);
if (be instanceof StressGaugeBlockEntity sgbe)
return () -> new StressGaugePeripheral(sgbe);
if (be instanceof StickerBlockEntity sbe)
return () -> new StickerPeripheral(sbe);
if (be instanceof StationBlockEntity sbe)
return () -> new StationPeripheral(sbe);
if (be instanceof TrackObserverBlockEntity tobe)
return () -> new TrackObserverPeripheral(tobe);

throw new IllegalArgumentException(
"No peripheral available for " + ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(be.getType()));
Expand All @@ -72,4 +97,10 @@ public void removePeripheral() {
peripheral.invalidate();
}

@Override
public void prepareComputerEvent(@NotNull ComputerEvent event) {
if (peripheral != null)
peripheral.ifPresent(p -> p.prepareComputerEvent(event));
}

}
Original file line number Diff line number Diff line change
@@ -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";
}

}
Loading