Search in sources :

Example 1 with IItemOxygenSupply

use of micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply in project Galacticraft by micdoodle8.

the class TileEntityOxygenCompressor method update.

@Override
public void update() {
    if (!this.worldObj.isRemote) {
        ItemStack oxygenItemStack = this.getStackInSlot(2);
        if (oxygenItemStack != null && oxygenItemStack.getItem() instanceof IItemOxygenSupply) {
            IItemOxygenSupply oxygenItem = (IItemOxygenSupply) oxygenItemStack.getItem();
            int oxygenDraw = (int) Math.floor(Math.min(this.oxygenPerTick * 2.5F, this.getMaxOxygenStored() - this.getOxygenStored()));
            this.setOxygenStored(getOxygenStored() + oxygenItem.discharge(oxygenItemStack, oxygenDraw));
            if (this.getOxygenStored() > this.getMaxOxygenStored()) {
                this.setOxygenStored(this.getOxygenStored());
            }
        }
    }
    super.update();
    if (!this.worldObj.isRemote) {
        this.usingEnergy = false;
        if (this.getOxygenStored() > 0 && this.hasEnoughEnergyToRun) {
            ItemStack tank0 = this.containingItems[0];
            if (tank0 != null) {
                if (tank0.getItem() instanceof ItemOxygenTank && tank0.getItemDamage() > 0) {
                    tank0.setItemDamage(tank0.getItemDamage() - TileEntityOxygenCompressor.TANK_TRANSFER_SPEED);
                    this.setOxygenStored(this.getOxygenStored() - TileEntityOxygenCompressor.TANK_TRANSFER_SPEED);
                    this.usingEnergy = true;
                }
            }
        }
    }
}
Also used : IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) ItemStack(net.minecraft.item.ItemStack) ItemOxygenTank(micdoodle8.mods.galacticraft.core.items.ItemOxygenTank)

Example 2 with IItemOxygenSupply

use of micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply in project Galacticraft by micdoodle8.

the class TileEntityOxygenSealer method update.

@Override
public void update() {
    if (!this.worldObj.isRemote) {
        ItemStack oxygenItemStack = this.getStackInSlot(1);
        if (oxygenItemStack != null && oxygenItemStack.getItem() instanceof IItemOxygenSupply) {
            IItemOxygenSupply oxygenItem = (IItemOxygenSupply) oxygenItemStack.getItem();
            int oxygenDraw = (int) Math.floor(Math.min(UNSEALED_OXYGENPERTICK * 2.5F, this.getMaxOxygenStored() - this.getOxygenStored()));
            this.setOxygenStored(getOxygenStored() + oxygenItem.discharge(oxygenItemStack, oxygenDraw));
            if (this.getOxygenStored() > this.getMaxOxygenStored()) {
                this.setOxygenStored(this.getOxygenStored());
            }
        }
        if (this.thermalControlEnabled()) {
            if (this.storage.getMaxExtract() != 20.0F) {
                this.storage.setMaxExtract(20.0F);
            }
        } else if (this.storage.getMaxExtract() != 5.0F) {
            this.storage.setMaxExtract(5.0F);
            this.storage.setMaxReceive(25.0F);
        }
    }
    this.oxygenPerTick = this.sealed ? 2 : UNSEALED_OXYGENPERTICK;
    super.update();
    if (!this.worldObj.isRemote) {
        // Some code to count the number of Oxygen Sealers being updated,
        // tick by tick - needed for queueing
        TileEntityOxygenSealer.countTemp++;
        this.active = this.getOxygenStored() >= 1 && this.hasEnoughEnergyToRun && !this.disabled;
        if (this.disabled != this.lastDisabled) {
            this.lastDisabled = this.disabled;
            if (!this.disabled)
                this.stopSealThreadCooldown = this.threadCooldownTotal * 3 / 5;
        }
        // TODO: if multithreaded, this codeblock should not run if the current threadSeal is flagged looping
        if (this.stopSealThreadCooldown > 0) {
            this.stopSealThreadCooldown--;
        } else if (!TileEntityOxygenSealer.sealerCheckedThisTick) {
            // This puts any Sealer which is updated to the back of the queue for updates
            this.threadCooldownTotal = this.stopSealThreadCooldown = 75 + TileEntityOxygenSealer.countEntities;
            if (this.active || this.sealed) {
                TileEntityOxygenSealer.sealerCheckedThisTick = true;
                OxygenPressureProtocol.updateSealerStatus(this);
            }
        }
        // TODO: if multithreaded, this.threadSeal needs to be atomic
        if (this.threadSeal != null) {
            if (this.threadSeal.looping.get()) {
                this.calculatingSealed = this.active;
            } else {
                this.calculatingSealed = false;
                this.sealed = this.threadSeal.sealedFinal.get();
            }
        } else {
            // Give an initial 'Check pending' in GUI when first placed
            this.calculatingSealed = true;
        }
        this.lastSealed = this.sealed;
    }
}
Also used : IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IItemOxygenSupply

use of micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply in project Galacticraft by micdoodle8.

the class ContainerOxygenCompressor method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) {
    ItemStack var2 = null;
    final Slot slot = (Slot) this.inventorySlots.get(par1);
    final int b = this.inventorySlots.size();
    if (slot != null && slot.getHasStack()) {
        final ItemStack stack = slot.getStack();
        var2 = stack.copy();
        boolean movedToMachineSlot = false;
        if (par1 < 3) {
            if (!this.mergeItemStack(stack, b - 36, b, true)) {
                return null;
            }
        } else {
            if (EnergyUtil.isElectricItem(stack.getItem())) {
                if (!this.mergeItemStack(stack, 1, 2, false)) {
                    return null;
                }
                movedToMachineSlot = true;
            } else if (stack.getItem() instanceof IItemOxygenSupply) {
                if (!this.mergeItemStack(stack, 2, 3, false)) {
                    return null;
                }
                movedToMachineSlot = true;
            } else if (stack.getItem() instanceof ItemOxygenTank && stack.getItemDamage() > 0) {
                if (!this.mergeItemStack(stack, 0, 1, false)) {
                    return null;
                }
                movedToMachineSlot = true;
            } else {
                if (par1 < b - 9) {
                    if (!this.mergeItemStack(stack, b - 9, b, false)) {
                        return null;
                    }
                } else if (!this.mergeItemStack(stack, b - 36, b - 9, false)) {
                    return null;
                }
            }
        }
        if (stack.stackSize == 0) {
            // Needed where tile has inventoryStackLimit of 1
            if (movedToMachineSlot && var2.stackSize > 1) {
                ItemStack remainder = var2.copy();
                --remainder.stackSize;
                slot.putStack(remainder);
            } else {
                slot.putStack((ItemStack) null);
            }
        } else {
            slot.onSlotChanged();
        }
        if (stack.stackSize == var2.stackSize) {
            return null;
        }
        slot.onPickupFromSlot(par1EntityPlayer, stack);
    }
    return var2;
}
Also used : IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) ItemOxygenTank(micdoodle8.mods.galacticraft.core.items.ItemOxygenTank)

Example 4 with IItemOxygenSupply

use of micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply in project Galacticraft by micdoodle8.

the class ContainerOxygenDistributor method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) {
    ItemStack var2 = null;
    final Slot slot = (Slot) this.inventorySlots.get(par1);
    final int b = this.inventorySlots.size();
    if (slot != null && slot.getHasStack()) {
        final ItemStack stack = slot.getStack();
        var2 = stack.copy();
        if (par1 < 2) {
            if (!this.mergeItemStack(stack, b - 36, b, true)) {
                return null;
            }
        } else {
            if (EnergyUtil.isElectricItem(stack.getItem())) {
                if (!this.mergeItemStack(stack, 0, 1, false)) {
                    return null;
                }
            } else if (stack.getItem() instanceof IItemOxygenSupply) {
                if (!this.mergeItemStack(stack, 1, 2, false)) {
                    return null;
                }
            } else {
                if (par1 < b - 9) {
                    if (!this.mergeItemStack(stack, b - 9, b, false)) {
                        return null;
                    }
                } else if (!this.mergeItemStack(stack, b - 36, b - 9, false)) {
                    return null;
                }
            }
        }
        if (stack.stackSize == 0) {
            slot.putStack((ItemStack) null);
        } else {
            slot.onSlotChanged();
        }
        if (stack.stackSize == var2.stackSize) {
            return null;
        }
        slot.onPickupFromSlot(par1EntityPlayer, stack);
    }
    return var2;
}
Also used : IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IItemOxygenSupply

use of micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply in project Galacticraft by micdoodle8.

the class ContainerOxygenStorageModule method transferStackInSlot.

/**
 * Called to transfer a stack from one inventory to the other eg. when shift
 * clicking.
 */
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) {
    ItemStack var2 = null;
    final Slot slot = (Slot) this.inventorySlots.get(par1);
    final int b = this.inventorySlots.size();
    if (slot != null && slot.getHasStack()) {
        final ItemStack stack = slot.getStack();
        var2 = stack.copy();
        if (par1 < 1) {
            if (!this.mergeItemStack(stack, b - 36, b, true)) {
                return null;
            }
        } else {
            if (stack.getItem() instanceof IItemOxygenSupply) {
                if (!this.mergeItemStack(stack, 0, 1, false)) {
                    return null;
                }
            } else {
                if (par1 < b - 9) {
                    if (!this.mergeItemStack(stack, b - 9, b, false)) {
                        return null;
                    }
                } else if (!this.mergeItemStack(stack, b - 36, b - 9, false)) {
                    return null;
                }
            }
        }
        if (stack.stackSize == 0) {
            slot.putStack((ItemStack) null);
        } else {
            slot.onSlotChanged();
        }
        if (stack.stackSize == var2.stackSize) {
            return null;
        }
        slot.onPickupFromSlot(par1EntityPlayer, stack);
    }
    return var2;
}
Also used : IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IItemOxygenSupply (micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply)8 ItemStack (net.minecraft.item.ItemStack)8 Slot (net.minecraft.inventory.Slot)4 ItemOxygenTank (micdoodle8.mods.galacticraft.core.items.ItemOxygenTank)2 IOxygenReliantBlock (micdoodle8.mods.galacticraft.api.block.IOxygenReliantBlock)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1