11package gregtech .integration .exnihilo .recipes ;
22
3+ import com .google .gson .JsonElement ;
4+ import com .google .gson .JsonObject ;
5+ import exnihilocreatio .ModBlocks ;
36import exnihilocreatio .blocks .BlockSieve ;
47import exnihilocreatio .registries .manager .ExNihiloRegistryManager ;
58import exnihilocreatio .registries .types .Siftable ;
69import 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 ;
813import gregtech .common .blocks .MetaBlocks ;
14+ import gregtech .integration .IntegrationModule ;
915import gregtech .integration .exnihilo .ExNihiloConfig ;
1016import gregtech .integration .exnihilo .ExNihiloModule ;
17+ import net .minecraft .block .Block ;
1118import net .minecraft .init .Blocks ;
1219import net .minecraft .item .ItemStack ;
1320import net .minecraft .item .crafting .Ingredient ;
1421import 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
1629public 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}
0 commit comments