aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java
blob: 015e5fd5f3df684b8e623c0f111d59c9f24caee9 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package gtPlusPlus.api.thermal.sample;

import gtPlusPlus.api.thermal.energy.IThermalContainerItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

public class ItemThermalContainer extends Item implements IThermalContainerItem {
	protected int capacity;
	protected int maxReceive;
	protected int maxExtract;

	public ItemThermalContainer() {
	}

	public ItemThermalContainer(int arg0) {
		this(arg0, arg0, arg0);
	}

	public ItemThermalContainer(int arg0, int arg1) {
		this(arg0, arg1, arg1);
	}

	public ItemThermalContainer(int arg0, int arg1, int arg2) {
		this.capacity = arg0;
		this.maxReceive = arg1;
		this.maxExtract = arg2;
	}

	public ItemThermalContainer setCapacity(int arg0) {
		this.capacity = arg0;
		return this;
	}

	public void setMaxTransfer(int arg0) {
		this.setMaxReceive(arg0);
		this.setMaxExtract(arg0);
	}

	public void setMaxReceive(int arg0) {
		this.maxReceive = arg0;
	}

	public void setMaxExtract(int arg0) {
		this.maxExtract = arg0;
	}

	public int receiveThermalEnergy(ItemStack arg0, int arg1, boolean arg2) {
		if (arg0.getTagCompound() == null) {
			arg0.stackTagCompound = new NBTTagCompound();
		}
		int arg3 = arg0.stackTagCompound.getInteger("ThermalEnergy");
		int arg4 = Math.min(this.capacity - arg3, Math.min(this.maxReceive, arg1));
		if (!arg2) {
			arg3 += arg4;
			arg0.stackTagCompound.setInteger("ThermalEnergy", arg3);
		}
		return arg4;
	}

	public int extractThermalEnergy(ItemStack arg0, int arg1, boolean arg2) {
		if (arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("ThermalEnergy")) {
			int arg3 = arg0.stackTagCompound.getInteger("ThermalEnergy");
			int arg4 = Math.min(arg3, Math.min(this.maxExtract, arg1));
			if (!arg2) {
				arg3 -= arg4;
				arg0.stackTagCompound.setInteger("ThermalEnergy", arg3);
			}
			return arg4;
		} else {
			return 0;
		}
	}

	public int getThermalEnergyStored(ItemStack arg0) {
		return arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("ThermalEnergy")
				? arg0.stackTagCompound.getInteger("ThermalEnergy")
				: 0;
	}

	public int getMaxThermalEnergyStored(ItemStack arg0) {
		return this.capacity;
	}
}