-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/reobf/proghatches/gt/metatileentity/ListeningFluidTank.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package reobf.proghatches.gt.metatileentity; | ||
|
||
import java.util.Optional; | ||
|
||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.FluidTank; | ||
import net.minecraftforge.fluids.FluidTankInfo; | ||
|
||
public class ListeningFluidTank extends FluidTank{ | ||
|
||
public ListeningFluidTank(int capacity,DualInputHatch thiz) { | ||
super(capacity); | ||
addListener(thiz::onFill); | ||
} | ||
public ListeningFluidTank(FluidStack stack, int capacity,DualInputHatch thiz) { | ||
super(stack, capacity); | ||
addListener(thiz::onFill); | ||
} | ||
public ListeningFluidTank(Fluid fluid, int amount, int capacity,DualInputHatch thiz) { | ||
super(fluid, amount, capacity); | ||
addListener(thiz::onFill); | ||
} | ||
Optional<Runnable> callback=Optional.empty(); | ||
|
||
public ListeningFluidTank addListener(Runnable c){ | ||
if(callback.isPresent())throw new RuntimeException("callback exists"); | ||
callback=Optional.of(c);return this; | ||
} | ||
@Override | ||
public int fill(FluidStack resource, boolean doFill) { | ||
try{return super.fill(resource, doFill);}finally{callback.ifPresent(Runnable::run);} | ||
} | ||
@Override | ||
public void setFluid(FluidStack fluid) { | ||
super.setFluid(fluid); | ||
callback.ifPresent(Runnable::run); | ||
} | ||
|
||
|
||
public int fillDirect(FluidStack resource, boolean doFill) { | ||
return super.fill(resource, doFill); | ||
} | ||
|
||
public void setFluidDirect(FluidStack fluid) { | ||
super.setFluid(fluid); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.