blob: 55bbf712fa7fe92713b6d3d9989b481bc80e863c (
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
85
|
package gregtech.api.objects;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import gregtech.api.GregTech_API;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_Utility;
/**
* Because Forge fucked this one up royally.
*/
public class GT_FluidStack extends FluidStack {
private static final Collection<GT_FluidStack> sAllFluidStacks = Collections
.newSetFromMap(new WeakHashMap<>(10000));
private static volatile boolean lock = false;
private Fluid mFluid;
public GT_FluidStack(Fluid aFluid, int aAmount) {
super(aFluid, aAmount);
mFluid = aFluid;
if (!GregTech_API.mServerStarted) {
sAllFluidStacks.add(this);
}
}
public GT_FluidStack(FluidStack aFluid) {
this(aFluid.getFluid(), aFluid.amount);
}
public static final synchronized void fixAllThoseFuckingFluidIDs() {
if (ForgeVersion.getBuildVersion() < 1355 && ForgeVersion.getRevisionVersion() < 4) {
try {
while (lock) {
Thread.sleep(1);
}
} catch (InterruptedException e) {}
lock = true;
for (GT_FluidStack tFluid : sAllFluidStacks) tFluid.fixFluidIDForFucksSake();
try {
for (Map<Fluid, ?> tMap : GregTech_API.sFluidMappings) GT_Utility.reMap(tMap);
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
lock = false;
}
}
public final void fixFluidIDForFucksSake() {
if (ForgeVersion.getBuildVersion() < 1355 && ForgeVersion.getRevisionVersion() < 4) {
int fluidID;
try {
fluidID = this.getFluid().getID();
} catch (Throwable e) {
System.err.println(e);
}
try {
fluidID = mFluid.getID();
} catch (Throwable e) {
fluidID = -1;
}
}
}
@Override
public FluidStack copy() {
if (ForgeVersion.getBuildVersion() < 1355 && ForgeVersion.getRevisionVersion() < 4) {
fixFluidIDForFucksSake();
}
return new GT_FluidStack(this);
}
@Override
public String toString() {
return String
.format("GT_FluidStack: %s x %s, ID:%s", this.amount, this.getFluid().getName(), this.getFluidID());
}
}
|