aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/PollutionUtils.java
blob: 7e8de5f706f4637e24bbf42317412524e1a51d5d (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
package gtPlusPlus.core.util;

import java.lang.reflect.*;

import gregtech.GT_Mod;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.GT_Proxy;
import gtPlusPlus.core.util.reflect.ReflectionUtils;

public class PollutionUtils {

	public static boolean mPollution() {
		try {
			GT_Proxy GT_Pollution = GT_Mod.gregtechproxy;
			if (GT_Pollution != null) {
				Field mPollution = ReflectionUtils.getField(GT_Pollution.getClass(), "mPollution");
				if (mPollution != null) {
					return mPollution.getBoolean(GT_Pollution);
				}
			}
		} catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
			return false;
		}
		return false;
	}

	public static boolean addPollution(IGregTechTileEntity te, int pollutionValue) {
		try {
			Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
			if (GT_Pollution != null) {
				Method addPollution = GT_Pollution.getMethod("addPollution", IGregTechTileEntity.class, int.class);
				if (addPollution != null) {
					addPollution.invoke(null, te, pollutionValue);
					return true;
				}
			}
		} catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
				| IllegalArgumentException | InvocationTargetException e) {
			return false;
		}
		return false;
	}

	public static int getPollution(IGregTechTileEntity te) {
		try {
			Class<?> GT_Pollution = Class.forName("gregtech.common.GT_Pollution");
			if (GT_Pollution != null) {
				Method addPollution = GT_Pollution.getMethod("getPollution", IGregTechTileEntity.class);
				if (addPollution != null) {
					return (int) addPollution.invoke(null, te);
				}
			}
		} catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalAccessException
				| IllegalArgumentException | InvocationTargetException e) {
			return 0;
		}
		return 0;
	}

}