This commit is contained in:
GlodBlock committed 2023-01-30 18:07:57 +08:00
1 parent 99f8e98017
commit 482298021e
25 files changed
+1010 -174

No files matched your search

@@ -9,10 +9,14 @@ import net.minecraft.item.ItemStack;
public abstract class BaseBlockContainer extends BlockContainer {
public BaseBlockContainer(Material p_i45386_1_) {
super(p_i45386_1_);
public BaseBlockContainer(Material material) {
super(material);
}
public void addInformation(ItemStack itemStack, EntityPlayer player, List<String> toolTip,
boolean advancedToolTips) {}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -1,11 +1,16 @@
package com.glodblock.github.common.block;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -13,13 +18,11 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.implementations.items.IAEWrench;
import buildcraft.api.tools.IToolWrench;
import buildcraft.factory.BlockTank;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.common.item.ItemCertusQuartzTank;
import com.glodblock.github.common.tabs.FluidCraftingTabs;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.loader.IRegister;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.NameConst;
@@ -28,98 +31,116 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockCertusQuartzTank extends BlockTank implements IRegister<BlockTank> {
public class BlockCertusQuartzTank extends BaseBlockContainer implements IRegister<BlockCertusQuartzTank> {
private IIcon textureStackedSide;
IIcon breakIcon;
IIcon topIcon;
IIcon bottomIcon;
IIcon sideIcon;
IIcon sideMiddleIcon;
IIcon sideTopIcon;
IIcon sideBottomIcon;
public BlockCertusQuartzTank() {
super(Material.glass);
setBlockName(NameConst.BLOCK_CERTUS_QUARTZ_TANK);
setResistance(1.0F);
setHardness(0.5F);
setResistance(10.0F);
setHardness(2.0F);
setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 1.0F, 0.9375F);
}
public ItemStack getDropWithNBT(World world, int x, int y, int z) {
NBTTagCompound nbt = new NBTTagCompound();
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileCertusQuartzTank) {
ItemStack dropStack = new ItemStack(ItemAndBlockHolder.CERTUS_QUARTZ_TANK, 1);
((TileCertusQuartzTank) te).writeToNBTWithoutCoords(nbt);
if (!nbt.getCompoundTag("tank").hasKey("Empty")) {
dropStack.setTagCompound(nbt);
}
@Override
public boolean canRenderInPass(int pass) {
return true;
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileCertusQuartzTank();
}
public ItemStack getDropWithNBT(World world, int x, int y, int z) {
NBTTagCompound tileEntity = new NBTTagCompound();
TileEntity worldTE = world.getTileEntity(x, y, z);
if (worldTE instanceof TileCertusQuartzTank) {
ItemStack dropStack = new ItemStack(ItemAndBlockHolder.CERTUS_QUARTZ_TANK, 1);
((TileCertusQuartzTank) worldTE).writeToNBTWithoutCoords(tileEntity);
if (!tileEntity.hasKey("Empty")) {
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
}
return dropStack;
}
return null;
}
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileCertusQuartzTank();
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
super.registerBlockIcons(par1IconRegister);
textureStackedSide = par1IconRegister.registerIcon(FluidCraft.MODID + ":certus_quartz_tank/side_stacked");
}
@Override
public IIcon getIconAbsolute(IBlockAccess iblockaccess, int x, int y, int z, int side, int metadata) {
if (side >= 2 && (iblockaccess.getBlock(x, y - 1, z) instanceof BlockCertusQuartzTank)) {
return textureStackedSide;
} else {
return super.getIconAbsolute(side, metadata);
public IIcon getIcon(int side, int meta) {
switch (meta) {
case 1:
return this.sideTopIcon;
case 2:
return this.sideBottomIcon;
case 3:
return this.sideMiddleIcon;
default:
return side == 0 ? this.bottomIcon : side == 1 ? this.topIcon : this.sideIcon;
}
}
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer p, int blockID, float offsetX,
float offsetY, float offsetZ) {
ItemStack current = p.inventory.getCurrentItem();
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
return getDropWithNBT(world, x, y, z);
}
if (p.isSneaking() && current != null) {
try {
if (current.getItem() instanceof IToolWrench
&& ((IToolWrench) current.getItem()).canWrench(p, x, y, z)) {
dropBlockAsItem(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
worldObj.setBlockToAir(x, y, z);
((IToolWrench) current.getItem()).wrenchUsed(p, x, y, z);
return true;
}
} catch (Throwable e) {
// No IToolWrench
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileCertusQuartzTank) {
TileCertusQuartzTank tank = (TileCertusQuartzTank) tile;
return tank.getFluidLightLevel();
}
return super.getLightValue(world, x, y, z);
}
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID,
float offsetX, float offsetY, float offsetZ) {
ItemStack current = entityplayer.inventory.getCurrentItem();
if (entityplayer.isSneaking() && current != null) {
if (current.getItem() instanceof IAEWrench
&& ((IAEWrench) current.getItem()).canWrench(current, p, x, y, z)) {
&& ((IAEWrench) current.getItem()).canWrench(current, entityplayer, x, y, z)) {
dropBlockAsItem(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
worldObj.setBlockToAir(x, y, z);
return true;
}
}
if (current != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
TileCertusQuartzTank tank = (TileCertusQuartzTank) worldObj.getTileEntity(x, y, z);
if (liquid != null) {
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (amountFilled != 0 && !p.capabilities.isCreativeMode) {
if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode && current.getItem() != null) {
if (current.stackSize > 1) {
p.inventory.mainInventory[p.inventory.currentItem].stackSize -= 1;
p.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
} else {
p.inventory.mainInventory[p.inventory.currentItem] = current.getItem()
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = current.getItem()
.getContainerItem(current);
}
}
return true;
// Handle empty containers
} else {
FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
if (available != null) {
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
@@ -128,12 +149,13 @@ public class BlockCertusQuartzTank extends BlockTank implements IRegister<BlockT
if (liquid != null) {
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
if (!p.capabilities.isCreativeMode) {
if (!entityplayer.capabilities.isCreativeMode) {
if (current.stackSize == 1) {
p.inventory.mainInventory[p.inventory.currentItem] = filled;
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
} else {
p.inventory.mainInventory[p.inventory.currentItem].stackSize--;
if (!p.inventory.addItemStackToInventory(filled)) p.entityDropItem(filled, 0);
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize--;
if (!entityplayer.inventory.addItemStackToInventory(filled))
entityplayer.entityDropItem(filled, 0);
}
}
return true;
@@ -144,6 +166,41 @@ public class BlockCertusQuartzTank extends BlockTank implements IRegister<BlockT
return false;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
if (!world.isRemote) {
ChannelLoader.sendPacketToAllPlayers(world.getTileEntity(x, y, z).getDescriptionPacket(), world);
}
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack != null && stack.hasTagCompound()) {
if (FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("tileEntity")) != null) list.add(
FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("tileEntity")).amount
+ "mB");
}
}
@Override
public void registerBlockIcons(IIconRegister iconregister) {
String folder = NameConst.RES_KEY + "certus_quartz_tank/";
this.breakIcon = iconregister.registerIcon(folder + "cube");
this.topIcon = iconregister.registerIcon(folder + "top");
this.bottomIcon = iconregister.registerIcon(folder + "bottom");
this.sideIcon = iconregister.registerIcon(folder + "side");
this.sideMiddleIcon = iconregister.registerIcon(folder + "side_mid");
this.sideTopIcon = iconregister.registerIcon(folder + "side_top");
this.sideBottomIcon = iconregister.registerIcon(folder + "side_bottom");
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public BlockCertusQuartzTank register() {
GameRegistry.registerBlock(this, ItemCertusQuartzTank.class, NameConst.BLOCK_CERTUS_QUARTZ_TANK);
@@ -151,8 +208,4 @@ public class BlockCertusQuartzTank extends BlockTank implements IRegister<BlockT
setCreativeTab(FluidCraftingTabs.INSTANCE);
return this;
}
public ItemStack stack() {
return new ItemStack(this, 1);
}
}
@@ -1,12 +1,7 @@
package com.glodblock.github.common.item;
import static com.glodblock.github.common.tile.TileCertusQuartzTank.CAPACITY;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@@ -14,41 +9,24 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.crossmod.waila.Tooltip;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemCertusQuartzTank extends BaseItemBlockContainer implements IFluidContainerItem {
public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerItem {
private final String tagKey = "tank";
private final int capacity = CAPACITY;
private final int capacity = 32000;
public ItemCertusQuartzTank(Block block) {
super(block);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack != null && stack.hasTagCompound()) {
if (FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag(tagKey)) != null) {
FluidStack fs = FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag(tagKey));
list.add(Tooltip.fluidFormat(fs.getFluid().getLocalizedName(fs), fs.amount));
}
}
}
@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey(tagKey)
|| container.stackTagCompound.getCompoundTag(tagKey).hasKey("Empty")) {
if (container.stackSize != 1 || container.stackTagCompound == null
|| !container.stackTagCompound.hasKey("tileEntity")
|| container.stackTagCompound.getCompoundTag("tileEntity").hasKey("Empty")) {
return null;
}
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag(tagKey));
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("tileEntity"));
if (stack == null) {
return null;
}
@@ -57,7 +35,7 @@ public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerIt
stack.amount = Math.min(stack.amount, maxDrain);
if (doDrain) {
if (currentAmount == stack.amount) {
container.stackTagCompound.removeTag(tagKey);
container.stackTagCompound.removeTag("tileEntity");
if (container.stackTagCompound.hasNoTags()) {
container.stackTagCompound = null;
@@ -65,25 +43,26 @@ public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerIt
return stack;
}
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag(tagKey);
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("tileEntity");
fluidTag.setInteger("Amount", currentAmount - stack.amount);
container.stackTagCompound.setTag(tagKey, fluidTag);
container.stackTagCompound.setTag("tileEntity", fluidTag);
}
return stack;
}
@Override
public int fill(ItemStack container, FluidStack resource, boolean doFill) {
if (resource == null) {
if (resource == null || container.stackSize != 1) {
return 0;
}
if (!doFill) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey(tagKey)) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("tileEntity")) {
return Math.min(this.capacity, resource.amount);
}
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag(tagKey));
FluidStack stack = FluidStack
.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("tileEntity"));
if (stack == null) {
return Math.min(this.capacity, resource.amount);
@@ -100,21 +79,21 @@ public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerIt
container.stackTagCompound = new NBTTagCompound();
}
if (!container.stackTagCompound.hasKey(tagKey)
|| container.stackTagCompound.getCompoundTag(tagKey).hasKey("Empty")) {
if (!container.stackTagCompound.hasKey("tileEntity")
|| container.stackTagCompound.getCompoundTag("tileEntity").hasKey("Empty")) {
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
if (this.capacity < resource.amount) {
fluidTag.setInteger("Amount", this.capacity);
container.stackTagCompound.setTag(tagKey, fluidTag);
container.stackTagCompound.setTag("tileEntity", fluidTag);
return this.capacity;
}
container.stackTagCompound.setTag(tagKey, fluidTag);
container.stackTagCompound.setTag("tileEntity", fluidTag);
return resource.amount;
}
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag(tagKey);
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("tileEntity");
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
if (!stack.isFluidEqual(resource)) {
@@ -129,7 +108,7 @@ public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerIt
stack.amount = this.capacity;
}
container.stackTagCompound.setTag(tagKey, stack.writeToNBT(fluidTag));
container.stackTagCompound.setTag("tileEntity", stack.writeToNBT(fluidTag));
return filled;
}
@@ -140,10 +119,10 @@ public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerIt
@Override
public FluidStack getFluid(ItemStack container) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey(tagKey)) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("tileEntity")) {
return null;
}
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag(tagKey));
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("tileEntity"));
}
@Override
@@ -159,7 +138,8 @@ public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerIt
}
if (stack != null && stack.hasTagCompound()) {
((TileCertusQuartzTank) world.getTileEntity(x, y, z)).readFromNBTWithoutCoords(stack.getTagCompound());
((TileCertusQuartzTank) world.getTileEntity(x, y, z))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}
return true;
}
@@ -1,36 +1,274 @@
package com.glodblock.github.common.tile;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import buildcraft.factory.TileTank;
import com.glodblock.github.loader.ChannelLoader;
public class TileCertusQuartzTank extends TileTank {
public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
public static final int CAPACITY = FluidContainerRegistry.BUCKET_VOLUME * 32;
private FluidStack lastBeforeUpdate = null;
public FluidTank tank = new FluidTank(32000) {
public TileCertusQuartzTank() {
super();
this.setCapacity();
@Override
public FluidTank readFromNBT(NBTTagCompound nbt) {
if (!nbt.hasKey("Empty")) {
FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt);
setFluid(fluid);
} else {
setFluid(null);
}
return this;
}
};
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return this.tank.getFluid() == null || this.tank.getFluid().getFluid() == fluid;
}
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
readFromNBTWithoutCoords(data);
this.setCapacity();
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return this.tank.getFluid() == null || this.tank.getFluid().getFluid() == fluid;
}
public int getFluidLightLevel() {
FluidStack tankFluid = tank.getFluid();
return tankFluid == null || tankFluid.amount == 0 ? 0 : tankFluid.getFluid().getLuminosity(tankFluid);
}
public void compareAndUpdate() {
if (!this.worldObj.isRemote) {
FluidStack current = this.tank.getFluid();
if (current != null) {
if (this.lastBeforeUpdate != null) {
if (Math.abs(current.amount - this.lastBeforeUpdate.amount) >= 500) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
} else if (this.lastBeforeUpdate.amount < this.tank.getCapacity()
&& current.amount == this.tank.getCapacity()
|| this.lastBeforeUpdate.amount == this.tank.getCapacity()
&& current.amount < this.tank.getCapacity()) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
}
} else {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = current.copy();
}
} else if (this.lastBeforeUpdate != null) {
ChannelLoader.sendPacketToAllPlayers(getDescriptionPacket(), this.worldObj);
this.lastBeforeUpdate = null;
}
}
}
public FluidStack drain(FluidStack fluid, boolean doDrain, boolean findMainTank) {
if (findMainTank) {
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
TileCertusQuartzTank mainTank = this;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
Fluid offFluid = ((TileCertusQuartzTank) offTE).getFluid();
if (offFluid != null && offFluid == fluid.getFluid()) {
mainTank = (TileCertusQuartzTank) this.worldObj
.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
continue;
}
}
break;
}
return mainTank != null ? mainTank.drain(fluid, doDrain, false) : null;
}
FluidStack drained = this.tank.drain(fluid.amount, doDrain);
compareAndUpdate();
if (drained == null || drained.amount < fluid.amount) {
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
if (offTE instanceof TileCertusQuartzTank) {
TileCertusQuartzTank tank = (TileCertusQuartzTank) offTE;
FluidStack externallyDrained = tank.drain(
new FluidStack(fluid.getFluid(), fluid.amount - (drained != null ? drained.amount : 0)),
doDrain,
false);
if (externallyDrained != null) return new FluidStack(
fluid.getFluid(),
(drained != null ? drained.amount : 0) + externallyDrained.amount);
else return drained;
}
}
return drained;
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if (this.tank.getFluid() == null || resource == null || resource.getFluid() != this.tank.getFluid().getFluid())
return null;
return drain(resource, doDrain, true);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
if (this.tank.getFluid() == null) return null;
return drain(from, new FluidStack(this.tank.getFluid(), maxDrain), doDrain);
}
public int fill(FluidStack fluid, boolean doFill, boolean findMainTank) {
if (findMainTank) {
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
TileCertusQuartzTank mainTank = this;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
Fluid offFluid = ((TileCertusQuartzTank) offTE).getFluid();
if (offFluid == null || offFluid == fluid.getFluid()) {
mainTank = (TileCertusQuartzTank) this.worldObj
.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
continue;
}
}
break;
}
return mainTank != null ? mainTank.fill(fluid, doFill, false) : 0;
}
int filled = this.tank.fill(fluid, doFill);
compareAndUpdate();
if (filled < fluid.amount) {
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + 1, this.zCoord);
if (offTE instanceof TileCertusQuartzTank) {
TileCertusQuartzTank tank = (TileCertusQuartzTank) offTE;
return filled + tank.fill(new FluidStack(fluid.getFluid(), fluid.amount - filled), doFill, false);
}
}
return filled;
}
/* IFluidHandler */
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if (resource == null || this.tank.getFluid() != null && resource.getFluid() != this.tank.getFluid().getFluid())
return 0;
return fill(resource, doFill, true);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
public Fluid getFluid() {
FluidStack tankFluid = this.tank.getFluid();
return tankFluid != null && tankFluid.amount > 0 ? tankFluid.getFluid() : null;
}
public Fluid getRenderFluid() {
return this.tank.getFluid() != null ? this.tank.getFluid().getFluid() : null;
}
public float getRenderScale() {
return (float) this.tank.getFluidAmount() / this.tank.getCapacity();
}
public FluidTankInfo[] getTankInfo(boolean goToMainTank) {
if (!goToMainTank) return new FluidTankInfo[] { this.tank.getInfo() };
int amount = 0, capacity = 0;
Fluid fluid = null;
int yOff = 0;
TileEntity offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
TileCertusQuartzTank mainTank;
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
if (((TileCertusQuartzTank) offTE).getFluid() == null
|| ((TileCertusQuartzTank) offTE).getFluid() == getFluid()) {
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
continue;
}
}
break;
}
yOff = 0;
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()) {
FluidTankInfo info = mainTank.getTankInfo(false)[0];
if (info != null) {
capacity += info.capacity;
if (info.fluid != null) {
amount += info.fluid.amount;
if (info.fluid.getFluid() != null) fluid = info.fluid.getFluid();
}
}
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
continue;
}
}
break;
}
return new FluidTankInfo[] {
new FluidTankInfo(fluid != null ? new FluidStack(fluid, amount) : null, capacity) };
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return getTankInfo(true);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
this.worldObj.markBlockRangeForRenderUpdate(
this.xCoord,
this.yCoord,
this.zCoord,
this.xCoord,
this.yCoord,
this.zCoord);
readFromNBT(packet.func_148857_g());
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
readFromNBTWithoutCoords(tag);
}
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
this.tank.readFromNBT(tag);
}
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
writeToNBTWithoutCoords(data);
}
public void setCapacity() {
this.tank.setCapacity(CAPACITY);
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
writeToNBTWithoutCoords(tag);
}
public void writeToNBTWithoutCoords(NBTTagCompound tag) {