Update to forge's new fluid system

This commit is contained in:
Ellpeck 2016-06-05 02:16:52 +02:00
parent 193bd806a3
commit c5cf9ec90f
18 changed files with 170 additions and 315 deletions

View file

@ -19,7 +19,7 @@ group = "de.ellpeck.actuallyadditions"
archivesBaseName = "ActuallyAdditions"
minecraft {
version = "1.9.4-12.17.0.1936-1.9.4"
version = "1.9.4-12.17.0.1951"
runDir = "idea"
mappings = "snapshot_20160519"

View file

@ -47,7 +47,7 @@ public class BlockCanolaPress extends BlockContainerBase{
if(!world.isRemote){
TileEntityCanolaPress press = (TileEntityCanolaPress)world.getTileEntity(pos);
if(press != null){
if(this.checkFailUseItemOnTank(player, stack, side, press)){
if(this.checkFailUseItemOnTank(player, stack, press.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.CANOLA_PRESS.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}

View file

@ -70,7 +70,7 @@ public class BlockCoffeeMachine extends BlockContainerBase{
if(!world.isRemote){
TileEntityCoffeeMachine machine = (TileEntityCoffeeMachine)world.getTileEntity(pos);
if(machine != null){
if(this.checkFailUseItemOnTank(player, stack, f6, machine)){
if(this.checkFailUseItemOnTank(player, stack, machine.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.COFFEE_MACHINE.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}

View file

@ -53,7 +53,7 @@ public class BlockFermentingBarrel extends BlockContainerBase{
if(!world.isRemote){
TileEntityFermentingBarrel press = (TileEntityFermentingBarrel)world.getTileEntity(pos);
if(press != null){
if(this.checkFailUseItemOnTank(player, heldItem, par6, press)){
if(this.checkFailUseItemOnTank(player, heldItem, press.canolaTank) && this.checkFailUseItemOnTank(player, heldItem, press.oilTank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FERMENTING_BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}

View file

@ -61,7 +61,7 @@ public class BlockFluidCollector extends BlockContainerBase{
if(!world.isRemote){
TileEntityFluidCollector collector = (TileEntityFluidCollector)world.getTileEntity(pos);
if(collector != null){
if(this.checkFailUseItemOnTank(player, stack, par6, collector)){
if(this.checkFailUseItemOnTank(player, stack, collector.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FLUID_COLLECTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}

View file

@ -69,7 +69,7 @@ public class BlockOilGenerator extends BlockContainerBase{
if(!world.isRemote){
TileEntityOilGenerator generator = (TileEntityOilGenerator)world.getTileEntity(pos);
if(generator != null){
if(this.checkFailUseItemOnTank(player, stack, par6, generator)){
if(this.checkFailUseItemOnTank(player, stack, generator.tank)){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.OIL_GENERATOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
}

View file

@ -31,13 +31,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.*;
import java.util.ArrayList;
import java.util.Random;
@ -174,8 +171,8 @@ public abstract class BlockContainerBase extends BlockContainer{
}
}
protected boolean checkFailUseItemOnTank(EntityPlayer player, ItemStack heldItem, EnumFacing sideHit, IFluidHandler tank){
return heldItem == null || !FluidUtil.interactWithTank(heldItem, player, tank, sideHit);
protected boolean checkFailUseItemOnTank(EntityPlayer player, ItemStack heldItem, FluidTank tank){
return heldItem == null || !FluidUtil.interactWithFluidHandler(heldItem, tank, player);
}
@Override

View file

@ -20,9 +20,13 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
@ -195,4 +199,24 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
}
}
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
return this.getCapability(capability, facing) != null;
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
IFluidHandler tank = this.getFluidHandler(facing);
if(tank != null){
return (T)tank;
}
}
return super.getCapability(capability, facing);
}
public IFluidHandler getFluidHandler(EnumFacing facing){
return null;
}
}

View file

@ -24,13 +24,18 @@ import net.minecraftforge.fluids.*;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler, IEnergySaver, IFluidSaver{
public class TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver, IFluidSaver{
public static final int PRODUCE = 80;
public static final int ENERGY_USE = 35;
private static final int TIME = 30;
public final EnergyStorage storage = new EnergyStorage(40000);
public final FluidTank tank = new FluidTank(2*Util.BUCKET);
public final FluidTank tank = new FluidTank(2*Util.BUCKET){
@Override
public boolean canFill(){
return false;
}
};
public int currentProcessTime;
private int lastEnergyStored;
private int lastTankAmount;
@ -88,7 +93,7 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
this.slots[0] = null;
}
this.tank.fill(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
this.markDirty();
}
}
@ -98,12 +103,12 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
}
if(this.tank.getFluidAmount() > 0){
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.DOWN, this.tank);
WorldUtil.pushFluid(this, EnumFacing.DOWN);
if(!this.isRedstonePowered){
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.NORTH, this.tank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.EAST, this.tank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.SOUTH, this.tank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.WEST, this.tank);
WorldUtil.pushFluid(this, EnumFacing.NORTH);
WorldUtil.pushFluid(this, EnumFacing.EAST);
WorldUtil.pushFluid(this, EnumFacing.SOUTH);
WorldUtil.pushFluid(this, EnumFacing.WEST);
}
}
@ -154,39 +159,6 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
return true;
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
if(resource.getFluid() == InitFluids.fluidCanolaOil){
return this.tank.drain(resource.amount, doDrain);
}
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
return this.tank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid){
return false;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid){
return from != EnumFacing.UP;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from){
return new FluidTankInfo[]{this.tank.getInfo()};
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
@ -206,4 +178,9 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
public void setFluids(FluidStack[] fluids){
this.tank.setFluid(fluids[0]);
}
@Override
public FluidTank getFluidHandler(EnumFacing facing){
return facing != EnumFacing.UP ? this.tank : null;
}
}

View file

@ -29,7 +29,7 @@ import net.minecraftforge.fluids.*;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, IEnergyReceiver, IFluidSaver, IFluidHandler, IEnergySaver{
public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, IEnergyReceiver, IFluidSaver, IEnergySaver{
public static final int SLOT_COFFEE_BEANS = 0;
public static final int SLOT_INPUT = 1;
@ -40,7 +40,17 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
public static final int COFFEE_CACHE_MAX_AMOUNT = 300;
private static final int TIME_USED = 500;
public final EnergyStorage storage = new EnergyStorage(300000);
public final FluidTank tank = new FluidTank(4*Util.BUCKET);
public final FluidTank tank = new FluidTank(4*Util.BUCKET){
@Override
public boolean canDrain(){
return false;
}
@Override
public boolean canFillFluidType(FluidStack fluid){
return fluid.getFluid() == FluidRegistry.WATER;
}
};
public int coffeeCacheAmount;
public int brewTime;
private int lastEnergy;
@ -159,7 +169,7 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
this.slots[SLOT_INPUT] = null;
}
this.coffeeCacheAmount -= CACHE_USE;
this.tank.drain(WATER_USE, true);
this.tank.drainInternal(WATER_USE, true);
}
}
}
@ -206,36 +216,6 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
return true;
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
return resource.getFluid() == FluidRegistry.WATER && from != EnumFacing.DOWN ? this.tank.fill(resource, doFill) : 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
return null;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid){
return true;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid){
return false;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from){
return new FluidTankInfo[]{this.tank.getInfo()};
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
@ -255,4 +235,9 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
public void setFluids(FluidStack[] fluids){
this.tank.setFluid(fluids[0]);
}
@Override
public FluidTank getFluidHandler(EnumFacing facing){
return facing != EnumFacing.DOWN ? this.tank : null;
}
}

View file

@ -16,14 +16,32 @@ import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.capability.*;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidHandlerFluidMap;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityFermentingBarrel extends TileEntityBase implements IFluidHandler, IFluidSaver{
public class TileEntityFermentingBarrel extends TileEntityBase implements IFluidSaver{
private static final int PROCESS_TIME = 100;
public final FluidTank canolaTank = new FluidTank(2*Util.BUCKET);
public final FluidTank oilTank = new FluidTank(2*Util.BUCKET);
public final FluidTank canolaTank = new FluidTank(2*Util.BUCKET){
@Override
public boolean canDrain(){
return false;
}
@Override
public boolean canFillFluidType(FluidStack fluid){
return fluid.getFluid() == InitFluids.fluidCanolaOil;
}
};
public final FluidTank oilTank = new FluidTank(2*Util.BUCKET){
@Override
public boolean canFill(){
return false;
}
};
public int currentProcessTime;
private int lastCanola;
private int lastOil;
@ -62,8 +80,8 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IFluid
if(this.currentProcessTime >= PROCESS_TIME){
this.currentProcessTime = 0;
this.oilTank.fill(new FluidStack(InitFluids.fluidOil, produce), true);
this.canolaTank.drain(produce, true);
this.oilTank.fillInternal(new FluidStack(InitFluids.fluidOil, produce), true);
this.canolaTank.drainInternal(produce, true);
this.markDirty();
}
}
@ -72,12 +90,12 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IFluid
}
if(this.oilTank.getFluidAmount() > 0){
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.DOWN, this.oilTank);
WorldUtil.pushFluid(this, EnumFacing.DOWN);
if(!this.isRedstonePowered){
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.NORTH, this.oilTank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.EAST, this.oilTank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.SOUTH, this.oilTank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.WEST, this.oilTank);
WorldUtil.pushFluid(this, EnumFacing.NORTH);
WorldUtil.pushFluid(this, EnumFacing.EAST);
WorldUtil.pushFluid(this, EnumFacing.SOUTH);
WorldUtil.pushFluid(this, EnumFacing.WEST);
}
}
@ -105,39 +123,15 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IFluid
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
if(from != EnumFacing.DOWN && resource.getFluid() == InitFluids.fluidCanolaOil){
return this.canolaTank.fill(resource, doFill);
public IFluidHandler getFluidHandler(EnumFacing facing){
FluidHandlerFluidMap map = new FluidHandlerFluidMap();
if(facing != EnumFacing.DOWN){
map.addHandler(InitFluids.fluidCanolaOil, this.canolaTank);
}
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
if(resource.getFluid() == InitFluids.fluidOil){
return this.oilTank.drain(resource.amount, doDrain);
if(facing != EnumFacing.UP){
map.addHandler(InitFluids.fluidOil, this.oilTank);
}
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
return this.oilTank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid){
return from != EnumFacing.DOWN && fluid == InitFluids.fluidCanolaOil;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid){
return from != EnumFacing.UP && fluid == InitFluids.fluidOil;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from){
return new FluidTankInfo[]{this.canolaTank.getInfo(), this.oilTank.getInfo()};
return map;
}
@Override

View file

@ -21,10 +21,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.capability.*;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityFluidCollector extends TileEntityBase implements IFluidHandler, IFluidSaver, IRedstoneToggle{
public class TileEntityFluidCollector extends TileEntityBase implements IFluidSaver, IRedstoneToggle{
public final FluidTank tank = new FluidTank(8*Util.BUCKET);
public boolean isPlacer;
@ -63,20 +65,20 @@ public class TileEntityFluidCollector extends TileEntityBase implements IFluidHa
Block blockToBreak = PosUtil.getBlock(coordsBlock, this.worldObj);
if(!this.isPlacer && blockToBreak != null && PosUtil.getMetadata(coordsBlock, this.worldObj) == 0 && Util.BUCKET <= this.tank.getCapacity()-this.tank.getFluidAmount()){
if(blockToBreak instanceof IFluidBlock && ((IFluidBlock)blockToBreak).getFluid() != null){
if(this.tank.fill(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), Util.BUCKET), false) >= Util.BUCKET){
this.tank.fill(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), Util.BUCKET), true);
if(this.tank.fillInternal(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), Util.BUCKET), false) >= Util.BUCKET){
this.tank.fillInternal(new FluidStack(((IFluidBlock)blockToBreak).getFluid(), Util.BUCKET), true);
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.pos);
}
}
else if(blockToBreak == Blocks.LAVA || blockToBreak == Blocks.FLOWING_LAVA){
if(this.tank.fill(new FluidStack(FluidRegistry.LAVA, Util.BUCKET), false) >= Util.BUCKET){
this.tank.fill(new FluidStack(FluidRegistry.LAVA, Util.BUCKET), true);
if(this.tank.fillInternal(new FluidStack(FluidRegistry.LAVA, Util.BUCKET), false) >= Util.BUCKET){
this.tank.fillInternal(new FluidStack(FluidRegistry.LAVA, Util.BUCKET), true);
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.pos);
}
}
else if(blockToBreak == Blocks.WATER || blockToBreak == Blocks.FLOWING_WATER){
if(this.tank.fill(new FluidStack(FluidRegistry.WATER, Util.BUCKET), false) >= Util.BUCKET){
this.tank.fill(new FluidStack(FluidRegistry.WATER, Util.BUCKET), true);
if(this.tank.fillInternal(new FluidStack(FluidRegistry.WATER, Util.BUCKET), false) >= Util.BUCKET){
this.tank.fillInternal(new FluidStack(FluidRegistry.WATER, Util.BUCKET), true);
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.pos);
}
}
@ -90,7 +92,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements IFluidHa
boolean placeable = !(blockPresent instanceof BlockLiquid) && !(blockPresent instanceof IFluidBlock) && blockPresent.isReplaceable(this.worldObj, offsetPos);
if(placeable){
PosUtil.setBlock(offsetPos, this.worldObj, block, 0, 3);
this.tank.drain(Util.BUCKET, true);
this.tank.drainInternal(Util.BUCKET, true);
}
}
}
@ -98,42 +100,8 @@ public class TileEntityFluidCollector extends TileEntityBase implements IFluidHa
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
if(this.isPlacer){
return this.tank.fill(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
if(!this.isPlacer){
return this.tank.drain(resource.amount, doDrain);
}
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
if(!this.isPlacer){
return this.tank.drain(maxDrain, doDrain);
}
return null;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid){
return this.isPlacer;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid){
return !this.isPlacer;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from){
return new FluidTankInfo[]{this.tank.getInfo()};
public IFluidHandler getFluidHandler(EnumFacing facing){
return this.tank;
}
@Override
@ -168,12 +136,12 @@ public class TileEntityFluidCollector extends TileEntityBase implements IFluidHa
}
if(!this.isPlacer && this.tank.getFluidAmount() > 0){
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.DOWN, this.tank);
WorldUtil.pushFluid(this, EnumFacing.DOWN);
if(!this.isRedstonePowered){
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.NORTH, this.tank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.EAST, this.tank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.SOUTH, this.tank);
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.WEST, this.tank);
WorldUtil.pushFluid(this, EnumFacing.NORTH);
WorldUtil.pushFluid(this, EnumFacing.EAST);
WorldUtil.pushFluid(this, EnumFacing.SOUTH);
WorldUtil.pushFluid(this, EnumFacing.WEST);
}
}

View file

@ -217,12 +217,6 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
return new TextComponentTranslation(this.getName());
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
return this.getCapability(capability, facing) != null;
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
if(this.hasInvWrapperCapabilities() && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){

View file

@ -19,15 +19,27 @@ import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.capability.*;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEntityOilGenerator extends TileEntityBase implements IEnergyProvider, IFluidHandler, IEnergySaver, IFluidSaver{
public class TileEntityOilGenerator extends TileEntityBase implements IEnergyProvider, IEnergySaver, IFluidSaver{
public static final int ENERGY_PRODUCED = 76;
private static final int BURN_TIME = 100;
public final EnergyStorage storage = new EnergyStorage(50000);
public final FluidTank tank = new FluidTank(2*Util.BUCKET);
public final FluidTank tank = new FluidTank(2*Util.BUCKET){
@Override
public boolean canDrain(){
return false;
}
@Override
public boolean canFillFluidType(FluidStack fluid){
return fluid.getFluid() == InitFluids.fluidOil;
}
};
public int currentBurnTime;
private int lastEnergy;
private int lastTank;
@ -84,7 +96,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro
if(ENERGY_PRODUCED*BURN_TIME <= this.storage.getMaxEnergyStored()-this.storage.getEnergyStored()){
if(this.currentBurnTime <= 0 && this.tank.getFluidAmount() >= fuelUsed){
this.currentBurnTime = BURN_TIME;
this.tank.drain(fuelUsed, true);
this.tank.drainInternal(fuelUsed, true);
}
}
@ -134,36 +146,8 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
if(resource.getFluid() == InitFluids.fluidOil){
return this.tank.fill(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
return null;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid){
return from != EnumFacing.DOWN && fluid == InitFluids.fluidOil;
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid){
return false;
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from){
return new FluidTankInfo[]{this.tank.getInfo()};
public IFluidHandler getFluidHandler(EnumFacing facing){
return facing != EnumFacing.DOWN ? this.tank : null;
}
@Override

View file

@ -119,15 +119,4 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface{
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canExtractItem(slot, stack, side));
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).hasCapability(capability, facing) : super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).getCapability(capability, facing) : super.getCapability(capability, facing);
}
}

View file

@ -14,12 +14,11 @@ import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{
public class TileEntityPhantomLiquiface extends TileEntityPhantomface{
public TileEntityPhantomLiquiface(){
super("liquiface");
@ -31,41 +30,9 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
super.updateEntity();
if(!this.worldObj.isRemote){
if(this.isRedstonePowered && this.isBoundThingInRange() && this.getHandler() != null){
this.pushFluid(EnumFacing.UP);
this.pushFluid(EnumFacing.DOWN);
this.pushFluid(EnumFacing.NORTH);
this.pushFluid(EnumFacing.EAST);
this.pushFluid(EnumFacing.SOUTH);
this.pushFluid(EnumFacing.WEST);
}
}
}
public IFluidHandler getHandler(){
if(this.boundPosition != null){
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
if(tile instanceof IFluidHandler){
return (IFluidHandler)tile;
}
}
return null;
}
private void pushFluid(EnumFacing side){
TileEntity tile = WorldUtil.getTileEntityFromSide(side, this.worldObj, this.pos);
if(tile != null && tile instanceof IFluidHandler && this.getTankInfo(side) != null && this.getTankInfo(side).length > 0 && ((IFluidHandler)tile).getTankInfo(side.getOpposite()) != null && ((IFluidHandler)tile).getTankInfo(side.getOpposite()).length > 0){
for(FluidTankInfo myInfo : this.getTankInfo(side)){
for(FluidTankInfo hisInfo : ((IFluidHandler)tile).getTankInfo(side.getOpposite())){
if(myInfo != null && hisInfo != null && myInfo.fluid != null && myInfo.fluid.getFluid() != null){
if(((IFluidHandler)tile).canFill(side.getOpposite(), myInfo.fluid.getFluid()) && this.canDrain(side, myInfo.fluid.getFluid())){
FluidStack receive = this.drain(side, Math.min(hisInfo.capacity-(hisInfo.fluid == null ? 0 : hisInfo.fluid.amount), myInfo.fluid.amount), false);
if(receive != null){
int actualReceive = ((IFluidHandler)tile).fill(side.getOpposite(), receive, true);
this.drain(side, new FluidStack(receive.getFluid(), actualReceive), true);
}
}
}
if(this.isRedstonePowered && this.isBoundThingInRange()){
for(EnumFacing side : EnumFacing.values()){
WorldUtil.pushFluid(this, side);
}
}
}
@ -73,48 +40,6 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
@Override
public boolean isBoundThingInRange(){
return super.isBoundThingInRange() && this.worldObj.getTileEntity(this.boundPosition) instanceof IFluidHandler;
}
@Override
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
if(this.isBoundThingInRange()){
return this.getHandler().fill(from, resource, doFill);
}
return 0;
}
@Override
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
if(this.isBoundThingInRange()){
return this.getHandler().drain(from, resource, doDrain);
}
return null;
}
@Override
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
if(this.isBoundThingInRange()){
return this.getHandler().drain(from, maxDrain, doDrain);
}
return null;
}
@Override
public boolean canFill(EnumFacing from, Fluid fluid){
return this.isBoundThingInRange() && this.getHandler().canFill(from, fluid);
}
@Override
public boolean canDrain(EnumFacing from, Fluid fluid){
return this.isBoundThingInRange() && this.getHandler().canDrain(from, fluid);
}
@Override
public FluidTankInfo[] getTankInfo(EnumFacing from){
if(this.isBoundThingInRange()){
return this.getHandler().getTankInfo(from);
}
return new FluidTankInfo[0];
return super.isBoundThingInRange() && this.worldObj.getTileEntity(this.boundPosition).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
}
}

View file

@ -23,6 +23,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -190,4 +191,14 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
public boolean hasInvWrapperCapabilities(){
return false;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing){
return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).hasCapability(capability, facing) : super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing){
return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).getCapability(capability, facing) : super.getCapability(capability, facing);
}
}

View file

@ -40,6 +40,8 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.capability.*;
import net.minecraftforge.fluids.capability.IFluidHandler;
import java.util.ArrayList;
import java.util.List;
@ -100,12 +102,17 @@ public class WorldUtil{
return true;
}
public static void pushFluid(World world, BlockPos pos, EnumFacing side, FluidTank tank){
TileEntity tile = getTileEntityFromSide(side, world, pos);
if(tile != null && tank.getFluid() != null && tile instanceof IFluidHandler){
if(((IFluidHandler)tile).canFill(side.getOpposite(), tank.getFluid().getFluid())){
int receive = ((IFluidHandler)tile).fill(side.getOpposite(), tank.getFluid(), true);
tank.drain(receive, true);
public static void pushFluid(TileEntity tileFrom, EnumFacing side){
TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos());
if(tileTo != null){
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite());
if(handlerFrom != null && handlerTo != null){
FluidStack drain = handlerFrom.drain(Integer.MAX_VALUE, false);
if(drain != null){
int filled = handlerTo.fill(drain.copy(), true);
handlerFrom.drain(filled, true);
}
}
}
}