-
Notifications
You must be signed in to change notification settings - Fork 497
/
CoolantManager.java
126 lines (107 loc) · 3.4 KB
/
CoolantManager.java
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.energy.fuels;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.core.StackKey;
import buildcraft.api.fuels.ICoolant;
import buildcraft.api.fuels.ICoolantManager;
import buildcraft.api.fuels.ISolidCoolant;
public final class CoolantManager implements ICoolantManager {
public static final CoolantManager INSTANCE = new CoolantManager();
private final List<ICoolant> coolants = new LinkedList<ICoolant>();
private final List<ISolidCoolant> solidCoolants = new LinkedList<ISolidCoolant>();
private CoolantManager() {
}
@Override
public ICoolant addCoolant(ICoolant coolant) {
coolants.add(coolant);
return coolant;
}
@Override
public ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB) {
return addCoolant(new BCCoolant(fluid, degreesCoolingPerMB));
}
@Override
public ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant) {
solidCoolants.add(solidCoolant);
return solidCoolant;
}
@Override
public ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier) {
assert solid.stack != null && solid.fluidStack == null;
assert liquid.stack == null && liquid.fluidStack != null;
return addSolidCoolant(new BCSolidCoolant(solid, liquid, multiplier));
}
@Override
public Collection<ICoolant> getCoolants() {
return coolants;
}
@Override
public Collection<ISolidCoolant> getSolidCoolants() {
return solidCoolants;
}
@Override
public ICoolant getCoolant(Fluid fluid) {
for (ICoolant coolant : coolants) {
if (coolant.getFluid() == fluid) {
return coolant;
}
}
return null;
}
@Override
public ISolidCoolant getSolidCoolant(StackKey solid) {
assert solid.stack != null && solid.fluidStack == null;
for (ISolidCoolant solidCoolant : solidCoolants) {
if (solidCoolant.getFluidFromSolidCoolant(solid.stack) != null) {
return solidCoolant;
}
}
return null;
}
private static final class BCCoolant implements ICoolant {
private final Fluid fluid;
private final float degreesCoolingPerMB;
public BCCoolant(Fluid fluid, float degreesCoolingPerMB) {
this.fluid = fluid;
this.degreesCoolingPerMB = degreesCoolingPerMB;
}
@Override
public Fluid getFluid() {
return fluid;
}
@Override
public float getDegreesCoolingPerMB(float heat) {
return degreesCoolingPerMB;
}
}
private static final class BCSolidCoolant implements ISolidCoolant {
private final StackKey solid;
private final StackKey liquid;
private final float multiplier;
public BCSolidCoolant(StackKey solid, StackKey liquid, float multiplier) {
this.solid = solid;
this.liquid = liquid;
this.multiplier = multiplier;
}
@Override
public FluidStack getFluidFromSolidCoolant(ItemStack stack) {
if (stack == null || !stack.isItemEqual(solid.stack)) {
return null;
}
int liquidAmount = (int) (stack.stackSize * liquid.fluidStack.amount * multiplier / solid.stack.stackSize);
return new FluidStack(liquid.fluidStack.fluidID, liquidAmount);
}
}
}