Add tank support for Fluid Replicator, fixes https://github.com/TechReborn/TechReborn/issues/1698
This commit is contained in:
parent
ec2fcf5d6d
commit
925a7b4c0a
1 changed files with 21 additions and 0 deletions
|
@ -25,9 +25,14 @@
|
||||||
package techreborn.api.fluidreplicator;
|
package techreborn.api.fluidreplicator;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
import reborncore.common.util.FluidUtils;
|
import reborncore.common.util.FluidUtils;
|
||||||
import techreborn.init.ModItems;
|
import techreborn.init.ModItems;
|
||||||
import techreborn.tiles.multiblock.TileFluidReplicator;
|
import techreborn.tiles.multiblock.TileFluidReplicator;
|
||||||
|
@ -112,6 +117,9 @@ public class FluidReplicatorRecipe implements Cloneable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final BlockPos hole = tile.getPos().offset(tile.getFacing().getOpposite(), 2);
|
final BlockPos hole = tile.getPos().offset(tile.getFacing().getOpposite(), 2);
|
||||||
|
if(hasValidTank(tile.getWorld(), hole)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
final Fluid fluid = FluidRegistry.lookupFluidForBlock(tile.getWorld().getBlockState(hole).getBlock());
|
final Fluid fluid = FluidRegistry.lookupFluidForBlock(tile.getWorld().getBlockState(hole).getBlock());
|
||||||
if (fluid == null) {
|
if (fluid == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -127,6 +135,19 @@ public class FluidReplicatorRecipe implements Cloneable {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasValidTank(World world, BlockPos pos){
|
||||||
|
TileEntity tileEntity = world.getTileEntity(pos);
|
||||||
|
if(tileEntity == null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
|
||||||
|
if(fluidHandler != null){
|
||||||
|
FluidStack containedStack = fluidHandler.drain(1000, false);
|
||||||
|
return containedStack != null && FluidUtils.fluidEquals(containedStack.getFluid(), output);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onCraft(TileFluidReplicator tile) {
|
public boolean onCraft(TileFluidReplicator tile) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue