Skip to content

Commit

Permalink
Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Irgendwer01 authored and serenibyss committed Nov 25, 2023
1 parent c7637d3 commit b862cb7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -51,7 +54,6 @@
)
public class ExNihiloModule extends IntegrationSubmodule {


// Items
public static ExNihiloPebble GTPebbles;

Expand Down Expand Up @@ -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
Expand Down
91 changes: 78 additions & 13 deletions src/main/java/gregtech/integration/exnihilo/recipes/SieveDrops.java
Original file line number Diff line number Diff line change
@@ -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> siftable = NonNullList.create();
if (ExNihiloConfig.overrideAllSiftDrops) {
ExNihiloRegistryManager.SIEVE_REGISTRY.getRegistry().entrySet().stream().anyMatch(entry -> {
Expand All @@ -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;
}
}
}
14 changes: 14 additions & 0 deletions src/main/resources/assets/gregtech/exnihilo/sieve_drops.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ore:sand":{
"copper":{
"meshlevel": 1,
"chance": 0.02
}
},
"exnihilocreatio:block_netherrack_crushed":{
"copper":{
"meshlevel": 1,
"chance": 0.02
}
}
}

0 comments on commit b862cb7

Please sign in to comment.