autodetect and support any block that is bundled redstone provider
This commit is contained in:
parent
e4f80985ec
commit
677e0c479d
@ -30,7 +30,7 @@ mod_name=More Red x CC:Tweaked Compat
|
||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=MIT
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=1.2.0
|
||||
mod_version=1.3.0
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
@ -3,8 +3,10 @@ package ru.yurannnzzz.moreredcccompat;
|
||||
import commoble.morered.api.MoreRedAPI;
|
||||
import commoble.morered.api.WireConnector;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
@ -13,7 +15,9 @@ import ru.yurannnzzz.moreredcccompat.cc.MoreRedBundledRedstoneProvider;
|
||||
import ru.yurannnzzz.moreredcccompat.morered.ComputerChanneledPowerCapability;
|
||||
import ru.yurannnzzz.moreredcccompat.morered.ComputerWireConnector;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod(MoreRedCCCompatMod.MOD_ID)
|
||||
public class MoreRedCCCompatMod {
|
||||
@ -26,24 +30,28 @@ public class MoreRedCCCompatMod {
|
||||
ComputerCraftAPI.registerBundledRedstoneProvider(new MoreRedBundledRedstoneProvider());
|
||||
}
|
||||
|
||||
private static final Map<Block, BlockEntityType<?>> BLOCKS = new HashMap<>();
|
||||
|
||||
private void registerConnectors(final FMLCommonSetupEvent event) {
|
||||
ComputerWireConnector connector = new ComputerWireConnector();
|
||||
Map<Block, WireConnector> registry = MoreRedAPI.getCableConnectabilityRegistry();
|
||||
|
||||
registry.put(ModRegistry.Blocks.COMPUTER_NORMAL.get(), connector);
|
||||
registry.put(ModRegistry.Blocks.COMPUTER_ADVANCED.get(), connector);
|
||||
registry.put(ModRegistry.Blocks.COMPUTER_COMMAND.get(), connector);
|
||||
registry.put(ModRegistry.Blocks.TURTLE_NORMAL.get(), connector);
|
||||
registry.put(ModRegistry.Blocks.TURTLE_ADVANCED.get(), connector);
|
||||
registry.put(ModRegistry.Blocks.REDSTONE_RELAY.get(), connector);
|
||||
for (Block block : BuiltInRegistries.BLOCK) {
|
||||
if (block instanceof IBundledRedstoneBlock) {
|
||||
Optional<BlockEntityType<?>> filter = BuiltInRegistries.BLOCK_ENTITY_TYPE.stream().filter(it -> it.isValid(block.defaultBlockState())).findFirst();
|
||||
|
||||
filter.ifPresent(blockEntityType -> BLOCKS.put(block, blockEntityType));
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Block, BlockEntityType<?>> entry : BLOCKS.entrySet()) {
|
||||
registry.put(entry.getKey(), connector);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCapabilities(RegisterCapabilitiesEvent event) {
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, ModRegistry.BlockEntities.COMPUTER_NORMAL.get(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, ModRegistry.BlockEntities.COMPUTER_ADVANCED.get(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, ModRegistry.BlockEntities.COMPUTER_COMMAND.get(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, ModRegistry.BlockEntities.TURTLE_NORMAL.get(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, ModRegistry.BlockEntities.TURTLE_ADVANCED.get(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, ModRegistry.BlockEntities.REDSTONE_RELAY.get(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
for (Map.Entry<Block, BlockEntityType<?>> entry : BLOCKS.entrySet()) {
|
||||
event.registerBlockEntity(MoreRedAPI.CHANNELED_POWER_CAPABILITY, entry.getValue(), (be, side) -> new ComputerChanneledPowerCapability(side));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user