aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/handler/OldCircuitHandler.java
blob: e20e13a337bcf1c0a2735bfcb78070bb20909930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gtPlusPlus.core.handler;

import static gtPlusPlus.core.lib.CORE.ConfigSwitches.enableOldGTcircuits;

import java.lang.reflect.Field;
import java.util.HashSet;

import org.apache.commons.lang3.reflect.FieldUtils;

import gregtech.api.enums.GT_Values;
import gregtech.api.util.EmptyRecipeMap;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;

import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.recipe.RECIPES_Old_Circuits;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechItems;

public class OldCircuitHandler {

	public static void preInit(){
		if (enableOldGTcircuits && CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH){
			removeCircuitRecipeMap(); //Bye shitty recipes.		
		}	
	}

	public static void init(){

	}

	public static void postInit(){
		if (enableOldGTcircuits && CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH){
			RECIPES_Old_Circuits.handleCircuits();
			new RECIPES_Old_Circuits();
		}
	}

	public static boolean addCircuitItems() {
		if (enableOldGTcircuits && CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH){
			return MetaGeneratedGregtechItems.INSTANCE.registerOldCircuits();
		}
		return false;
	}

	private static boolean removeCircuitRecipeMap(){
		if (enableOldGTcircuits && CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK && !CORE.GTNH){
			try {			
				Logger.INFO("[Old Feature - Circuits] Trying to override the Circuit Assembler Recipe map, so that no recipes for new circuits get added.");
				ReflectionUtils.setFinalStatic(GT_Recipe_Map.class.getDeclaredField("sCircuitAssemblerRecipes"), new EmptyRecipeMap(new HashSet<GT_Recipe>(0), "gt.recipe.removed", "Removed", null, GT_Values.RES_PATH_GUI + "basicmachines/Default", 0, 0, 0, 0, 0, GT_Values.E, 0, GT_Values.E, true, false));		
				Field jaffar = GT_Recipe_Map.class.getDeclaredField("sCircuitAssemblerRecipes");
				FieldUtils.removeFinalModifier(jaffar, true);
				jaffar.set(null, new EmptyRecipeMap(new HashSet<GT_Recipe>(0), "gt.recipe.removed", "Removed", null, GT_Values.RES_PATH_GUI + "basicmachines/Default", 0, 0, 0, 0, 0, GT_Values.E, 0, GT_Values.E, true, false));
				Logger.INFO("[Old Feature - Circuits] Successfully replaced circuit assembler recipe map with one that cannot hold recipes.");
			}
			catch (Exception e) {
				Logger.INFO("[Old Feature - Circuits] Failed removing circuit assembler recipe map.");
				return false;
			}
			return true;
		}
		return false;
	}

}