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 thaumcraft compat to prevent trees&aura node generation when requested #12

Merged
merged 1 commit into from
Sep 16, 2022
Merged
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
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ dependencies {
compile("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-104-GTNH:dev") { transitive = false }
compile("com.github.GTNewHorizons:NotEnoughItems:2.3.1-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Galaxy-Space-GTNH:1.1.16p-GTNH:dev") {transitive = false}
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Baubles:1.0.1.14:dev') {transitive = false}
}
59 changes: 48 additions & 11 deletions src/main/java/xyz/kubasz/personalspace/PersonalSpaceMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import gnu.trove.map.hash.TIntObjectHashMap;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -53,7 +55,7 @@
version = Tags.VERSION,
name = Tags.MODNAME,
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "after:utilityworlds;after:appliedenergistics2-core;after:GalaxySpace")
dependencies = "after:utilityworlds;after:appliedenergistics2-core;after:GalaxySpace;after:Thaumcraft")
public class PersonalSpaceMod {

public static final String DIM_METADATA_FILE = "personalspace_metadata.cfg";
Expand Down Expand Up @@ -220,6 +222,9 @@ public void worldSave(WorldEvent.Save event) {
private static final int NATURA_DIM_WORLDGEN_CLOUD_BIT = 2;
private static final int NATURA_DIM_WORLDGEN_TREE_BIT = 4;

private static final String THAUMCRAFT_MODID = "Thaumcraft";
private static Field thaumcraftDimensionBlacklist = null;

private static int naturaConfigForDim(DimensionConfig config) {
int gen = 0;
if (config.isGeneratingVegetation()) {
Expand All @@ -232,35 +237,67 @@ private static int naturaConfigForDim(DimensionConfig config) {
return gen;
}

private static HashMap<Integer, Integer> getThaumcraftDimensionBlacklist() {
if (Loader.isModLoaded(THAUMCRAFT_MODID)) {
try {
if (thaumcraftDimensionBlacklist == null) {
Class<?> klass = Class.forName("thaumcraft.common.lib.world.ThaumcraftWorldGenerator");
thaumcraftDimensionBlacklist = klass.getField("dimensionBlacklist");
}
return (HashMap<Integer, Integer>) thaumcraftDimensionBlacklist.get(null);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return null;
}

private void bulkDimSettingsUpdate() {
TIntArrayList dimIds = new TIntArrayList();
TIntArrayList dimNaturaGens = new TIntArrayList();
HashMap<Integer, Integer> tcBlacklist = getThaumcraftDimensionBlacklist();
CommonProxy.getDimensionConfigObjects(false).forEachEntry((dimId, config) -> {
if (config == null) {
return true;
}
dimIds.add(dimId);
dimNaturaGens.add(naturaConfigForDim(config));
if (tcBlacklist != null) {
if (config.isGeneratingTrees()) {
tcBlacklist.remove(dimId);
} else {
tcBlacklist.put(dimId, 0);
}
}
return true;
});
if (dimIds.isEmpty()) {
return;
if (Loader.isModLoaded(NATURA_MODID) && !dimIds.isEmpty()) {
NBTTagCompound naturaImc = new NBTTagCompound();
naturaImc.setIntArray(NATURA_IMC_DIMS, dimIds.toArray());
naturaImc.setIntArray(NATURA_IMC_SETS, dimNaturaGens.toArray());
FMLInterModComms.sendRuntimeMessage(this, NATURA_MODID, NATURA_IMC, naturaImc);
}
NBTTagCompound naturaImc = new NBTTagCompound();
naturaImc.setIntArray(NATURA_IMC_DIMS, dimIds.toArray());
naturaImc.setIntArray(NATURA_IMC_SETS, dimNaturaGens.toArray());
FMLInterModComms.sendRuntimeMessage(this, NATURA_MODID, NATURA_IMC, naturaImc);
}

public void onDimSettingsChangeServer(int dimId) {
DimensionConfig config = DimensionConfig.getForDimension(dimId, false);
if (config == null) {
return;
}
NBTTagCompound naturaImc = new NBTTagCompound();
naturaImc.setIntArray(NATURA_IMC_DIMS, new int[] {dimId});
naturaImc.setIntArray(NATURA_IMC_SETS, new int[] {naturaConfigForDim(config)});
FMLInterModComms.sendRuntimeMessage(this, NATURA_MODID, NATURA_IMC, naturaImc);
HashMap<Integer, Integer> tcBlacklist = getThaumcraftDimensionBlacklist();
if (tcBlacklist != null) {
if (config.isGeneratingTrees()) {
tcBlacklist.remove(dimId);
} else {
tcBlacklist.put(dimId, 0);
}
}
if (Loader.isModLoaded(NATURA_MODID)) {
NBTTagCompound naturaImc = new NBTTagCompound();
naturaImc.setIntArray(NATURA_IMC_DIMS, new int[] {dimId});
naturaImc.setIntArray(NATURA_IMC_SETS, new int[] {naturaConfigForDim(config)});
FMLInterModComms.sendRuntimeMessage(this, NATURA_MODID, NATURA_IMC, naturaImc);
}
}

private static boolean thermosLogged = false;
Expand Down