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 initial computercraft support. #2792

Open
wants to merge 1 commit into
base: 1.20.1
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
6 changes: 6 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ dependencies {
modCompileOnly(forge.journeymap.api)
modCompileOnly(forge.journeymap.forge)

// CC: Tweaked
modCompileOnly(forge.cc.tweaked.core.api)
modCompileOnly(forge.cc.tweaked.forge.api)

// Standard runtime mods //
modRuntimeOnly(forge.jade)
modRuntimeOnly(forge.ae2)
Expand Down Expand Up @@ -109,6 +113,8 @@ dependencies {
modExtraRuntimeOnly(forge.ftbteams)
modExtraRuntimeOnly(forge.ftbchunks)

modExtraRuntimeOnly(forge.cc.tweaked.forge.impl)

modExtraRuntimeOnly("top.theillusivec4.curios:curios-forge:${forge.versions.curios.get()}")
modExtraRuntimeOnly("curse.maven:spark-361579:4738952")
modExtraRuntimeOnly("curse.maven:observable-509575:5643037")
Expand Down
7 changes: 7 additions & 0 deletions gradle/scripts/repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ repositories {
includeGroup "thedarkcolour"
}
}
maven {
name = "CC: Tweaked"
url = "https://maven.squiddev.cc"
content {
includeGroup "cc.tweaked"
}
}
maven { url "https://maven.architectury.dev/" }
maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes
maven { url 'https://jitpack.io' } // Mixin Extras, Fabric ASM
Expand Down
6 changes: 6 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencyResolutionManagement {
def argonautsForgeFile = "5263580"
def resourcefulForgeFile = "5659871"
def kffVersion = "4.11.0"
def cctVersion = "1.114.3"

// Libs
def quiltMappingsVersion = "5" // https://lambdaurora.dev/tools/import_quilt.html
Expand Down Expand Up @@ -147,6 +148,11 @@ dependencyResolutionManagement {

def kotlinForForge = version("kotlinForForge", kffVersion)
library("kotlinforforge", "thedarkcolour", "kotlinforforge").versionRef(kotlinForForge)

def ccTweaked = version("cc-tweaked", cctVersion)
library("cc-tweaked-core-api", "cc.tweaked", "cc-tweaked-${minecraftVersion}-core-api").versionRef(ccTweaked)
library("cc-tweaked-forge-api", "cc.tweaked", "cc-tweaked-${minecraftVersion}-forge-api").versionRef(ccTweaked)
library("cc-tweaked-forge-impl", "cc.tweaked", "cc-tweaked-${minecraftVersion}-forge").versionRef(ccTweaked)
}

libs {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/GTCEu.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,9 @@ public static boolean isFTBTeamsLoaded() {
public static boolean isArgonautsLoaded() {
return isModLoaded(GTValues.MODID_ARGONAUTS);
}

public static boolean isCCTweakedLoaded() {
return isModLoaded(GTValues.MODID_CCTWEAKED);
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/gregtechceu/gtceu/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public static int[] tiersBetween(int minInclusive, int maxInclusive) {
MODID_FTB_CHUNKS = "ftbchunks",
MODID_JAVD = "javd",
MODID_FTB_TEAMS = "ftbteams",
MODID_ARGONAUTS = "argonauts";
MODID_ARGONAUTS = "argonauts",
MODID_CCTWEAKED = "computercraft";

/**
* Spray painting compat modids
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack;
import com.gregtechceu.gtceu.data.pack.GTPackSource;
import com.gregtechceu.gtceu.forge.AlloyBlastPropertyAddition;
import com.gregtechceu.gtceu.integration.cctweaked.CCTweakedPlugin;
import com.gregtechceu.gtceu.integration.kjs.GTCEuStartupEvents;
import com.gregtechceu.gtceu.integration.kjs.GTRegistryInfo;
import com.gregtechceu.gtceu.integration.kjs.events.MaterialModificationEventJS;
Expand Down Expand Up @@ -235,6 +236,11 @@ public void commonSetup(FMLCommonSetupEvent event) {
CraftingHelper.register(IntCircuitIngredient.TYPE, IntCircuitIngredient.SERIALIZER);
CraftingHelper.register(IntProviderIngredient.TYPE, IntProviderIngredient.SERIALIZER);
CraftingHelper.register(FluidContainerIngredient.TYPE, FluidContainerIngredient.SERIALIZER);

if (GTCEu.Mods.isCCTweakedLoaded()) {
GTCEu.LOGGER.info("CC: Tweaked found. Enabling integration...");
CCTweakedPlugin.init();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gregtechceu.gtceu.integration.cctweaked;

import com.gregtechceu.gtceu.api.capability.forge.GTCapability;
import com.gregtechceu.gtceu.integration.cctweaked.peripherals.*;

import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.ForgeComputerCraftAPI;

public class CCTweakedPlugin {

public static void init() {
ComputerCraftAPI.registerGenericSource(new EnergyInfoPeripheral());
ForgeComputerCraftAPI.registerGenericCapability(GTCapability.CAPABILITY_ENERGY_INFO_PROVIDER);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.gregtechceu.gtceu.integration.cctweaked.peripherals;

import com.gregtechceu.gtceu.api.capability.IEnergyInfoProvider;

import dan200.computercraft.api.lua.LuaFunction;
import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.api.peripheral.GenericPeripheral;

import java.math.BigInteger;

public class EnergyInfoPeripheral implements GenericPeripheral {

public String id() {
return "gtceu:energy_info";
}

@LuaFunction
static public MethodResult getEnergyStored(IEnergyInfoProvider infoProvider) {
return toResult(infoProvider.getEnergyInfo().stored());
}

@LuaFunction
static public MethodResult getEnergyCapacity(IEnergyInfoProvider infoProvider) {
return toResult(infoProvider.getEnergyInfo().capacity());
}

private static BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE);

private static MethodResult toResult(BigInteger val) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lua treats all numbers as doubles, so there's no advantage to special-casing small values.
In CC:Tweaked specifically, values are converted by calling java.lang.Number#doubleValue(), so you can just pass the BigInteger into MethodResult.of() directly.
https://github.com/cc-tweaked/CC-Tweaked/blob/mc-1.20.x/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java#L177

if (val.compareTo(MAX_LONG) > 0) {
return MethodResult.of(val.doubleValue());
} else {
return MethodResult.of(val.longValue());
}
}
}
Loading