mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-08 09:34:11 +00:00
Add back MoreRed support
I removed this in fc834cd97fe941a192e40962ac3bb27be102ce09, way back in late 2024. Looks like it's been updating in the meantime and I hadn't noticed, so add it back. I've simplified the code a little bit, to make use of our NeoForge's new capability system, but otherwise it's almost exactly the same :D.
This commit is contained in:
parent
1e25fa9bc3
commit
1278246cf7
@ -48,7 +48,7 @@ repositories {
|
|||||||
includeGroup("cc.tweaked")
|
includeGroup("cc.tweaked")
|
||||||
// Things we mirror
|
// Things we mirror
|
||||||
includeGroup("com.simibubi.create")
|
includeGroup("com.simibubi.create")
|
||||||
includeGroup("commoble.morered")
|
includeGroup("net.commoble.morered")
|
||||||
includeGroup("dev.architectury")
|
includeGroup("dev.architectury")
|
||||||
includeGroup("dev.emi")
|
includeGroup("dev.emi")
|
||||||
includeGroup("maven.modrinth")
|
includeGroup("maven.modrinth")
|
||||||
|
@ -42,7 +42,7 @@ iris-fabric = "1.8.0-beta.3+1.21-fabric"
|
|||||||
iris-forge = "1.8.0-beta.3+1.21-neoforge"
|
iris-forge = "1.8.0-beta.3+1.21-neoforge"
|
||||||
jei = "19.8.2.99"
|
jei = "19.8.2.99"
|
||||||
modmenu = "11.0.0-rc.4"
|
modmenu = "11.0.0-rc.4"
|
||||||
moreRed = "4.0.0.4"
|
moreRed = "6.0.0.3"
|
||||||
rei = "16.0.729"
|
rei = "16.0.729"
|
||||||
sodium-fabric = "mc1.21-0.6.0-beta.1-fabric"
|
sodium-fabric = "mc1.21-0.6.0-beta.1-fabric"
|
||||||
sodium-forge = "mc1.21-0.6.0-beta.1-neoforge"
|
sodium-forge = "mc1.21-0.6.0-beta.1-neoforge"
|
||||||
@ -119,7 +119,7 @@ jei-forge = { module = "mezz.jei:jei-1.21-neoforge", version.ref = "jei" }
|
|||||||
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
|
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
|
||||||
mixinExtra = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinExtra" }
|
mixinExtra = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinExtra" }
|
||||||
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
|
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
|
||||||
moreRed = { module = "commoble.morered:morered-1.20.1", version.ref = "moreRed" }
|
moreRed = { module = "net.commoble.morered:morered-1.21.1", version.ref = "moreRed" }
|
||||||
rei-api = { module = "me.shedaniel:RoughlyEnoughItems-api", version.ref = "rei" }
|
rei-api = { module = "me.shedaniel:RoughlyEnoughItems-api", version.ref = "rei" }
|
||||||
rei-builtin = { module = "me.shedaniel:RoughlyEnoughItems-default-plugin", version.ref = "rei" }
|
rei-builtin = { module = "me.shedaniel:RoughlyEnoughItems-default-plugin", version.ref = "rei" }
|
||||||
rei-fabric = { module = "me.shedaniel:RoughlyEnoughItems-fabric", version.ref = "rei" }
|
rei-fabric = { module = "me.shedaniel:RoughlyEnoughItems-fabric", version.ref = "rei" }
|
||||||
|
@ -20,6 +20,7 @@ import dan200.computercraft.shared.config.Config;
|
|||||||
import dan200.computercraft.shared.config.ConfigSpec;
|
import dan200.computercraft.shared.config.ConfigSpec;
|
||||||
import dan200.computercraft.shared.details.FluidData;
|
import dan200.computercraft.shared.details.FluidData;
|
||||||
import dan200.computercraft.shared.integration.CreateIntegration;
|
import dan200.computercraft.shared.integration.CreateIntegration;
|
||||||
|
import dan200.computercraft.shared.integration.MoreRedIntegration;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
import dan200.computercraft.shared.network.NetworkMessages;
|
import dan200.computercraft.shared.network.NetworkMessages;
|
||||||
import dan200.computercraft.shared.network.client.ClientNetworkContext;
|
import dan200.computercraft.shared.network.client.ClientNetworkContext;
|
||||||
@ -70,6 +71,8 @@ public final class ComputerCraft {
|
|||||||
var container = ModLoadingContext.get().getActiveContainer();
|
var container = ModLoadingContext.get().getActiveContainer();
|
||||||
container.registerConfig(ModConfig.Type.SERVER, ((ForgeConfigFile) ConfigSpec.serverSpec).spec());
|
container.registerConfig(ModConfig.Type.SERVER, ((ForgeConfigFile) ConfigSpec.serverSpec).spec());
|
||||||
container.registerConfig(ModConfig.Type.CLIENT, ((ForgeConfigFile) ConfigSpec.clientSpec).spec());
|
container.registerConfig(ModConfig.Type.CLIENT, ((ForgeConfigFile) ConfigSpec.clientSpec).spec());
|
||||||
|
|
||||||
|
if (ModList.get().isLoaded(MoreRedIntegration.MOD_ID)) MoreRedIntegration.setup(eventBus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void withEventBus(IEventBus eventBus, Runnable task) {
|
private static void withEventBus(IEventBus eventBus, Runnable task) {
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.integration;
|
||||||
|
|
||||||
|
import commoble.morered.api.MoreRedAPI;
|
||||||
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
|
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
|
||||||
|
|
||||||
|
public final class MoreRedIntegration {
|
||||||
|
public static final String MOD_ID = "morered";
|
||||||
|
|
||||||
|
private static void onRegisterCapabilities(RegisterCapabilitiesEvent event) {
|
||||||
|
for (var block : BuiltInRegistries.BLOCK) {
|
||||||
|
if (!(block instanceof IBundledRedstoneBlock bundledBlock)) continue;
|
||||||
|
event.registerBlock(
|
||||||
|
MoreRedAPI.CHANNELED_POWER_CAPABILITY,
|
||||||
|
(level, pos, state, blockEntity, context) -> (level2, wirePos, wireState, wireFace, channel) -> {
|
||||||
|
var outputLevel = bundledBlock.getBundledRedstoneOutput(level2, pos, context);
|
||||||
|
return (outputLevel & (1 << channel)) != 0 ? 31 : 0;
|
||||||
|
},
|
||||||
|
block
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setup(IEventBus bus) {
|
||||||
|
bus.addListener(MoreRedIntegration::onRegisterCapabilities);
|
||||||
|
ComputerCraftAPI.registerBundledRedstoneProvider(MoreRedIntegration::getBundledPower);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getBundledPower(Level world, BlockPos pos, Direction side) {
|
||||||
|
var blockState = world.getBlockState(pos);
|
||||||
|
|
||||||
|
// Skip ones already handled by CC. We can do this more efficiently.
|
||||||
|
if (blockState.getBlock() instanceof IBundledRedstoneBlock) return -1;
|
||||||
|
|
||||||
|
var power = world.getCapability(MoreRedAPI.CHANNELED_POWER_CAPABILITY, pos, blockState, null, side);
|
||||||
|
if (power == null) return -1;
|
||||||
|
|
||||||
|
var mask = 0;
|
||||||
|
for (var i = 0; i < 16; i++) {
|
||||||
|
mask |= power.getPowerOnChannel(world, pos, blockState, side, i) > 0 ? (1 << i) : 0;
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user