mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-26 03:17:38 +00:00
Add redstone relay block (#2002)
- Move redstone methods out of the IAPIEnvironment, and into a new RedstoneAccess. We similarly move the implementation from Environment into a new RedstoneState class. The interface is possibly a little redundant (interfaces with a single implementation are always a little suspect), but it's nice to keep the consumer/producer interfaces separate. - Abstract most redstone API methods into a separate shared class, that can be used by both the rs API and the new redstone relay. - Add the new redstone relay block. The docs are probably a little lacking here, but I really struggled to write anything which wasn't just "look, it's the same as the redstone API".
This commit is contained in:
12
projects/forge/src/generated/resources/data/computercraft/recipes/redstone_relay.json
generated
Normal file
12
projects/forge/src/generated/resources/data/computercraft/recipes/redstone_relay.json
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "redstone",
|
||||
"key": {
|
||||
"C": {"item": "computercraft:wired_modem"},
|
||||
"R": {"tag": "forge:dusts/redstone"},
|
||||
"S": {"item": "minecraft:stone"}
|
||||
},
|
||||
"pattern": ["SRS", "RCR", "SRS"],
|
||||
"result": {"item": "computercraft:redstone_relay"},
|
||||
"show_notification": true
|
||||
}
|
||||
1
projects/forge/src/generated/resources/data/minecraft/tags/blocks/mineable/axe.json
generated
Normal file
1
projects/forge/src/generated/resources/data/minecraft/tags/blocks/mineable/axe.json
generated
Normal file
@@ -0,0 +1 @@
|
||||
{"values": ["computercraft:lectern"]}
|
||||
@@ -12,6 +12,7 @@
|
||||
"computercraft:wireless_modem_normal",
|
||||
"computercraft:wireless_modem_advanced",
|
||||
"computercraft:wired_modem_full",
|
||||
"computercraft:cable"
|
||||
"computercraft:cable",
|
||||
"computercraft:redstone_relay"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import dan200.computercraft.shared.peripheral.modem.wired.WiredModemFullBlockEnt
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemBlockEntity;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorBlockEntity;
|
||||
import dan200.computercraft.shared.peripheral.printer.PrinterBlockEntity;
|
||||
import dan200.computercraft.shared.peripheral.redstone.RedstoneRelayBlockEntity;
|
||||
import dan200.computercraft.shared.peripheral.speaker.SpeakerBlockEntity;
|
||||
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
|
||||
import dan200.computercraft.shared.util.CapabilityProvider;
|
||||
@@ -43,6 +44,7 @@ import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
|
||||
import static dan200.computercraft.shared.Capabilities.CAPABILITY_PERIPHERAL;
|
||||
import static dan200.computercraft.shared.Capabilities.CAPABILITY_WIRED_ELEMENT;
|
||||
import static net.minecraftforge.common.capabilities.ForgeCapabilities.ITEM_HANDLER;
|
||||
|
||||
/**
|
||||
@@ -133,15 +135,15 @@ public class ForgeCommonHooks {
|
||||
CapabilityProvider.attach(event, INVENTORY, ITEM_HANDLER, () -> new InvWrapper(diskDrive));
|
||||
CapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, diskDrive::peripheral);
|
||||
} else if (blockEntity instanceof CableBlockEntity cable) {
|
||||
var peripheralHandler = SidedCapabilityProvider.attach(event, PERIPHERAL, Capabilities.CAPABILITY_PERIPHERAL, cable::getPeripheral);
|
||||
var elementHandler = SidedCapabilityProvider.attach(event, WIRED_ELEMENT, Capabilities.CAPABILITY_WIRED_ELEMENT, cable::getWiredElement);
|
||||
var peripheralHandler = SidedCapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, cable::getPeripheral);
|
||||
var elementHandler = SidedCapabilityProvider.attach(event, WIRED_ELEMENT, CAPABILITY_WIRED_ELEMENT, cable::getWiredElement);
|
||||
cable.onModemChanged(() -> {
|
||||
peripheralHandler.invalidate();
|
||||
elementHandler.invalidate();
|
||||
});
|
||||
} else if (blockEntity instanceof WiredModemFullBlockEntity modem) {
|
||||
SidedCapabilityProvider.attach(event, PERIPHERAL, Capabilities.CAPABILITY_PERIPHERAL, modem::getPeripheral);
|
||||
CapabilityProvider.attach(event, WIRED_ELEMENT, Capabilities.CAPABILITY_WIRED_ELEMENT, modem::getElement);
|
||||
SidedCapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, modem::getPeripheral);
|
||||
CapabilityProvider.attach(event, WIRED_ELEMENT, CAPABILITY_WIRED_ELEMENT, modem::getElement);
|
||||
} else if (blockEntity instanceof WirelessModemBlockEntity modem) {
|
||||
var peripheral = SidedCapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, modem::getPeripheral);
|
||||
modem.onModemChanged(peripheral::invalidate);
|
||||
@@ -150,12 +152,14 @@ public class ForgeCommonHooks {
|
||||
} else if (blockEntity instanceof SpeakerBlockEntity speaker) {
|
||||
CapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, speaker::peripheral);
|
||||
} else if (blockEntity instanceof PrinterBlockEntity printer) {
|
||||
CapabilityProvider.attach(event, PERIPHERAL, Capabilities.CAPABILITY_PERIPHERAL, printer::peripheral);
|
||||
CapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, printer::peripheral);
|
||||
// We don't need to invalidate here as the block's can't be rotated on the X axis!
|
||||
SidedCapabilityProvider.attach(
|
||||
event, INVENTORY, ITEM_HANDLER,
|
||||
s -> s == null ? new InvWrapper(printer) : new SidedInvWrapper(printer, s)
|
||||
);
|
||||
} else if (blockEntity instanceof RedstoneRelayBlockEntity redstone) {
|
||||
CapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, redstone::peripheral);
|
||||
} else if (Config.enableCommandBlock && blockEntity instanceof CommandBlockEntity commandBlock) {
|
||||
CapabilityProvider.attach(event, PERIPHERAL, CAPABILITY_PERIPHERAL, () -> new CommandBlockPeripheral(commandBlock));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user