use of net.minecraftforge.liquids.ILiquidTank in project MineFactoryReloaded by powercrystals.
the class MFRLiquidMover method manuallyDrainTank.
/**
* Attempts to drain tank into the player's current item.
* @param itcb the tank the liquid is coming from
* @param entityplayer the player trying to take liquid from the tank
* @return True if liquid was transferred from the tank.
*/
public static boolean manuallyDrainTank(ITankContainerBucketable itcb, EntityPlayer entityplayer) {
ItemStack ci = entityplayer.inventory.getCurrentItem();
if (LiquidContainerRegistry.isEmptyContainer(ci)) {
for (ILiquidTank tank : itcb.getTanks(ForgeDirection.UNKNOWN)) {
LiquidStack tankLiquid = tank.getLiquid();
ItemStack filledBucket = LiquidContainerRegistry.fillLiquidContainer(tankLiquid, ci);
if (LiquidContainerRegistry.isFilledContainer(filledBucket)) {
LiquidStack bucketLiquid = LiquidContainerRegistry.getLiquidForFilledItem(filledBucket);
if (entityplayer.capabilities.isCreativeMode) {
tank.drain(bucketLiquid.amount, true);
return true;
} else if (ci.stackSize == 1) {
tank.drain(bucketLiquid.amount, true);
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filledBucket);
return true;
} else if (entityplayer.inventory.addItemStackToInventory(filledBucket)) {
tank.drain(bucketLiquid.amount, true);
ci.stackSize -= 1;
return true;
}
}
}
}
return false;
}
use of net.minecraftforge.liquids.ILiquidTank in project MineFactoryReloaded by powercrystals.
the class ContainerLiquiCrafter method detectAndSendChanges.
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
int tankIndex = (int) (_crafter.worldObj.getWorldTime() % 9);
ILiquidTank tank = _crafter.getTanks(ForgeDirection.UNKNOWN)[tankIndex];
LiquidStack l = tank.getLiquid();
for (int i = 0; i < crafters.size(); i++) {
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 0, tankIndex);
if (l != null) {
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 1, l.itemID);
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 2, l.itemMeta);
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 3, l.amount);
} else {
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 1, 0);
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 2, 0);
((ICrafting) crafters.get(i)).sendProgressBarUpdate(this, 3, 0);
}
}
}
use of net.minecraftforge.liquids.ILiquidTank in project MineFactoryReloaded by powercrystals.
the class TileEntityFactoryInventory method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
_inventory = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < _inventory.length) {
ItemStack s = new ItemStack(0, 0, 0);
s.readFromNBT(nbttagcompound1);
_inventory[j] = s;
}
}
onFactoryInventoryChanged();
boolean foundLiquid = false;
ILiquidTank tank = getTank();
int tankAmount = nbttagcompound.getInteger("tankAmount");
if (tank != null && nbttagcompound.hasKey("tankFluidName")) {
LiquidStack fluid = LiquidDictionary.getLiquid(nbttagcompound.getString("tankFluidName"), tankAmount);
if (fluid != null) {
if (fluid.amount > tank.getCapacity()) {
fluid.amount = tank.getCapacity();
}
((LiquidTank) tank).setLiquid(fluid);
foundLiquid = true;
}
}
if (!foundLiquid) {
int tankItemId = nbttagcompound.getInteger("tankItemId");
int tankItemMeta = nbttagcompound.getInteger("tankItemMeta");
if (tank != null && Item.itemsList[tankItemId] != null && LiquidContainerRegistry.isLiquid(new ItemStack(tankItemId, 1, tankItemMeta))) {
((LiquidTank) tank).setLiquid(new LiquidStack(tankItemId, tankAmount, tankItemMeta));
if (tank.getLiquid() != null && tank.getLiquid().amount > tank.getCapacity()) {
tank.getLiquid().amount = tank.getCapacity();
}
}
}
for (int i = 0; i < getSizeInventory(); i++) {
if (_inventory[i] != null && _inventory[i].getItem() == null) {
_inventory[i] = null;
}
}
if (nbttagcompound.hasKey("display")) {
NBTTagCompound display = nbttagcompound.getCompoundTag("display");
if (display.hasKey("Name")) {
this.setInvName(display.getString("Name"));
}
}
}
use of net.minecraftforge.liquids.ILiquidTank in project MineFactoryReloaded by powercrystals.
the class BlockFactoryMachine method getComparatorInputOverride.
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
int ret = 0;
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityFactoryInventory) {
TileEntityFactoryInventory inv = (TileEntityFactoryInventory) te;
ILiquidTank tank = inv.getTank();
float tankPercent = 0, invPercent = 0;
boolean hasTank = false, hasInventory = false;
if (tank != null) {
hasTank = true;
if (tank.getLiquid() != null) {
tankPercent = ((float) tank.getLiquid().amount) / tank.getCapacity();
}
}
int[] accSlots = inv.getAccessibleSlotsFromSide(side);
if (accSlots.length > 0) {
hasInventory = true;
invPercent = inv.getComparatorOutput(side);
}
float mult = hasTank & hasInventory ? (tankPercent + invPercent) / 2 : hasTank ? tankPercent : hasInventory ? invPercent : 0f;
ret = (int) Math.ceil(15 * mult);
}
return ret;
}
Aggregations