diff --git a/src/main/java/gregtech/integration/exnihilo/ExNihiloModule.java b/src/main/java/gregtech/integration/exnihilo/ExNihiloModule.java index eea268e61d3..6d2a3890487 100644 --- a/src/main/java/gregtech/integration/exnihilo/ExNihiloModule.java +++ b/src/main/java/gregtech/integration/exnihilo/ExNihiloModule.java @@ -12,6 +12,7 @@ import gregtech.api.unification.material.event.MaterialEvent; import gregtech.api.unification.material.info.MaterialIconType; import gregtech.api.unification.ore.OrePrefix; +import gregtech.api.util.FileUtility; import gregtech.common.items.MetaItems; import gregtech.common.metatileentities.MetaTileEntities; import gregtech.integration.IntegrationModule; @@ -28,12 +29,14 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import javax.annotation.Nonnull; +import java.io.File; import java.util.Collections; import java.util.List; @@ -51,7 +54,6 @@ ) public class ExNihiloModule extends IntegrationSubmodule { - // Items public static ExNihiloPebble GTPebbles; @@ -89,6 +91,7 @@ public void preInit(FMLPreInitializationEvent event) { getLogger().info("Registering Ex Nihilo Compat Items, Blocks, and Machines"); GTPebbles = new ExNihiloPebble(); registerMetaTileEntities(); + FileUtility.extractJarFiles(String.format("/assets/%s/%s", GTValues.MODID, "exnihilo"), new File(Loader.instance().getConfigDir(), "gregtech"), false); } @Override diff --git a/src/main/java/gregtech/integration/exnihilo/recipes/SieveDrops.java b/src/main/java/gregtech/integration/exnihilo/recipes/SieveDrops.java index b26deece216..08652855c7b 100644 --- a/src/main/java/gregtech/integration/exnihilo/recipes/SieveDrops.java +++ b/src/main/java/gregtech/integration/exnihilo/recipes/SieveDrops.java @@ -1,21 +1,98 @@ package gregtech.integration.exnihilo.recipes; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import exnihilocreatio.ModBlocks; import exnihilocreatio.blocks.BlockSieve; import exnihilocreatio.registries.manager.ExNihiloRegistryManager; import exnihilocreatio.registries.types.Siftable; import exnihilocreatio.util.ItemInfo; -import gregtech.api.unification.material.Material; +import gregtech.api.GregTechAPI; +import gregtech.api.unification.OreDictUnifier; +import gregtech.api.util.FileUtility; import gregtech.common.blocks.MetaBlocks; +import gregtech.integration.IntegrationModule; import gregtech.integration.exnihilo.ExNihiloConfig; import gregtech.integration.exnihilo.ExNihiloModule; +import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.NonNullList; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.oredict.OreDictionary; + +import java.io.File; + +import static gregtech.integration.exnihilo.ExNihiloModule.*; public class SieveDrops { + private static boolean validateDrops(String material, int meshlevel, float chance) { + if (GregTechAPI.materialManager.getMaterial(material) == null) { + IntegrationModule.logger.error(String.format("Material %s does not exist!", material)); + return false; + } + if (chance > 1F) { + IntegrationModule.logger.error(String.format("Chance for %s can't be higher than 1!", material)); + return false; + } + if (meshlevel > 4) { + IntegrationModule.logger.error(String.format("Mesh Level for %s out of range!", material)); + return false; + } + return true; + } + private static void processDrops(JsonElement element) { + if (!element.isJsonObject()) { + IntegrationModule.logger.error("Parsed JSONElement is not an JSON Object!"); + return; + } + JsonObject object = element.getAsJsonObject(); + object.entrySet().forEach(set -> { + String oreDict; + Block block; + if (set.getKey().startsWith("ore:")) { + block = null; + oreDict = set.getKey().substring(4); + if (!OreDictionary.doesOreNameExist(oreDict)) { + IntegrationModule.logger.error(String.format("OreDict %s does not exist!", oreDict)); + return; + } + } else { + oreDict = null; + block = Block.getBlockFromName(set.getKey()); + if (block == null) { + IntegrationModule.logger.error(String.format("Block with ID %s does not exist!", set.getKey())); + return; + } + } + + JsonObject m = set.getValue().getAsJsonObject(); + m.entrySet().forEach(material -> { + JsonObject values = material.getValue().getAsJsonObject(); + ItemStack stack; + if (!validateDrops(material.getKey(), values.get("meshlevel").getAsInt(), values.get("chance").getAsFloat())) { + return; + } + if (oreDict != null || !(block == ModBlocks.netherrackCrushed || block == ModBlocks.endstoneCrushed)) { + stack = OreDictUnifier.get(oreChunk, GregTechAPI.materialManager.getMaterial(material.getKey())); + } else { + stack = block == ModBlocks.netherrackCrushed + ? OreDictUnifier.get(oreNetherChunk, GregTechAPI.materialManager.getMaterial(material.getKey())) + : OreDictUnifier.get(oreEnderChunk, GregTechAPI.materialManager.getMaterial(material.getKey())); + } + if (oreDict != null) { + ExNihiloRegistryManager.SIEVE_REGISTRY.register(oreDict, new ItemInfo(stack.getItem(), stack.getMetadata()), values.get("chance").getAsFloat(), values.get("meshlevel").getAsInt()); + } else { + ExNihiloRegistryManager.SIEVE_REGISTRY.register(block.getDefaultState(), new ItemInfo(stack.getItem(), stack.getMetadata()), values.get("chance").getAsFloat(), values.get("meshlevel").getAsInt()); + } + }); + }); + } + public static void registerRecipes() { + processDrops(FileUtility.loadJson(new File(Loader.instance().getConfigDir(), "gregtech/sieve_drops.json"))); NonNullList siftable = NonNullList.create(); if (ExNihiloConfig.overrideAllSiftDrops) { ExNihiloRegistryManager.SIEVE_REGISTRY.getRegistry().entrySet().stream().anyMatch(entry -> { @@ -38,16 +115,4 @@ public static void registerRecipes() { ExNihiloRegistryManager.SIEVE_REGISTRY.register("dirt", new ItemInfo(MetaBlocks.RUBBER_SAPLING.getBlockState().getBlock()), 0.1f, BlockSieve.MeshType.STRING.getID()); } } - - private static class SieveDrop { - public Material material; - public float chance; - public int level; - - public SieveDrop(Material material, float chance, int level) { - this.material = material; - this.chance = chance; - this.level = level; - } - } } diff --git a/src/main/resources/assets/gregtech/exnihilo/sieve_drops.json b/src/main/resources/assets/gregtech/exnihilo/sieve_drops.json new file mode 100644 index 00000000000..00f4d9acb35 --- /dev/null +++ b/src/main/resources/assets/gregtech/exnihilo/sieve_drops.json @@ -0,0 +1,14 @@ +{ + "ore:sand":{ + "copper":{ + "meshlevel": 1, + "chance": 0.02 + } + }, + "exnihilocreatio:block_netherrack_crushed":{ + "copper":{ + "meshlevel": 1, + "chance": 0.02 + } + } +}