Skip to content

Commit

Permalink
Attempts to fix CommonProxy issue
Browse files Browse the repository at this point in the history
- Now has a text file that tells the mod what Thaumcraft's jar name is. Change accordingly!
  • Loading branch information
Rongmario committed Oct 10, 2020
1 parent a046022 commit e34414f
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'org.spongepowered.mixin'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.3'
version = '1.4'
group = 'zone.rong' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'thaumicspeedup'

Expand Down
11 changes: 0 additions & 11 deletions src/main/java/zone/rong/thaumicspeedup/Config.java

This file was deleted.

12 changes: 1 addition & 11 deletions src/main/java/zone/rong/thaumicspeedup/ThaumicSpeedup.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
package zone.rong.thaumicspeedup;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;

import java.util.Collection;

@Mod(modid = "thaumicspeedup", name = "Thaumic Speedup", version = "1.3", dependencies = "required:thaumcraft")
@Mod(modid = "thaumicspeedup", name = "Thaumic Speedup", version = "1.4", dependencies = "required:thaumcraft")
public class ThaumicSpeedup {

public static final Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();

public static ThreadLocal<Collection<IRecipe>> RECIPES;

public static Logger LOGGER;

public static boolean isTFCLoaded;
public static boolean isCELoaded;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
LOGGER = event.getModLog();
isTFCLoaded = Loader.isModLoaded("tfc");
isCELoaded = Loader.isModLoaded("gregtech");
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package zone.rong.thaumicspeedup;

import net.minecraft.launchwrapper.LaunchClassLoader;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.CoreModManager;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import org.apache.commons.io.FileUtils;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.Mixins;

import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.charset.Charset;
import java.util.Map;


Expand All @@ -17,9 +20,19 @@ public class ThaumicSpeedupLoadingPlugin implements IFMLLoadingPlugin {

public ThaumicSpeedupLoadingPlugin() {
try {
File jarLocation = new File("./mods/".concat(Config.fileName));
File parent = new File("./config/", "/thaumicspeedup");
parent.mkdir();
File nameFile = new File(parent, "/thaumcraft_jar_name.txt");
String thaumcraftName;
if (nameFile.createNewFile() || nameFile.length() <= 0L) {
thaumcraftName = "Thaumcraft-1.12.2-6.1.BETA26.jar";
FileUtils.writeStringToFile(nameFile, thaumcraftName, Charset.defaultCharset());
} else {
thaumcraftName = FileUtils.readFileToString(nameFile, Charset.defaultCharset());
}
File jarLocation = new File("./mods/".concat(thaumcraftName));
if (!jarLocation.exists()) {
throw new FileNotFoundException("You need to have Thaumcraft installed! Or if you have, please change /config/thaumicspeedup.cfg's string to it's jar file name!");
ThaumicSpeedup.LOGGER.fatal("You need to have Thaumcraft installed! Or if you have, please change /config/thaumicspeedup/thaumcraft_jar_name.txt's string to Thaumcraft's jar file name!");
}
loadModJar(jarLocation);
} catch (Exception e) {
Expand Down

This file was deleted.

101 changes: 101 additions & 0 deletions src/main/java/zone/rong/thaumicspeedup/mixins/ThaumcraftMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package zone.rong.thaumicspeedup.mixins;

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import thaumcraft.Thaumcraft;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.internal.CommonInternals;
import thaumcraft.common.config.*;
import zone.rong.thaumicspeedup.ThaumicSpeedup;

import java.io.*;
import java.util.Collection;

@Mixin(Thaumcraft.class)
public class ThaumcraftMixin {

@Inject(method = "postInit", at = @At("HEAD"), remap = false, cancellable = true)
private void redirectProxyPostInit(FMLPostInitializationEvent event, CallbackInfo ci) {
ConfigEntities.postInitEntitySpawns();
final Collection<IRecipe> recipes = ForgeRegistries.RECIPES.getValues();
new Thread(() -> {
long time = System.currentTimeMillis();
ThaumicSpeedup.LOGGER.info("Offloading aspects registration...");
ThaumicSpeedup.RECIPES = ThreadLocal.withInitial(() -> recipes);
CommonInternals.objectTags.clear();
try {
File parent = new File(Loader.instance().getConfigDir(), "/thaumicspeedup");
File file = new File(parent, "/cache.lock");
if (file.createNewFile() || file.length() <= 0L) {
ConfigAspects.postInit();
write(file);
} else {
FileInputStream fileStream = new FileInputStream(file);
ObjectInputStream objectStream = new ObjectInputStream(fileStream);
Int2ObjectMap<Object2IntMap<String>> store = (Int2ObjectMap<Object2IntMap<String>>) objectStream.readObject();
objectStream.close();
fileStream.close();
store.forEach((i, o2i) -> {
AspectList list = new AspectList();
o2i.forEach((s, j) -> list.add(Aspect.getAspect(s), j));
CommonInternals.objectTags.put(i, list);
});
/*
long previousHash = objectStream.readLong();
ThaumicSpeedup.LOGGER.info("Previous Hash: {}, Current Hash: {}", previousHash, currentHash);
if (previousHash == currentHash) {
Int2ObjectMap<Object2IntMap<String>> store = (Int2ObjectMap<Object2IntMap<String>>) objectStream.readObject();
objectStream.close();
fileStream.close();
store.forEach((i, o2i) -> {
AspectList list = new AspectList();
o2i.forEach((s, j) -> list.add(Aspect.getAspect(s), j));
CommonInternals.objectTags.put(i, list);
});
} else {
objectStream.close();
fileStream.close();
ConfigAspects.postInit();
write(file);
}
*/
}
ConfigRecipes.postAspects();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
ThaumicSpeedup.LOGGER.info("Offloading complete! Taken {}ms", System.currentTimeMillis() - time);
}, "ThaumicSpeedup/AspectThread-0").start();
ModConfig.postInitLoot();
ModConfig.postInitMisc();
ConfigRecipes.compileGroups();
ConfigResearch.postInit();
ci.cancel();
}

private static void write(File file) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(file);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
// objectOutputStream.writeLong(CraftingManager.REGISTRY.getKeys().hashCode());
Int2ObjectMap<Object2IntMap<String>> store = new Int2ObjectOpenHashMap<>();
CommonInternals.objectTags.forEach((i, list) -> {
Object2IntMap<String> map = store.computeIfAbsent(i, k -> new Object2IntOpenHashMap<>());
list.aspects.forEach((a, j) -> map.put(a.getTag(), j));
});
objectOutputStream.writeObject(store);
fileOutputStream.close();
objectOutputStream.close();
}

}
5 changes: 2 additions & 3 deletions src/main/resources/mixins.thaumicspeedup.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"CommonInternalsMixin",
"CommonProxyMixin",
"ConfigAspectsMixin",
"ThaumcraftApiHelperMixin",
"ThaumcraftApiMixin",
"ThaumcraftCraftingManagerMixin"
"ThaumcraftCraftingManagerMixin",
"ThaumcraftMixin"
]
}

0 comments on commit e34414f

Please sign in to comment.