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 #6849

Open
wants to merge 7 commits into
base: mc1.18/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
4 changes: 2 additions & 2 deletions src/generated/resources/.cache/cache
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ bf2b0310500213ff853c748c236eb5d01f61658e assets/create/blockstates/yellow_toolbo
5616dda664dd106d576848124fc0fc1de18d0fd3 assets/create/blockstates/yellow_valve_handle.json
7f39521b211441f5c3e06d60c5978cebe16cacfb assets/create/blockstates/zinc_block.json
b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json
3c04d30f0521554ade532f1662cdaf4ae2958ab3 assets/create/lang/en_ud.json
6a0df005c7594667d9c7582a877984d25382df7b assets/create/lang/en_us.json
82ed4a747f58fc0435f52fff39b7ea1579147d04 assets/create/lang/en_ud.json
f8a82ca4b8aee16b3ba754016e1994766251fc56 assets/create/lang/en_us.json
487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json
b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.json
3066db1bf03cffa1a9c7fbacf47ae586632f4eb3 assets/create/models/block/acacia_window_pane_noside_alt.json
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/create/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,7 @@
"create.track_signal.cannot_change_mode": "\u05DF\u0250ub\u0131S s\u0131\u0265\u0287 \u025Fo \u01DDpo\u026F \u0265\u0254\u0287\u0131\u028Ds o\u0287 \u01DD\u05DFq\u0250u\u2229",
"create.track_signal.mode_change.cross_signal": "\u01DD\u05DFq\u0250s\u0279\u01DD\u028C\u0250\u0279\u0287 \u028E\u05DF\u05DFn\u025F uo\u0131\u0287\u0254\u01DDs \u025F\u0131 \u01DDb\u0250ss\u0250d \u028Do\u05DF\u05DF\u2C6F >-",
"create.track_signal.mode_change.entry_signal": "p\u01DD\u0131dn\u0254\u0254oun uo\u0131\u0287\u0254\u01DDs \u025F\u0131 \u01DDb\u0250ss\u0250d \u028Do\u05DF\u05DF\u2C6F >-",
"create.track_signal.mode_controlled_by_computer": "\u0279\u01DD\u0287nd\u026Fo\u0254 \u028Eq p\u01DD\u05DF\u05DFo\u0279\u0287uo\u0254 s\u0131 \u01DDpo\u026F \u05DF\u0250ub\u0131S",
"create.track_target.clear": "uo\u0131\u0287\u0254\u01DD\u05DF\u01DDs \u029E\u0254\u0250\u0279\u0287 p\u01DD\u0279\u0250\u01DD\u05DF\u0186",
"create.track_target.invalid": "\u01DD\u0279\u01DD\u0265 \u029E\u0254\u0250\u0279\u0287 s\u0131\u0265\u0287 \u0287\u01DDb\u0279\u0250\u0287 \u0287ouu\u0250\u0186",
"create.track_target.missing": "\u0287s\u0279\u0131\u025F \u029E\u0254\u0250\u0279\u0287 u\u0131\u0250\u0279\u0287 p\u01DD\u0287\u01DDb\u0279\u0250\u0287 \u01DD\u0265\u0287 \u029E\u0254\u0131\u05DF\u0254-\u0287\u0265b\u0131\u1D1A",
Expand Down
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 @@ -2606,6 +2606,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 @@ -156,6 +156,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_INERT = block("blaze_burner/blaze/inert"), BLAZE_SUPER_ACTIVE = block("blaze_burner/blaze/super_active"),
BLAZE_GOGGLES = block("blaze_burner/goggles"), BLAZE_GOGGLES_SMALL = block("blaze_burner/goggles_small"),
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 @@ -27,27 +42,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 " + be.getType()
.getRegistryName());
Expand All @@ -71,4 +96,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