Search in sources :

Example 6 with IItemOxygenSupply

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

the class TileEntityOxygenStorageModule method update.

@Override
public void update() {
    if (!this.worldObj.isRemote) {
        ItemStack oxygenItemStack = this.getStackInSlot(0);
        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();
    this.scaledOxygenLevel = this.getScaledOxygenLevel(16);
    if (this.scaledOxygenLevel != this.lastScaledOxygenLevel) {
        this.worldObj.notifyLightSet(this.getPos());
    }
    this.lastScaledOxygenLevel = this.scaledOxygenLevel;
    this.produceOxygen(getFront().rotateY().getOpposite());
    // if (!this.worldObj.isRemote)
    // {
    // int gasToSend = Math.min(this.storedOxygen,
    // GCCoreTileEntityOxygenStorageModule.OUTPUT_PER_TICK);
    // GasStack toSend = new GasStack(GalacticraftCore.gasOxygen,
    // gasToSend);
    // this.storedOxygen -= GasTransmission.emitGasToNetwork(toSend, this,
    // this.getOxygenOutputDirection());
    // 
    // Vector3 thisVec = new Vector3(this);
    // TileEntity tileEntity =
    // thisVec.modifyPositionFromSide(this.getOxygenOutputDirection()).getTileEntity(this.worldObj);
    // 
    // if (tileEntity instanceof IGasAcceptor)
    // {
    // if (((IGasAcceptor)
    // tileEntity).canReceiveGas(this.getOxygenInputDirection(),
    // GalacticraftCore.gasOxygen))
    // {
    // double sendingGas = 0;
    // 
    // if (this.storedOxygen >=
    // GCCoreTileEntityOxygenStorageModule.OUTPUT_PER_TICK)
    // {
    // sendingGas = GCCoreTileEntityOxygenStorageModule.OUTPUT_PER_TICK;
    // }
    // else
    // {
    // sendingGas = this.storedOxygen;
    // }
    // 
    // this.storedOxygen -= sendingGas - ((IGasAcceptor)
    // tileEntity).receiveGas(new GasStack(GalacticraftCore.gasOxygen, (int)
    // Math.floor(sendingGas)));
    // }
    // }
    // }
    this.lastScaledOxygenLevel = this.scaledOxygenLevel;
}
Also used : IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) ItemStack(net.minecraft.item.ItemStack)

Example 7 with IItemOxygenSupply

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

the class TileEntityOxygenDistributor 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(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) {
        if (this.getEnergyStoredGC() > 0.0F && this.hasEnoughEnergyToRun && this.getOxygenStored() > this.oxygenPerTick) {
            this.bubbleSize += 0.01F;
        } else {
            this.bubbleSize -= 0.1F;
        }
        this.bubbleSize = Math.min(Math.max(this.bubbleSize, 0.0F), 10.0F);
    }
    if (!this.worldObj.isRemote) /* && this.oxygenBubble != null*/
    {
        this.active = bubbleSize >= 1 && this.hasEnoughEnergyToRun && this.getOxygenStored() > this.oxygenPerTick;
        if (this.ticks % (this.active ? 20 : 4) == 0) {
            double size = bubbleSize;
            int bubbleR = MathHelper.floor_double(size) + 4;
            int bubbleR2 = (int) (size * size);
            for (int x = this.getPos().getX() - bubbleR; x <= this.getPos().getX() + bubbleR; x++) {
                for (int y = this.getPos().getY() - bubbleR; y <= this.getPos().getY() + bubbleR; y++) {
                    for (int z = this.getPos().getZ() - bubbleR; z <= this.getPos().getZ() + bubbleR; z++) {
                        BlockPos pos = new BlockPos(x, y, z);
                        IBlockState state = this.worldObj.getBlockState(pos);
                        Block block = state.getBlock();
                        if (block instanceof IOxygenReliantBlock) {
                            if (this.getDistanceFromServer(x, y, z) <= bubbleR2) {
                                ((IOxygenReliantBlock) block).onOxygenAdded(this.worldObj, pos, state);
                            } else {
                                // Do not necessarily extinguish it - it might be inside another oxygen system
                                this.worldObj.scheduleUpdate(pos, block, 0);
                            }
                        }
                    }
                }
            }
        }
    }
    this.lastActive = this.active;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IItemOxygenSupply(micdoodle8.mods.galacticraft.api.item.IItemOxygenSupply) IOxygenReliantBlock(micdoodle8.mods.galacticraft.api.block.IOxygenReliantBlock) Block(net.minecraft.block.Block) IOxygenReliantBlock(micdoodle8.mods.galacticraft.api.block.IOxygenReliantBlock) ItemStack(net.minecraft.item.ItemStack)

Example 8 with IItemOxygenSupply

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

the class ContainerOxygenSealer 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 (stack.getItem() == GCItems.basicItem && stack.getItemDamage() == 20) {
                if (!this.mergeItemStack(stack, 2, 3, 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