2015-10-10 02:58:07 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityPhantomLiquiface.java") is part of the Actually Additions mod for Minecraft.
|
2015-10-10 02:58:07 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-10-10 02:58:07 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-10-10 02:58:07 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
2016-06-07 23:22:26 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 19:04:29 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-09-02 08:33:54 +02:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
2016-06-05 02:16:52 +02:00
|
|
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
2016-09-02 08:33:54 +02:00
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
|
|
|
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
2016-08-31 20:16:36 +02:00
|
|
|
public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler{
|
2015-10-10 02:58:07 +02:00
|
|
|
|
|
|
|
public TileEntityPhantomLiquiface(){
|
|
|
|
super("liquiface");
|
|
|
|
this.type = BlockPhantom.Type.LIQUIFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBoundThingInRange(){
|
2016-06-07 23:22:26 +02:00
|
|
|
if(super.isBoundThingInRange()){
|
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
2016-09-02 08:33:54 +02:00
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for(EnumFacing facing : EnumFacing.values()){
|
|
|
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-07 23:22:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
2016-06-10 22:00:30 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
|
|
|
|
if(this.isBoundThingInRange()){
|
2016-09-02 08:33:54 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return ((net.minecraftforge.fluids.IFluidHandler)tile).fill(from, resource, doFill);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from)){
|
|
|
|
IFluidHandler cap = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.fill(resource, doFill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
|
|
|
|
if(this.isBoundThingInRange()){
|
2016-09-02 08:33:54 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return ((net.minecraftforge.fluids.IFluidHandler)tile).drain(from, resource, doDrain);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from)){
|
|
|
|
IFluidHandler cap = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.drain(resource, doDrain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
|
|
|
|
if(this.isBoundThingInRange()){
|
2016-09-02 08:33:54 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return ((net.minecraftforge.fluids.IFluidHandler)tile).drain(from, maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from)){
|
|
|
|
IFluidHandler cap = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.drain(maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid){
|
2016-09-02 08:33:54 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return ((net.minecraftforge.fluids.IFluidHandler)tile).canFill(from, fluid);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from)){
|
|
|
|
IFluidHandler cap = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from);
|
|
|
|
if(cap != null){
|
|
|
|
FluidStack stack = new FluidStack(fluid, 1);
|
|
|
|
IFluidTankProperties[] props = cap.getTankProperties();
|
|
|
|
if(props != null){
|
|
|
|
for(IFluidTankProperties prop : props){
|
|
|
|
if(prop.canFillFluidType(stack)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid){
|
2016-09-02 08:33:54 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return ((net.minecraftforge.fluids.IFluidHandler)tile).canDrain(from, fluid);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from)){
|
|
|
|
IFluidHandler cap = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, from);
|
|
|
|
if(cap != null){
|
|
|
|
FluidStack stack = new FluidStack(fluid, 1);
|
|
|
|
IFluidTankProperties[] props = cap.getTankProperties();
|
|
|
|
if(props != null){
|
|
|
|
for(IFluidTankProperties prop : props){
|
|
|
|
if(prop.canDrainFluidType(stack)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from){
|
2016-09-02 08:33:54 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile instanceof net.minecraftforge.fluids.IFluidHandler){
|
|
|
|
return ((net.minecraftforge.fluids.IFluidHandler)tile).getTankInfo(from);
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
2016-09-02 08:33:54 +02:00
|
|
|
else{
|
|
|
|
return new FluidTankInfo[0];
|
2016-06-10 22:00:30 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 20:16:36 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFluidAmountToSplitShare(){
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean doesShareFluid(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing[] getFluidShareSides(){
|
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|