Skip to content

Commit b862cb7

Browse files
Irgendwer01serenibyss
authored andcommitted
Upload
1 parent c7637d3 commit b862cb7

File tree

3 files changed

+96
-14
lines changed

3 files changed

+96
-14
lines changed

src/main/java/gregtech/integration/exnihilo/ExNihiloModule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import gregtech.api.unification.material.event.MaterialEvent;
1313
import gregtech.api.unification.material.info.MaterialIconType;
1414
import gregtech.api.unification.ore.OrePrefix;
15+
import gregtech.api.util.FileUtility;
1516
import gregtech.common.items.MetaItems;
1617
import gregtech.common.metatileentities.MetaTileEntities;
1718
import gregtech.integration.IntegrationModule;
@@ -28,12 +29,14 @@
2829
import net.minecraft.item.crafting.IRecipe;
2930
import net.minecraft.util.ResourceLocation;
3031
import net.minecraftforge.event.RegistryEvent;
32+
import net.minecraftforge.fml.common.Loader;
3133
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
3234
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
3335
import net.minecraftforge.fml.common.eventhandler.EventPriority;
3436
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
3537

3638
import javax.annotation.Nonnull;
39+
import java.io.File;
3740
import java.util.Collections;
3841
import java.util.List;
3942

@@ -51,7 +54,6 @@
5154
)
5255
public class ExNihiloModule extends IntegrationSubmodule {
5356

54-
5557
// Items
5658
public static ExNihiloPebble GTPebbles;
5759

@@ -89,6 +91,7 @@ public void preInit(FMLPreInitializationEvent event) {
8991
getLogger().info("Registering Ex Nihilo Compat Items, Blocks, and Machines");
9092
GTPebbles = new ExNihiloPebble();
9193
registerMetaTileEntities();
94+
FileUtility.extractJarFiles(String.format("/assets/%s/%s", GTValues.MODID, "exnihilo"), new File(Loader.instance().getConfigDir(), "gregtech"), false);
9295
}
9396

9497
@Override

src/main/java/gregtech/integration/exnihilo/recipes/SieveDrops.java

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,98 @@
11
package gregtech.integration.exnihilo.recipes;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonObject;
5+
import exnihilocreatio.ModBlocks;
36
import exnihilocreatio.blocks.BlockSieve;
47
import exnihilocreatio.registries.manager.ExNihiloRegistryManager;
58
import exnihilocreatio.registries.types.Siftable;
69
import exnihilocreatio.util.ItemInfo;
7-
import gregtech.api.unification.material.Material;
10+
import gregtech.api.GregTechAPI;
11+
import gregtech.api.unification.OreDictUnifier;
12+
import gregtech.api.util.FileUtility;
813
import gregtech.common.blocks.MetaBlocks;
14+
import gregtech.integration.IntegrationModule;
915
import gregtech.integration.exnihilo.ExNihiloConfig;
1016
import gregtech.integration.exnihilo.ExNihiloModule;
17+
import net.minecraft.block.Block;
1118
import net.minecraft.init.Blocks;
1219
import net.minecraft.item.ItemStack;
1320
import net.minecraft.item.crafting.Ingredient;
1421
import net.minecraft.util.NonNullList;
22+
import net.minecraftforge.fml.common.Loader;
23+
import net.minecraftforge.oredict.OreDictionary;
24+
25+
import java.io.File;
26+
27+
import static gregtech.integration.exnihilo.ExNihiloModule.*;
1528

1629
public class SieveDrops {
1730

31+
private static boolean validateDrops(String material, int meshlevel, float chance) {
32+
if (GregTechAPI.materialManager.getMaterial(material) == null) {
33+
IntegrationModule.logger.error(String.format("Material %s does not exist!", material));
34+
return false;
35+
}
36+
if (chance > 1F) {
37+
IntegrationModule.logger.error(String.format("Chance for %s can't be higher than 1!", material));
38+
return false;
39+
}
40+
if (meshlevel > 4) {
41+
IntegrationModule.logger.error(String.format("Mesh Level for %s out of range!", material));
42+
return false;
43+
}
44+
return true;
45+
}
46+
private static void processDrops(JsonElement element) {
47+
if (!element.isJsonObject()) {
48+
IntegrationModule.logger.error("Parsed JSONElement is not an JSON Object!");
49+
return;
50+
}
51+
JsonObject object = element.getAsJsonObject();
52+
object.entrySet().forEach(set -> {
53+
String oreDict;
54+
Block block;
55+
if (set.getKey().startsWith("ore:")) {
56+
block = null;
57+
oreDict = set.getKey().substring(4);
58+
if (!OreDictionary.doesOreNameExist(oreDict)) {
59+
IntegrationModule.logger.error(String.format("OreDict %s does not exist!", oreDict));
60+
return;
61+
}
62+
} else {
63+
oreDict = null;
64+
block = Block.getBlockFromName(set.getKey());
65+
if (block == null) {
66+
IntegrationModule.logger.error(String.format("Block with ID %s does not exist!", set.getKey()));
67+
return;
68+
}
69+
}
70+
71+
JsonObject m = set.getValue().getAsJsonObject();
72+
m.entrySet().forEach(material -> {
73+
JsonObject values = material.getValue().getAsJsonObject();
74+
ItemStack stack;
75+
if (!validateDrops(material.getKey(), values.get("meshlevel").getAsInt(), values.get("chance").getAsFloat())) {
76+
return;
77+
}
78+
if (oreDict != null || !(block == ModBlocks.netherrackCrushed || block == ModBlocks.endstoneCrushed)) {
79+
stack = OreDictUnifier.get(oreChunk, GregTechAPI.materialManager.getMaterial(material.getKey()));
80+
} else {
81+
stack = block == ModBlocks.netherrackCrushed
82+
? OreDictUnifier.get(oreNetherChunk, GregTechAPI.materialManager.getMaterial(material.getKey()))
83+
: OreDictUnifier.get(oreEnderChunk, GregTechAPI.materialManager.getMaterial(material.getKey()));
84+
}
85+
if (oreDict != null) {
86+
ExNihiloRegistryManager.SIEVE_REGISTRY.register(oreDict, new ItemInfo(stack.getItem(), stack.getMetadata()), values.get("chance").getAsFloat(), values.get("meshlevel").getAsInt());
87+
} else {
88+
ExNihiloRegistryManager.SIEVE_REGISTRY.register(block.getDefaultState(), new ItemInfo(stack.getItem(), stack.getMetadata()), values.get("chance").getAsFloat(), values.get("meshlevel").getAsInt());
89+
}
90+
});
91+
});
92+
}
93+
1894
public static void registerRecipes() {
95+
processDrops(FileUtility.loadJson(new File(Loader.instance().getConfigDir(), "gregtech/sieve_drops.json")));
1996
NonNullList<Siftable> siftable = NonNullList.create();
2097
if (ExNihiloConfig.overrideAllSiftDrops) {
2198
ExNihiloRegistryManager.SIEVE_REGISTRY.getRegistry().entrySet().stream().anyMatch(entry -> {
@@ -38,16 +115,4 @@ public static void registerRecipes() {
38115
ExNihiloRegistryManager.SIEVE_REGISTRY.register("dirt", new ItemInfo(MetaBlocks.RUBBER_SAPLING.getBlockState().getBlock()), 0.1f, BlockSieve.MeshType.STRING.getID());
39116
}
40117
}
41-
42-
private static class SieveDrop {
43-
public Material material;
44-
public float chance;
45-
public int level;
46-
47-
public SieveDrop(Material material, float chance, int level) {
48-
this.material = material;
49-
this.chance = chance;
50-
this.level = level;
51-
}
52-
}
53118
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"ore:sand":{
3+
"copper":{
4+
"meshlevel": 1,
5+
"chance": 0.02
6+
}
7+
},
8+
"exnihilocreatio:block_netherrack_crushed":{
9+
"copper":{
10+
"meshlevel": 1,
11+
"chance": 0.02
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)