Skip to content

Commit

Permalink
Add Support for Legacy IC2 (#12)
Browse files Browse the repository at this point in the history
* Update FancyGradle and Forge Maven link to make anything work properly

* Create temporary patch as workaround to missing profiles.

* Make JEI CompileOnly so the game actually boots

TODO: Find out why JEI was crashing and how to fix it.

* Update Forge to 13.23.5.2860

* Remove ASM Patch, as it was causing a crash for some reason

* Another try at getting JEI working, sadly unsuccessful

* Remove temporary workaround of the missing resources issue

* Bring back ASM Patch, as it wasn't the cause of corrupted asm jar? No idea how that worked the first time

* Few build.gradle changes that could or could not improve stability of in-dev client?

* Separate patches for 221+ and legacy into other folders for base

* Set Patching mode for base to Fuzzy so it will find more patches required to compile

* Add working patches for 164

* IC2-Base ApplyPatches Folder Version Separation

Make the IC2-Base ApplyPatches gather patches from the folders with version ranges, depending on the version specified in the properties

* Revert back to offset due to fuzzy accepting stuff that shouldn't be necessarily accepted.

* Remove broken patches for 164

* Update build.gradle.kts

* Fix up Generate Patches for IC2-Base

* Generate Patches so Base for 164 compiles

* Finish Patches per version separation in dev env

* Port relevant Patches from 221+ to 164

* Fix up build script, it actually works for 164 \o/

* Update mcmod.info because it felt weird with so little info

* Add requirement of 221+ with addition to 164

* OPINION REQUIRED - Single Jar Multiple IC2 Versions support

* Dev Env Setup for multiple version patch generation.

Bin Patches are now saved, as they are required for the mod build with multiple version support. They are saved under `src\main\generatedResrouces` directory.

ISSUE: Either Build is required to be runned twice, or generateBinPatches has to be launched before triggering the build. I wasn't able to get this to find freshly-generated files for whatever reason.

ISSUE: Dev Builds work only on a version of IC2 that is used to compile it. Dev Bin Patches are inserted to the jar root, and other patches are excluded.

* Add patches pack for original 2.8.221+ support

* Few Small fixes about the patch version selection

* Fix patches not being possible to generate after initial setup

* Add setup task to seperate group

* Add additional check in PatcherFMLPlugin
  • Loading branch information
Kanzaji authored Oct 1, 2023
1 parent 5760730 commit 9cf7c02
Show file tree
Hide file tree
Showing 230 changed files with 6,638 additions and 55 deletions.
34 changes: 28 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
idea
id("net.minecraftforge.gradle") version "5.0.11"
id("de.undercouch.download") version "4.1.1"
id("wtf.gofancy.fancygradle") version "1.0.0"
id("wtf.gofancy.fancygradle") version "1.1.+"
}

evaluationDependsOnChildren()
Expand All @@ -29,6 +29,7 @@ val mappingsVersion: String by project

val versionIC2: String by project
val versionJEI: String by project
val versionForge: String by project

version = getGitVersion()
group = "mods.su5ed"
Expand Down Expand Up @@ -56,26 +57,37 @@ minecraft {

fancyGradle {
patches {
patch(Patch.RESOURCES, Patch.COREMODS, Patch.CODE_CHICKEN_LIB, Patch.ASM)
Patch.RESOURCES
Patch.COREMODS
Patch.CODE_CHICKEN_LIB
Patch.ASM
}
}

repositories {
maven {
// JEI Repository
name = "Progwml6 maven"
url = uri("https://dvs1.progwml6.com/files/maven/")
}
maven {
// Mirror Maven for JEI
name = "ModMaven"
url = uri("https://modmaven.dev")
}
maven {
// IC2 Repository
name = "ic2"
url = uri("https://maven.ic2.player.to/")
}
}

dependencies {
minecraft(group = "net.minecraftforge", name = "forge", version = "1.12.2-14.23.5.2855")
minecraft(group = "net.minecraftforge", name = "forge", version = "1.12.2-${versionForge}")

implementation(project(":IC2-Patched"))
implementation(fg.deobf(group = "mezz.jei", name = "jei_1.12.2", version = versionJEI))
// implementation(fg.deobf(group = "mezz.jei", name = "jei_1.12.2", version = versionJEI))
compileOnly(fg.deobf(group = "mezz.jei", name = "jei_1.12.2", version = versionJEI))
}

tasks {
Expand All @@ -100,7 +112,9 @@ tasks {
register<Jar>("devJar") {
val generateDevBinPatches = project(":IC2-Patched").tasks.getByName<GenerateBinPatches>("generateDevBinPatches")
dependsOn(generateDevBinPatches)
from(sourceSets.main.get().output)
from(sourceSets.main.get().output) {
exclude("patches");
}
from(generateDevBinPatches.output)

manifest {
Expand All @@ -117,7 +131,6 @@ tasks {
dependsOn(generateBinPatches)

from(sourceSets.main.get().output)
from (generateBinPatches.output)
manifest {
attributes(
"FMLCorePlugin" to "mods.su5ed.ic2patcher.asm.PatcherFMLPlugin",
Expand All @@ -127,6 +140,7 @@ tasks {
}

register("setup") {
group = "env setup"
dependsOn(":IC2-Patched:setup")
}

Expand All @@ -147,6 +161,14 @@ artifacts {
archives(tasks.getByName("releaseJar"))
}

sourceSets {
main {
resources {
srcDir("src/main/generatedResources")
}
}
}

fun getGitVersion(): String {
val jgitver = GitVersionCalculator.location(rootDir)
.setNonQualifierBranches("master")
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ mappingsChannel=snapshot
mappingsVersion=20171003-1.12

versionIC2=2.8.222
versionJEI=4.15.0.293
versionJEI=4.16.1.302
versionBuildCraft=7.99.24.7
versionForge=14.23.5.2860
120 changes: 97 additions & 23 deletions projects/IC2-Base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import codechicken.diffpatch.util.PatchMode
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.minecraftforge.gradle.common.task.JarExec
import net.minecraftforge.gradle.patcher.task.TaskApplyPatches
Expand Down Expand Up @@ -32,6 +33,7 @@ val versionIC2: String by project
val versionJEI: String by project
val versionBuildCraft: String by project
val versionForgeFlower: String by project
val versionForge: String by project

val decompiledJar: File = File(buildDir, "decompileIC2/output.jar")
val patchedJar: File = File(buildDir, "applyPatches/output.jar")
Expand Down Expand Up @@ -68,9 +70,11 @@ tasks {
group = taskGroup
dependsOn("applyStyle")
base = processedJar
patches = file("patches/minecraft")

patches = getPatchesDirectory()
rejects = File(buildDir, "$name/rejects.zip")
output = patchedJar
patchMode = PatchMode.OFFSET

isPrintSummary = true
}
Expand All @@ -86,7 +90,9 @@ tasks {
group = taskGroup
dependsOn("applyStylePatched")

from(zipTree(processedJarPatched))
from(zipTree(processedJarPatched)) {
exclude("ic2/api/energy/usage.txt")
}
into("src/main/java")
}

Expand All @@ -103,13 +109,30 @@ tasks {
register<Jar>("sourceJar") {
dependsOn("classes")
archiveClassifier.set("sources")
from(sourceSets.main.get().allJava)
from(sourceSets.main.get().allJava) {
exclude("*.txt")
}
}

register<Jar>("sourceJarW-ODep") {
// This dependency didn't allow for generatePatches to work correctly.
// dependsOn("classes")
archiveClassifier.set("sources")
from(sourceSets.main.get().allJava) {
exclude("*.txt")
}
}

register<Jar>("sourceJarWithResources") {
dependsOn("classes","extractResources")
archiveClassifier.set("sources-with-resources")
from(sourceSets.main.get().allSource)
}

register<TaskGeneratePatches>("generatePatches") {
group = taskGroup
val sourceJar = getByName<Jar>("sourceJar")
val outputDir = file("patches/minecraft")
val sourceJar = getByName<Jar>("sourceJarW-ODep")
var outputDir = getPatchesDirectory()
dependsOn(sourceJar, "applyStyle")
base = processedJar
modified = sourceJar.archiveFile.get().asFile
Expand All @@ -134,12 +157,11 @@ tasks {
}

named<ShadowJar>("shadowJar") {
dependsOn("classes")
dependsOn("classes", "extractSources")

configurations = listOf(project.configurations["shade"])

archiveClassifier.set("")

from("src/main/java/ic2") {
include("profiles/**")
include("sounds/**")
Expand Down Expand Up @@ -183,7 +205,7 @@ repositories {
}

dependencies {
minecraft(group = "net.minecraftforge", name = "forge", version = "1.12.2-14.23.5.2855")
minecraft(group = "net.minecraftforge", name = "forge", version = "1.12.2-${versionForge}")

ic2(group = "net.industrial-craft", name = "industrialcraft-2", version = "${versionIC2}-ex112", classifier = "dev")
compileOnly(group = "mezz.jei", name = "jei_1.12.2", version = versionJEI)
Expand Down Expand Up @@ -212,24 +234,76 @@ open class ApplyAstyle : DefaultTask() {
val out = ZipOutputStream(FileOutputStream(output.get().asFile))

for (entry in zipFile.entries()) {
if (entry.name.startsWith("ic2") && entry.name.endsWith(".java")) {
val txt = BufferedReader(InputStreamReader(zipFile.getInputStream(entry)))
.run {
val builder = StringBuilder()
forEachLine(builder::appendLine)
builder.toString()
}
val reader = StringReader(txt)

val newEntry = ZipEntry(entry.name)
out.putNextEntry(newEntry)

val outString = reader.readText().trimEnd() + System.lineSeparator()
out.write(outString.toByteArray())
out.closeEntry()
if (entry.name.startsWith("ic2")) {
if (entry.name.endsWith(".java")) {
val txt = BufferedReader(InputStreamReader(zipFile.getInputStream(entry)))
.run {
val builder = StringBuilder()
forEachLine(builder::appendLine)
builder.toString()
}
val reader = StringReader(txt)

val newEntry = ZipEntry(entry.name)
out.putNextEntry(newEntry)

val outString = reader.readText().trimEnd() + System.lineSeparator()
out.write(outString.toByteArray())
out.closeEntry()
} else if (entry.name.startsWith("ic2/profiles") || entry.name.startsWith("ic2/sounds")) {
val newEntry = ZipEntry(entry.name)
out.putNextEntry(newEntry)
out.write(zipFile.getInputStream(entry).readBytes())
out.closeEntry()
}
}
}

out.close()
}
}

/**
* Compares two versions separated by dots. Doesn't work with versions schema containing letters.
* Truth table:
* v1 > v2 => true
* v1 == v2 => true
* v1 < v2 => false
* v1 // v2 contain chars -> Integer parsing Exception
*/
fun compareVersions(v1:String, v2:String): Boolean {
val v1s = v1.split(".");
val v2s = v2.split(".");

val length: Int = if (v1s.size > v2s.size) { v2s.size } else { v1s.size }
for (i in 0 until length) {
val v1i = Integer.parseInt(v1s[i]);
val v2i = Integer.parseInt(v2s[i])
if (v1i > v2i) {
return true
} else if (v2i > v1i) {
return false;
}
}
return v1s.size >= v2s.size
}

/**
* Used to get patches directory based on the IC2 Version specified in the Gradle properties.
*/
fun getPatchesDirectory(): File {
project(":IC2-Base").projectDir.listFiles { _, name ->
name.startsWith("patches[") && name.endsWith("]")
}?.forEach { file ->
val name = file.name.toString()
val versions = name.substring(name.indexOf("[")+1, name.indexOf("]")).split(",")
if (versions.size == 2) {
if (compareVersions(versionIC2, versions[0])) {
if (versions[1] == "+" || !compareVersions(versionIC2, versions[1])) {
return file("patches[${versions[0]},${versions[1]}]/minecraft")
}
}
}
}
return File("patches/minecraft")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- a/ic2/core/block/BlockTileEntity.java
+++ b/ic2/core/block/BlockTileEntity.java
@@ -111,7 +111,7 @@
private BlockTileEntity(String name, final ResourceLocation identifier) {
super((BlockName)null, TeBlockRegistry.getInfo(identifier).getDefaultMaterial());
ModContainer modcontainer = Loader.instance().activeModContainer();
- Optional optional = Loader.instance().getActiveModList().stream().filter((mod) -> {
+ Optional<ModContainer> optional = Loader.instance().getActiveModList().stream().filter((mod) -> {
return identifier.getResourceDomain().equals(mod.getModId());
}).findFirst();
Loader loader = Loader.instance();
@@ -673,10 +673,10 @@
list.addAll(this.getDrops(world, pos, state, fortune));
}

- public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
- TileEntityBlock tileentityblock = getTe(world, pos);
+ public List<ItemStack> getDrops(IBlockAccess blockAccess, BlockPos pos, IBlockState state, int fortune) {
+ TileEntityBlock tileentityblock = getTe(blockAccess, pos);
if (tileentityblock == null) {
- World world = Util.getWorld(world);
+ World world = Util.getWorld(blockAccess);
if (world != null && world.isRemote || world == null && !IC2.platform.isSimulating()) {
return new ArrayList<ItemStack>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/ic2/core/block/invslot/InvSlotUpgrade.java
+++ b/ic2/core/block/invslot/InvSlotUpgrade.java
@@ -31,7 +31,7 @@
private List<Redstone.IRedstoneModifier> redstoneModifiers = Collections.<Redstone.IRedstoneModifier>emptyList();

public static InvSlotUpgrade createUnchecked(TileEntityInventory base, String name, int count) {
- return new InvSlotUpgrade((TileEntityInventory)((IUpgradableBlock)base), name, count);
+ return new InvSlotUpgrade((TileEntityInventory & IUpgradableBlock)base, name, count);
}

public <T extends TileEntityInventory & IUpgradableBlock> InvSlotUpgrade(T base, String name, int count) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/ic2/core/block/machine/container/ContainerIndustrialWorkbench.java
+++ b/ic2/core/block/machine/container/ContainerIndustrialWorkbench.java
@@ -129,8 +129,8 @@
}

public boolean canMergeSlot(ItemStack stack, Slot slot) {
- for(Slot slot : this.outputs) {
- if (slot.inventory == slot.inventory) {
+ for(Slot output : this.outputs) {
+ if (output.inventory == slot.inventory) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--- a/ic2/core/block/machine/tileentity/TileEntityBatchCrafter.java
+++ b/ic2/core/block/machine/tileentity/TileEntityBatchCrafter.java
@@ -132,8 +132,9 @@
this.progress = 0;
this.guiProgress = 0.0F;

- for(final int i = 0; i < this.ingredientsRow.length; ++i) {
- this.ingredientsRow[i] = new InvSlot(this, "ingredient[" + i + ']', InvSlot.Access.I, 1) {
+ for(int i = 0; i < this.ingredientsRow.length; ++i) {
+ int finalI = i;
+ this.ingredientsRow[i] = new InvSlot(this, "ingredient[" + finalI + ']', InvSlot.Access.I, 1) {
public boolean accepts(ItemStack ingredient) {
IRecipe irecipe = TileEntityBatchCrafter.this.world.isRemote ? TileEntityBatchCrafter.this.findRecipe() : TileEntityBatchCrafter.this.recipe;
if (irecipe == null) {
@@ -141,14 +142,14 @@
} else {
assert irecipe.matches(TileEntityBatchCrafter.this.crafting, TileEntityBatchCrafter.this.world);

- ItemStack itemstack = TileEntityBatchCrafter.this.craftingGrid[i];
+ ItemStack itemstack = TileEntityBatchCrafter.this.craftingGrid[finalI];

boolean flag;
try {
- TileEntityBatchCrafter.this.craftingGrid[i] = ingredient;
+ TileEntityBatchCrafter.this.craftingGrid[finalI] = ingredient;
flag = irecipe.matches(TileEntityBatchCrafter.this.crafting, TileEntityBatchCrafter.this.world);
} finally {
- TileEntityBatchCrafter.this.craftingGrid[i] = itemstack;
+ TileEntityBatchCrafter.this.craftingGrid[finalI] = itemstack;
}

return flag;
@@ -157,7 +158,7 @@

public void onChanged() {
super.onChanged();
- TileEntityBatchCrafter.this.ingredientChange(i);
+ TileEntityBatchCrafter.this.ingredientChange(finalI);
}
};
}
Loading

0 comments on commit 9cf7c02

Please sign in to comment.