mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Do not allow rain tanks to be filled from the bottom
This commit is contained in:
1 parent
52b1784f25
commit
27d932ee34
2 files changed
+93
-1
No files matched your search
@@ -0,0 +1,85 @@
|
||||
package forestry.core.fluids;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
|
||||
public class DrainOnlyFluidHandlerWrapper implements IFluidHandler {
|
||||
@Nonnull
|
||||
private final IFluidHandler internalFluidHandler;
|
||||
|
||||
public DrainOnlyFluidHandlerWrapper(@Nonnull IFluidHandler internalFluidHandler) {
|
||||
this.internalFluidHandler = internalFluidHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidTankProperties[] getTankProperties() {
|
||||
IFluidTankProperties[] internalTankProperties = internalFluidHandler.getTankProperties();
|
||||
IFluidTankProperties[] tankProperties = new IFluidTankProperties[internalTankProperties.length];
|
||||
for (int i = 0; i < internalTankProperties.length; i++) {
|
||||
IFluidTankProperties fluidTankProperties = internalTankProperties[i];
|
||||
tankProperties[i] = new DrainOnlyFluidPropertiesWrapper(fluidTankProperties);
|
||||
}
|
||||
return tankProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||
return internalFluidHandler.drain(resource, doDrain);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
return internalFluidHandler.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
private static class DrainOnlyFluidPropertiesWrapper implements IFluidTankProperties {
|
||||
@Nonnull
|
||||
private final IFluidTankProperties internalTankProperties;
|
||||
|
||||
public DrainOnlyFluidPropertiesWrapper(@Nonnull IFluidTankProperties internalTankProperties) {
|
||||
this.internalTankProperties = internalTankProperties;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FluidStack getContents() {
|
||||
return internalTankProperties.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return internalTankProperties.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain() {
|
||||
return internalTankProperties.canDrain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFillFluidType(FluidStack fluidStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrainFluidType(FluidStack fluidStack) {
|
||||
return internalTankProperties.canDrainFluidType(fluidStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import forestry.api.core.IErrorLogic;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.ContainerFiller;
|
||||
import forestry.core.fluids.DrainOnlyFluidHandlerWrapper;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
@@ -189,7 +190,13 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
final IFluidHandler fluidHandler;
|
||||
if (facing == EnumFacing.DOWN) {
|
||||
fluidHandler = new DrainOnlyFluidHandlerWrapper(tankManager);
|
||||
} else {
|
||||
fluidHandler = tankManager;
|
||||
}
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(fluidHandler);
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user