Skip to content

Commit 2d052e5

Browse files
committed
Refactored TickTimer.
1 parent 1c27f10 commit 2d052e5

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

energy/src/main/java/sunsetsatellite/catalyst/energy/impl/TileEntityEnergy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class TileEntityEnergy extends TileEntity implements IEnergy {
1818
public HashMap<Direction, Connection> connections = new HashMap<>();
1919

2020
public TileEntityEnergy(){
21-
this.lastTransferMemory = new TickTimer(this,"clearLastTransfers",10,true);
21+
this.lastTransferMemory = new TickTimer(this,this::clearLastTransfers,10,true);
2222
for (Direction dir : Direction.values()) {
2323
connections.put(dir, Connection.NONE);
2424
}

fluids/src/main/java/sunsetsatellite/catalyst/fluids/util/FluidStack.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ public FluidStack(CompoundTag nbt){
1818
readFromNBT(nbt);
1919
}
2020

21-
public BlockFluid getLiquid(){
21+
public FluidStack(BlockFluid block) {
22+
this(block, 1000);
23+
}
24+
25+
public int getAmount() {
26+
return amount;
27+
}
28+
29+
public BlockFluid getLiquid(){
2230
return liquid;
2331
}
2432

@@ -74,4 +82,12 @@ public static boolean areFluidStacksEqual(FluidStack fluidStack, FluidStack flui
7482
}
7583
}
7684

85+
public static boolean areFluidsEqual(FluidStack fluidStack, FluidStack fluidStack1) {
86+
if (fluidStack == null && fluidStack1 == null) {
87+
return true;
88+
} else {
89+
return fluidStack != null && fluidStack1 != null && fluidStack.isFluidEqual(fluidStack1);
90+
}
91+
}
92+
7793
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package sunsetsatellite.catalyst.core.util;
2+
3+
/**
4+
* Represents a function that accepts no arguments and produces no result.
5+
*
6+
* <p>This is a functional interface
7+
* whose functional method is {@link #run()}.
8+
*/
9+
@FunctionalInterface
10+
public interface Procedure {
11+
12+
/**
13+
* Runs the procedure.
14+
*/
15+
void run();
16+
}

src/main/java/sunsetsatellite/catalyst/core/util/TickTimer.java

+4-20
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
package sunsetsatellite.catalyst.core.util;
22

3-
import java.lang.reflect.InvocationTargetException;
4-
import java.lang.reflect.Method;
5-
63
public class TickTimer {
74
public Object owner;
8-
public Method timeout;
5+
public Procedure timeoutMethod;
96
public int max = 0;
107
public int value = 0;
118
public boolean loop = true;
129

13-
public TickTimer(Object owner, String method, int max, boolean loop){
14-
Method timeout;
15-
try {
16-
timeout = owner.getClass().getMethod(method);
17-
} catch (NoSuchMethodException e) {
18-
throw new RuntimeException(e);
19-
}
10+
public TickTimer(Object owner, Procedure method, int max, boolean loop){
2011
this.owner = owner;
21-
this.timeout = timeout;
12+
this.timeoutMethod = method;
2213
this.max = max;
2314
this.loop = loop;
2415
}
@@ -33,14 +24,7 @@ public void tick(){
3324
} else {
3425
value = -1;
3526
}
36-
try {
37-
timeout.invoke(owner);
38-
} catch (IllegalAccessException | InvocationTargetException e) {
39-
e.printStackTrace();
40-
if(e.getCause() instanceof Error){
41-
throw new Error("Fatal error occurred when invoking method.");
42-
}
43-
}
27+
timeoutMethod.run();
4428
}
4529
}
4630

0 commit comments

Comments
 (0)