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

ComputerCraft and OpenComputers II integration #1785

Open
wants to merge 8 commits into
base: 1.20
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
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,27 @@ configurations {
}

repositories {
flatDir { dirs 'libs' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be here.

mavenLocal()
maven { url = "https://maven.covers1624.net/" }
maven { url = "https://dvs1.progwml6.com/files/maven" }
maven { url = "https://maven.cil.li/" }
maven { url = "https://maven.theillusivec4.top/" }
maven { url = "https://squiddev.cc/maven/" }
maven { url = "https://maven.blamejared.com/" }
maven {
url "https://maven.architectury.dev"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I would like to avoid having an arch dep. You should be able to just dep on the OC2 api, which should not require an arch dep.

content {
includeGroup 'dev.architectury'
}
}
maven {
name 'CurseMaven'
url 'https://www.cursemaven.com'
content {
includeGroup 'curse.maven'
}
}
// maven { url = "https://modmaven.dev/" }
}

Expand All @@ -85,8 +99,13 @@ dependencies {

compileOnly("cc.tweaked:cc-tweaked-${mc_version}-core-api:${cct_version}")
compileOnly(fg.deobf("cc.tweaked:cc-tweaked-${mc_version}-forge-api:${cct_version}"))
runtimeOnly(fg.deobf("cc.tweaked:cc-tweaked-${mc_version}-forge:${cct_version}"))
implementation(fg.deobf("cc.tweaked:cc-tweaked-${mc_version}-forge:${cct_version}"))

implementation fg.deobf("dev.architectury:architectury-forge:${architectury_version}")

implementation fg.deobf("curse.maven:sedna-511276:${sedna_version}")
implementation fg.deobf("curse.maven:markdownmanual-502485:${md_version}")
implementation fg.deobf("curse.maven:oc2r-1037738:${oc2_version}")
// For Testing
// runtimeOnly fg.deobf("mekanism:Mekanism:1.18.2-10.2.5.465")// core
// runtimeOnly fg.deobf("mekanism:Mekanism:1.18.2-10.2.5.465:additions")// Mekanism: Additions
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ cct_version=1.109.3
curios_version=5.4.7+1.20.1
crt_version=14.0.28
ender_storage_version=2.11.0.+
oc2_version=5544316
md_version=4873115
sedna_version=5261893
architectury_version=9.2.14
15 changes: 0 additions & 15 deletions src/main/java/com/brandon3055/draconicevolution/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@
import com.brandon3055.draconicevolution.blocks.tileentity.TileFusionCraftingCore;
import com.brandon3055.draconicevolution.blocks.tileentity.TileGenerator;
import com.brandon3055.draconicevolution.client.render.tile.fxhandlers.ITileFXHandler;
import com.brandon3055.draconicevolution.handlers.DEEventHandler;
import com.brandon3055.draconicevolution.init.DETags;
import com.brandon3055.draconicevolution.init.ModCapabilities;
import com.brandon3055.draconicevolution.integration.computers.ComputerCraftCompatEventHandler;
import com.brandon3055.draconicevolution.integration.equipment.EquipmentManager;
import com.brandon3055.draconicevolution.items.tools.Dislocator;
import com.brandon3055.draconicevolution.lib.ISidedTileHandler;
import com.brandon3055.draconicevolution.network.DraconicNetwork;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.OptionalMod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Deprecated
public class CommonProxy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import com.brandon3055.draconicevolution.command.DECommands;
import com.brandon3055.draconicevolution.handlers.*;
import com.brandon3055.draconicevolution.init.*;
import com.brandon3055.draconicevolution.integration.computers.ComputerCraftCompatEventHandler;
import com.brandon3055.draconicevolution.integration.computers.cc.ComputerCraftCompatEventHandler;
import com.brandon3055.draconicevolution.integration.equipment.EquipmentManager;
import com.brandon3055.draconicevolution.items.tools.Dislocator;
import com.brandon3055.draconicevolution.network.DraconicNetwork;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.crafting.CraftingHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.brandon3055.draconicevolution.api.capability.ModuleHost;
import com.brandon3055.draconicevolution.api.capability.ModuleProvider;
import com.brandon3055.draconicevolution.api.capability.PropertyProvider;
import com.brandon3055.draconicevolution.integration.computers.CCOCIntegration;
import net.covers1624.quack.util.CrashLock;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.eventbus.api.IEventBus;
Expand All @@ -17,7 +18,7 @@ public class ModCapabilities {

public static void init() {
LOCK.lock();

CCOCIntegration.init();
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(ModCapabilities::register);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,97 +1,27 @@
package com.brandon3055.draconicevolution.integration.computers;

import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional;
import com.brandon3055.draconicevolution.integration.computers.cc.DEPeripheralProvider;
import com.brandon3055.draconicevolution.integration.computers.oc2.OC2DeviceProvider;
import dan200.computercraft.api.ForgeComputerCraftAPI;
import net.minecraftforge.fml.ModList;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Created by brandon3055 on 21/9/2015.
*/
public class CCOCIntegration {

public static String ENERGY_PYLON = "draconic_rf_storage";
public static String FLUX_GATE = "flux_gate";
public static String FLUID_GATE = "fluid_gate";
public static String FLOW_GATE = "flow_gate";
public static String DRACONIC_REACTOR = "draconic_reactor";

public static void init() {
if (ModList.get().isLoaded("computercraft")) {
initCC();
ForgeComputerCraftAPI.registerPeripheralProvider(new DEPeripheralProvider());
}
if (ModList.get().isLoaded("opencomputers")) {
initOC();
if (ModList.get().isLoaded("oc2r")) {
OC2DeviceProvider.init();
}
}

// @Optional.Method(modid = "computercraft")
public static void initCC() {
// ComputerCraftAPI.registerPeripheralProvider(new DEPeripheralProvider());
}

// @Optional.Method(modid = "opencomputers")
public static void initOC() {
// Driver.add(new OCAdapter());
// Driver.add(new OCExtendedRFAdapter());
}

// public static class OCAdapter extends DriverSidedTileEntity {
//
// @Override
// public Class<?> getTileEntityClass() {
// return IDEPeripheral.class;
// }
//
// @Override
// public AbstractManagedEnvironment createEnvironment(World world, BlockPos pos, Direction side) {
// return new DEManagedPeripheral((IDEPeripheral) world.getTileEntity(pos));
// }
// }
//
// public static class OCExtendedRFAdapter extends DriverSidedTileEntity {
//
// @Override
// public Class<?> getTileEntityClass() {
// return IExtendedRFStorage.class;
// }
//
// @Override
// public AbstractManagedEnvironment createEnvironment(World world, BlockPos pos, Direction side) {
// return new IExtendedRFStoragePeripheral((IExtendedRFStorage) world.getTileEntity(pos));
// }
// }
//
//Computercraft
public static class DEPeripheralProvider implements IPeripheralProvider {
private IPeripheral peripheral;
private LazyOptional<IPeripheral> holderPeripheral;

/**
* Produce an peripheral implementation from a block location.
*
* @param world The world the block is in.
* @param pos The position the block is at.
* @param side The side to get the peripheral from.
* @return A peripheral, or {@code null} if there is not a peripheral here you'd like to handle.
* @see ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
*/
@Nullable
@Override
public LazyOptional<IPeripheral> getPeripheral(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side) {
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof IPeripheral) {
setPeripheral((IPeripheral)tile);
return holderPeripheral;
}
else return null;
}

protected void setPeripheral(IPeripheral peripheral) {
this.peripheral = peripheral;
this.holderPeripheral = LazyOptional.of(() -> peripheral);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.brandon3055.draconicevolution.integration.computers;
package com.brandon3055.draconicevolution.integration.computers.cc;

import com.brandon3055.brandonscore.blocks.TileBCore;
import com.brandon3055.draconicevolution.DraconicEvolution;
Expand All @@ -7,14 +7,24 @@
import com.brandon3055.draconicevolution.blocks.tileentity.flowgate.TileFlowGate;
import com.brandon3055.draconicevolution.blocks.tileentity.flowgate.TileFluidGate;
import com.brandon3055.draconicevolution.blocks.tileentity.flowgate.TileFluxGate;
import dan200.computercraft.api.ForgeComputerCraftAPI;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class ComputerCraftCompatEventHandler {

@SubscribeEvent(priority = EventPriority.LOW)
public void onAttachCapabilities(AttachCapabilitiesEvent<BlockEntity> event) {
if (event.getObject() instanceof TileBCore) {
Expand All @@ -30,12 +40,6 @@ else if (tile instanceof TileEnergyPylon) {
event.addCapability(new ResourceLocation(DraconicEvolution.MODID, peripheral.getType()), peripheral);
event.addListener(peripheral::invalidate);
}
else if (tile instanceof TileFlowGate) {
TileFlowGate tileEntity = (TileFlowGate)tile;
PeripheralFlowGate peripheral = new PeripheralFlowGate((TileFlowGate)tile);
event.addCapability(new ResourceLocation(DraconicEvolution.MODID, peripheral.getType()), peripheral);
event.addListener(peripheral::invalidate);
}
else if (tile instanceof TileFluidGate) {
TileFluidGate tileEntity = (TileFluidGate)tile;
PeripheralFluidGate peripheral = new PeripheralFluidGate((TileFluidGate)tile);
Expand All @@ -48,6 +52,12 @@ else if (tile instanceof TileFluxGate) {
event.addCapability(new ResourceLocation(DraconicEvolution.MODID, peripheral.getType()), peripheral);
event.addListener(peripheral::invalidate);
}
else if (tile instanceof TileFlowGate) {
TileFlowGate tileEntity = (TileFlowGate)tile;
PeripheralFlowGate peripheral = new PeripheralFlowGate((TileFlowGate)tile);
event.addCapability(new ResourceLocation(DraconicEvolution.MODID, peripheral.getType()), peripheral);
event.addListener(peripheral::invalidate);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.brandon3055.draconicevolution.integration.computers.cc;

import dan200.computercraft.api.ForgeComputerCraftAPI;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class DEPeripheralProvider implements IPeripheralProvider {
private IPeripheral peripheral;
private LazyOptional<IPeripheral> holderPeripheral;

/**
* Produce an peripheral implementation from a block location.
*
* @param world The world the block is in.
* @param pos The position the block is at.
* @param side The side to get the peripheral from.
* @return A peripheral, or {@code null} if there is not a peripheral here you'd like to handle.
* @see ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
*/
@Nullable
@Override
public LazyOptional<IPeripheral> getPeripheral(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side) {
BlockEntity tile = world.getBlockEntity(pos);
if (tile instanceof IPeripheral) {
setPeripheral((IPeripheral)tile);
return holderPeripheral;
}
return LazyOptional.empty();
}

protected void setPeripheral(IPeripheral peripheral) {
this.peripheral = peripheral;
this.holderPeripheral = LazyOptional.of(() -> peripheral);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.brandon3055.draconicevolution.integration.computers;
package com.brandon3055.draconicevolution.integration.computers.cc;

import com.brandon3055.brandonscore.api.power.IOInfo;
import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyPylon;
import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.Capabilities;
import dan200.computercraft.shared.util.CapabilityUtil;
import net.minecraft.core.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
Expand All @@ -15,6 +17,8 @@
import java.util.Locale;
import java.util.Map;

import static com.brandon3055.draconicevolution.integration.computers.CCOCIntegration.ENERGY_PYLON;

public class PeripheralEnergyPylon implements IPeripheral, ICapabilityProvider {

TileEnergyPylon tile;
Expand All @@ -26,7 +30,7 @@ public PeripheralEnergyPylon(TileEnergyPylon tile) {

@Override
public String getType() {
return "draconic_rf_storage";
return ENERGY_PYLON;
}

@Override
Expand Down Expand Up @@ -92,15 +96,14 @@ public final long getOutputPerTick() {

@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
//TODO?
// if (cap == Capabilities.CAPABILITY_PERIPHERAL) {
// if (self == null) self = LazyOptional.of(() -> this);
// return self.cast();
// }
if (cap == Capabilities.CAPABILITY_PERIPHERAL) {
if (self == null) self = LazyOptional.of(() -> this);
return self.cast();
}
return LazyOptional.empty();
}

public void invalidate() {
// self = CapabilityUtil.invalidate(self);
self = CapabilityUtil.invalidate(self);
}
}
Loading