mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-15 17:44:46 +00:00
Certus Quartz Tank add waila support
fluid packet decode add support to use conduit to export fluid
This commit is contained in:
1 parent
ebf5a23ab9
commit
78e9291fc6
8 files changed
+285
-7
No files matched your search
@@ -1,14 +1,17 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.*;
|
||||
|
||||
import com.glodblock.github.loader.ChannelLoader;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
|
||||
public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
|
||||
@@ -26,6 +29,7 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
private boolean hasUpdate;
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
@@ -191,6 +195,40 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
return (float) this.tank.getFluidAmount() / this.tank.getCapacity();
|
||||
}
|
||||
|
||||
private void onComparatorUpdate(World world, int x, int y, int z, Block block) {
|
||||
world.func_147453_f(x, y, z, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (this.tank.getFluid() != null) {
|
||||
TileCertusQuartzTank below = getTankBelow(this);
|
||||
if (below != null) {
|
||||
FluidStack filled = this.tank.getFluid().copy();
|
||||
filled.amount = below.fill(this.tank.getFluid(), true, true);
|
||||
if (filled.amount >= 0) {
|
||||
this.drain(filled, true, true);
|
||||
this.hasUpdate = true;
|
||||
below.hasUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hasUpdate) {
|
||||
onComparatorUpdate(this.worldObj, this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
|
||||
this.hasUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
private TileCertusQuartzTank getTankBelow(TileEntity tile) {
|
||||
TileEntity tank = new BlockPos(tile).getOffSet(0, -1, 0).getTileEntity();
|
||||
if (tank != null && tank instanceof TileCertusQuartzTank) {
|
||||
return (TileCertusQuartzTank) tank;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluidTankInfo[] getTankInfo(boolean goToMainTank) {
|
||||
if (!goToMainTank) return new FluidTankInfo[] { this.tank.getInfo() };
|
||||
|
||||
@@ -212,12 +250,12 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
break;
|
||||
}
|
||||
|
||||
yOff = 0;
|
||||
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
|
||||
yOff -= 1;
|
||||
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
|
||||
while (true) {
|
||||
if (offTE instanceof TileCertusQuartzTank) {
|
||||
mainTank = (TileCertusQuartzTank) offTE;
|
||||
if (mainTank.getFluid() == null || mainTank.getFluid() == getFluid()) {
|
||||
if (mainTank.getFluid() == null || getFluid() == null || mainTank.getFluid() == getFluid()) {
|
||||
FluidTankInfo info = mainTank.getTankInfo(false)[0];
|
||||
if (info != null) {
|
||||
capacity += info.capacity;
|
||||
@@ -226,8 +264,7 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
if (info.fluid.getFluid() != null) fluid = info.fluid.getFluid();
|
||||
}
|
||||
}
|
||||
yOff++;
|
||||
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
|
||||
offTE = new BlockPos(offTE).getOffSet(0, 1, 0).getTileEntity();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -274,4 +311,8 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
|
||||
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
|
||||
this.tank.writeToNBT(tag);
|
||||
}
|
||||
|
||||
public FluidTankInfo[] getInternalFluid() {
|
||||
return this.getTankInfo(true);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.*;
|
||||
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
@@ -30,7 +31,8 @@ import appeng.util.item.AEFluidStack;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
|
||||
public class TileFluidPacketDecoder extends AENetworkTile implements IGridTickable, IAEAppEngInventory, IInventory {
|
||||
public class TileFluidPacketDecoder extends AENetworkTile
|
||||
implements IGridTickable, IAEAppEngInventory, IInventory, IFluidHandler {
|
||||
|
||||
private final AppEngInternalInventory inventory = new AppEngInternalInventory(this, 1);
|
||||
private final BaseActionSource ownActionSource = new MachineSource(this);
|
||||
@@ -164,4 +166,65 @@ public class TileFluidPacketDecoder extends AENetworkTile implements IGridTickab
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemFluidPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack requestFluid, boolean doDrain) {
|
||||
return this.drain(requestFluid, doDrain);
|
||||
}
|
||||
|
||||
private FluidStack drain(FluidStack requestFluid, boolean doDrain) {
|
||||
if (requestFluid == null || requestFluid.amount <= 0) return null;
|
||||
ItemStack fluidPacket = this.inventory.getStackInSlot(0);
|
||||
if (fluidPacket != null) {
|
||||
FluidStack fs = ItemFluidPacket.getFluidStack(fluidPacket);
|
||||
if (fs.isFluidEqual(requestFluid)) {
|
||||
if (fs.amount > requestFluid.amount) {
|
||||
fs.amount -= requestFluid.amount;
|
||||
if (doDrain) this.inventory.setInventorySlotContents(0, ItemFluidPacket.newStack(fs));
|
||||
return requestFluid;
|
||||
} else {
|
||||
if (doDrain) this.inventory.setInventorySlotContents(0, null);
|
||||
return fs;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
ItemStack fluidPacket = this.inventory.getStackInSlot(0);
|
||||
if (fluidPacket != null) {
|
||||
FluidStack requestFluid = ItemFluidPacket.getFluidStack(fluidPacket);
|
||||
requestFluid.amount = maxDrain;
|
||||
return this.drain(requestFluid, doDrain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
ItemStack fluidPacket = this.inventory.getStackInSlot(0);
|
||||
if (fluidPacket == null) {
|
||||
return new FluidTankInfo[0];
|
||||
} else {
|
||||
FluidStack fs = ItemFluidPacket.getFluidStack(fluidPacket);
|
||||
return new FluidTankInfo[] { new FluidTankInfo(fs, fs.amount) };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user