-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Now has a text file that tells the mod what Thaumcraft's jar name is. Change accordingly!
- Loading branch information
Showing
7 changed files
with
120 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/main/java/zone/rong/thaumicspeedup/mixins/ConfigAspectsMixin.java
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
src/main/java/zone/rong/thaumicspeedup/mixins/ThaumcraftMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters