Search in sources :

Example 6 with IPneumaticMachine

use of pneumaticCraft.api.tileentity.IPneumaticMachine in project PneumaticCraft by MineMaarten.

the class BlockVortexTube method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack) {
    super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, par6ItemStack);
    TileEntityVortexTube te = (TileEntityVortexTube) world.getTileEntity(x, y, z);
    for (int i = 0; i < 4; i++) {
        te.rotateRoll(1);
        ForgeDirection d = te.getTubeDirection();
        IPneumaticMachine pneumaticMachine = ModInteractionUtils.getInstance().getMachine(world.getTileEntity(x + d.offsetX, y + d.offsetY, z + d.offsetZ));
        if (pneumaticMachine != null && pneumaticMachine.isConnectedTo(d.getOpposite()))
            break;
    }
}
Also used : TileEntityVortexTube(pneumaticCraft.common.tileentity.TileEntityVortexTube) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 7 with IPneumaticMachine

use of pneumaticCraft.api.tileentity.IPneumaticMachine in project PneumaticCraft by MineMaarten.

the class ModuleCharging method update.

@Override
public void update() {
    super.update();
    IInventory inv = getConnectedInventory();
    if (inv != null) {
        int[] accessibleSlots = IOHelper.getAccessibleSlotsForInventory(inv, dir.getOpposite());
        for (int i = 0; i < (upgraded ? 10 : 1) * PneumaticValues.CHARGING_STATION_CHARGE_RATE; i++) {
            boolean charged = false;
            for (int slot : accessibleSlots) {
                ItemStack chargedItem = inv.getStackInSlot(slot);
                if (chargedItem != null && chargedItem.getItem() instanceof IPressurizable) {
                    IPressurizable chargingItem = (IPressurizable) chargedItem.getItem();
                    IAirHandler airHandler = ((IPneumaticMachine) pressureTube).getAirHandler();
                    if (chargingItem.getPressure(chargedItem) > airHandler.getPressure(ForgeDirection.UNKNOWN) + 0.01F && chargingItem.getPressure(chargedItem) > 0F) {
                        chargingItem.addAir(chargedItem, -1);
                        airHandler.addAir(1, ForgeDirection.UNKNOWN);
                        charged = true;
                    } else if (chargingItem.getPressure(chargedItem) < airHandler.getPressure(ForgeDirection.UNKNOWN) - 0.01F && chargingItem.getPressure(chargedItem) < chargingItem.maxPressure(chargedItem)) {
                        // if there is pressure, and the item isn't fully charged yet..
                        chargingItem.addAir(chargedItem, 1);
                        airHandler.addAir(-1, ForgeDirection.UNKNOWN);
                        charged = true;
                    }
                }
            }
            if (!charged)
                break;
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) IPressurizable(pneumaticCraft.api.item.IPressurizable) IAirHandler(pneumaticCraft.api.tileentity.IAirHandler) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ItemStack(net.minecraft.item.ItemStack)

Example 8 with IPneumaticMachine

use of pneumaticCraft.api.tileentity.IPneumaticMachine in project PneumaticCraft by MineMaarten.

the class ItemManometer method onItemUseFirst.

/**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
@Override
public boolean onItemUseFirst(ItemStack iStack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) {
    if (world.isRemote)
        return false;
    if (((IPressurizable) iStack.getItem()).getPressure(iStack) > 0F) {
        TileEntity te = world.getTileEntity(x, y, z);
        IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
        List<IChatComponent> curInfo = new ArrayList<IChatComponent>();
        List<String> info = new ArrayList<String>();
        if (te instanceof IManoMeasurable) {
            ((IManoMeasurable) te).printManometerMessage(player, info);
        } else if (machine != null) {
            machine.getAirHandler().printManometerMessage(player, info);
        }
        for (String s : info) curInfo.add(new ChatComponentTranslation(s));
        if (te instanceof IHeatExchanger) {
            IHeatExchangerLogic exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(ForgeDirection.getOrientation(side));
            if (exchanger != null) {
                curInfo.add(new ChatComponentTranslation("waila.temperature", (int) exchanger.getTemperature() - 273));
            } else {
                for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                    exchanger = ((IHeatExchanger) te).getHeatExchangerLogic(d);
                    if (exchanger != null) {
                        curInfo.add(new ChatComponentTranslation("waila.temperature." + d.toString().toLowerCase(), (int) exchanger.getTemperature() - 273));
                    }
                }
            }
        }
        if (curInfo.size() > 0) {
            ((IPressurizable) iStack.getItem()).addAir(iStack, -30);
            for (IChatComponent s : curInfo) {
                player.addChatComponentMessage(s);
            }
            return true;
        }
    } else {
        player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
        return false;
    }
    return false;
}
Also used : IPressurizable(pneumaticCraft.api.item.IPressurizable) IManoMeasurable(pneumaticCraft.api.tileentity.IManoMeasurable) ArrayList(java.util.ArrayList) TileEntity(net.minecraft.tileentity.TileEntity) IHeatExchanger(pneumaticCraft.api.tileentity.IHeatExchanger) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) IChatComponent(net.minecraft.util.IChatComponent) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Example 9 with IPneumaticMachine

use of pneumaticCraft.api.tileentity.IPneumaticMachine in project PneumaticCraft by MineMaarten.

the class TileEntityElevatorBase method updateConnections.

public void updateConnections() {
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity te = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
        if (te instanceof IPneumaticMachine) {
            sidesConnected[direction.ordinal()] = ((IPneumaticMachine) te).isConnectedTo(direction.getOpposite());
        } else {
            sidesConnected[direction.ordinal()] = false;
        }
    }
    if (worldObj.getBlock(xCoord, yCoord + 1, zCoord) != Blockss.elevatorBase) {
        coreElevator = this;
        int i = -1;
        TileEntity te = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord);
        while (te instanceof TileEntityElevatorBase) {
            ((TileEntityElevatorBase) te).coreElevator = this;
            i--;
            te = worldObj.getTileEntity(xCoord, yCoord + i, zCoord);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 10 with IPneumaticMachine

use of pneumaticCraft.api.tileentity.IPneumaticMachine in project PneumaticCraft by MineMaarten.

the class TileEntityPneumaticBase method getConnectedPneumatics.

/**
        * Retrieves a list of all the connecting pneumatics. It takes sides in account.
        * @return
        */
@Override
public List<Pair<ForgeDirection, IAirHandler>> getConnectedPneumatics() {
    List<Pair<ForgeDirection, IAirHandler>> teList = new ArrayList<Pair<ForgeDirection, IAirHandler>>();
    for (IAirHandler specialConnection : specialConnectedHandlers) {
        teList.add(new ImmutablePair(ForgeDirection.UNKNOWN, specialConnection));
    }
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity te = getTileCache()[direction.ordinal()].getTileEntity();
        IPneumaticMachine machine = ModInteractionUtils.getInstance().getMachine(te);
        if (machine != null && isConnectedTo(direction) && machine.isConnectedTo(direction.getOpposite())) {
            teList.add(new ImmutablePair(direction, machine.getAirHandler()));
        } else if (te instanceof ISidedPneumaticMachine) {
            IAirHandler handler = ((ISidedPneumaticMachine) te).getAirHandler(direction.getOpposite());
            if (handler != null) {
                teList.add(new ImmutablePair(direction, handler));
            }
        }
    }
    return teList;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAirHandler(pneumaticCraft.api.tileentity.IAirHandler) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) IPneumaticMachine(pneumaticCraft.api.tileentity.IPneumaticMachine) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISidedPneumaticMachine(pneumaticCraft.api.tileentity.ISidedPneumaticMachine) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Aggregations

IPneumaticMachine (pneumaticCraft.api.tileentity.IPneumaticMachine)11 TileEntity (net.minecraft.tileentity.TileEntity)9 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 IAirHandler (pneumaticCraft.api.tileentity.IAirHandler)4 ArrayList (java.util.ArrayList)3 ISidedPneumaticMachine (pneumaticCraft.api.tileentity.ISidedPneumaticMachine)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 Pair (org.apache.commons.lang3.tuple.Pair)2 IPressurizable (pneumaticCraft.api.item.IPressurizable)2 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 IChatComponent (net.minecraft.util.IChatComponent)1 ChunkPosition (net.minecraft.world.ChunkPosition)1 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)1 IHeatExchanger (pneumaticCraft.api.tileentity.IHeatExchanger)1 IManoMeasurable (pneumaticCraft.api.tileentity.IManoMeasurable)1 DroneAIBlockCondition (pneumaticCraft.common.ai.DroneAIBlockCondition)1