Search in sources :

Example 6 with IPressurizable

use of pneumaticCraft.api.item.IPressurizable 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 7 with IPressurizable

use of pneumaticCraft.api.item.IPressurizable in project PneumaticCraft by MineMaarten.

the class ContainerAmadron method canInteractWith.

@Override
public boolean canInteractWith(EntityPlayer player) {
    if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Itemss.amadronTablet) {
        IPressurizable pressurizable = (IPressurizable) Itemss.amadronTablet;
        pressurizable.addAir(player.getCurrentEquippedItem(), -1);
        if (pressurizable.getPressure(player.getCurrentEquippedItem()) > 0)
            return true;
        else {
            player.addChatMessage(new ChatComponentTranslation("gui.tab.problems.notEnoughPressure"));
        }
    }
    return false;
}
Also used : IPressurizable(pneumaticCraft.api.item.IPressurizable) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation)

Example 8 with IPressurizable

use of pneumaticCraft.api.item.IPressurizable 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)

Aggregations

IPressurizable (pneumaticCraft.api.item.IPressurizable)8 ItemStack (net.minecraft.item.ItemStack)4 ArrayList (java.util.ArrayList)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 IManoMeasurable (pneumaticCraft.api.tileentity.IManoMeasurable)2 IPneumaticMachine (pneumaticCraft.api.tileentity.IPneumaticMachine)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 Point (java.awt.Point)1 Entity (net.minecraft.entity.Entity)1 EntityItem (net.minecraft.entity.item.EntityItem)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IChatComponent (net.minecraft.util.IChatComponent)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)1 IAirHandler (pneumaticCraft.api.tileentity.IAirHandler)1 IHeatExchanger (pneumaticCraft.api.tileentity.IHeatExchanger)1