Hbm-s-Nuclear-Tech-GIT/src/main/java/com/hbm/tileentity/machine/TileEntityMachineFluidTank.java
Bob 4a395504cd just like 800 errors left
i will build a time machine, go back to the year 2017 and shoot my former self in the head
2022-01-11 23:40:34 +01:00

190 lines
4.6 KiB
Java

package com.hbm.tileentity.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.ModBlocks;
import com.hbm.handler.FluidTypeHandler.FluidTypeTheOldOne;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidContainer;
import com.hbm.interfaces.IFluidSource;
import com.hbm.inventory.FluidTank;
import com.hbm.inventory.fluid.FluidType.FluidTrait;
import com.hbm.lib.Library;
import com.hbm.tileentity.TileEntityMachineBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
public class TileEntityMachineFluidTank extends TileEntityMachineBase implements IFluidContainer, IFluidSource, IFluidAcceptor {
public FluidTank tank;
public short mode = 0;
public static final short modes = 4;
public int age = 0;
public List<IFluidAcceptor> list = new ArrayList();
public TileEntityMachineFluidTank() {
super(6);
tank = new FluidTank(FluidTypeTheOldOne.NONE, 256000, 0);
}
@Override
public String getName() {
return "container.fluidtank";
}
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
age++;
if(age >= 20)
age = 0;
if((mode == 1 || mode == 2) && (age == 9 || age == 19))
fillFluidInit(tank.getTankType());
tank.loadTank(2, 3, slots);
tank.setType(0, 1, slots);
if(tank.getFill() > 0) {
if(tank.getTankType().isAntimatter()) {
worldObj.func_147480_a(xCoord, yCoord, zCoord, false);
worldObj.newExplosion(null, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, 5, true, true);
}
if(tank.getTankType().traits.contains(FluidTrait.CORROSIVE_2)) {
worldObj.func_147480_a(xCoord, yCoord, zCoord, false);
}
}
tank.unloadTank(4, 5, slots);
tank.updateTank(xCoord, yCoord, zCoord, worldObj.provider.dimensionId);
NBTTagCompound data = new NBTTagCompound();
data.setShort("mode", mode);
this.networkPack(data, 50);
}
}
public void networkUnpack(NBTTagCompound data) {
mode = data.getShort("mode");
}
public void handleButtonPacket(int value, int meta) {
mode = (short) ((mode + 1) % modes);
markDirty();
}
@Override
public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared()
{
return 65536.0D;
}
@Override
public void setFillstate(int fill, int index) {
tank.setFill(fill);
}
@Override
public void setType(FluidTypeTheOldOne type, int index) {
tank.setTankType(type);
}
@Override
public int getMaxFluidFill(FluidTypeTheOldOne type) {
if(mode == 2 || mode == 3)
return 0;
return type.name().equals(this.tank.getTankType().name()) ? tank.getMaxFill() : 0;
}
@Override
public void fillFluidInit(FluidTypeTheOldOne type) {
fillFluid(this.xCoord + 2, this.yCoord, this.zCoord - 1, getTact(), type);
fillFluid(this.xCoord + 2, this.yCoord, this.zCoord + 1, getTact(), type);
fillFluid(this.xCoord - 2, this.yCoord, this.zCoord - 1, getTact(), type);
fillFluid(this.xCoord - 2, this.yCoord, this.zCoord + 1, getTact(), type);
fillFluid(this.xCoord - 1, this.yCoord, this.zCoord + 2, getTact(), type);
fillFluid(this.xCoord + 1, this.yCoord, this.zCoord + 2, getTact(), type);
fillFluid(this.xCoord - 1, this.yCoord, this.zCoord - 2, getTact(), type);
fillFluid(this.xCoord + 1, this.yCoord, this.zCoord - 2, getTact(), type);
}
@Override
public void fillFluid(int x, int y, int z, boolean newTact, FluidTypeTheOldOne type) {
Library.transmitFluid(x, y, z, newTact, this, worldObj, type);
}
@Override
public boolean getTact() {
if (age >= 0 && age < 10) {
return true;
}
return false;
}
@Override
public int getFluidFill(FluidTypeTheOldOne type) {
return type.name().equals(this.tank.getTankType().name()) ? tank.getFill() : 0;
}
@Override
public void setFluidFill(int i, FluidTypeTheOldOne type) {
if(type.name().equals(tank.getTankType().name()))
tank.setFill(i);
}
@Override
public List<IFluidAcceptor> getFluidList(FluidTypeTheOldOne type) {
return this.list;
}
@Override
public void clearFluidList(FluidTypeTheOldOne type) {
this.list.clear();
}
@Override
public List<FluidTank> getTanks() {
List<FluidTank> list = new ArrayList();
list.add(tank);
return list;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
mode = nbt.getShort("mode");
tank.readFromNBT(nbt, "tank");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setShort("mode", mode);
tank.writeToNBT(nbt, "tank");
}
}