Search in sources :

Example 1 with IPressurizable

use of me.desht.pneumaticcraft.api.item.IPressurizable in project pnc-repressurized by TeamPneumatic.

the class TileEntityChargingStation method update.

@Override
public void update() {
    disCharging = false;
    charging = false;
    List<IPressurizable> chargingItems = new ArrayList<>();
    List<ItemStack> chargedStacks = new ArrayList<>();
    if (getChargingItem().getItem() instanceof IPressurizable) {
        chargingItems.add((IPressurizable) getChargingItem().getItem());
        chargedStacks.add(getChargingItem());
    }
    if (this.getUpgrades(EnumUpgrade.DISPENSER) > 0) {
        // creating a new word, 'entities padding'.
        List<Entity> entitiesPadding = getWorld().getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX() + 1, getPos().getY() + 2, getPos().getZ() + 1));
        for (Entity entity : entitiesPadding) {
            if (entity instanceof IPressurizable) {
                chargingItems.add((IPressurizable) entity);
                chargedStacks.add(ItemStack.EMPTY);
            } else if (entity instanceof EntityItem) {
                ItemStack entityStack = ((EntityItem) entity).getItem();
                if (entityStack.getItem() instanceof IPressurizable) {
                    chargingItems.add((IPressurizable) entityStack.getItem());
                    chargedStacks.add(entityStack);
                }
            } else if (entity instanceof EntityPlayer) {
                InventoryPlayer inv = ((EntityPlayer) entity).inventory;
                for (int i = 0; i < inv.getSizeInventory(); i++) {
                    ItemStack stack = inv.getStackInSlot(i);
                    if (stack.getItem() instanceof IPressurizable) {
                        chargingItems.add((IPressurizable) stack.getItem());
                        chargedStacks.add(stack);
                    }
                }
            }
        }
    }
    int speedMultiplier = (int) getSpeedMultiplierFromUpgrades();
    for (int i = 0; i < PneumaticValues.CHARGING_STATION_CHARGE_RATE * speedMultiplier; i++) {
        boolean charged = false;
        for (int j = 0; j < chargingItems.size(); j++) {
            IPressurizable chargingItem = chargingItems.get(j);
            ItemStack chargedItem = chargedStacks.get(j);
            if (chargingItem.getPressure(chargedItem) > getPressure() + 0.01F && chargingItem.getPressure(chargedItem) > 0F) {
                if (!getWorld().isRemote) {
                    chargingItem.addAir(chargedItem, -1);
                    addAir(1);
                }
                disCharging = true;
                renderAirProgress -= ANIMATION_AIR_SPEED;
                if (renderAirProgress < 0.0F) {
                    renderAirProgress += 1F;
                }
                charged = true;
            } else if (chargingItem.getPressure(chargedItem) < getPressure() - 0.01F && chargingItem.getPressure(chargedItem) < chargingItem.maxPressure(chargedItem)) {
                // if there is pressure, and the item isn't fully charged yet..
                if (!getWorld().isRemote) {
                    chargingItem.addAir(chargedItem, 1);
                    addAir(-1);
                }
                charging = true;
                renderAirProgress += ANIMATION_AIR_SPEED;
                if (renderAirProgress > 1.0F) {
                    renderAirProgress -= 1F;
                }
                charged = true;
            }
        }
        if (!charged)
            break;
    }
    if (!getWorld().isRemote && oldRedstoneStatus != shouldEmitRedstone()) {
        oldRedstoneStatus = shouldEmitRedstone();
        updateNeighbours();
    }
    super.update();
    if (!getWorld().isRemote) {
        List<Pair<EnumFacing, IAirHandler>> teList = getAirHandler(null).getConnectedPneumatics();
        if (teList.size() == 0)
            getAirHandler(null).airLeak(getRotation());
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with IPressurizable

use of me.desht.pneumaticcraft.api.item.IPressurizable in project pnc-repressurized by TeamPneumatic.

the class ItemManometer method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(ItemStack iStack, EntityPlayer player, EntityLivingBase entity, EnumHand hand) {
    if (!player.world.isRemote) {
        if (entity instanceof IManoMeasurable) {
            if (((IPressurizable) iStack.getItem()).getPressure(iStack) > 0F) {
                List<String> curInfo = new ArrayList<String>();
                ((IManoMeasurable) entity).printManometerMessage(player, curInfo);
                if (curInfo.size() > 0) {
                    ((IPressurizable) iStack.getItem()).addAir(iStack, -30);
                    for (String s : curInfo) {
                        player.sendStatusMessage(new TextComponentTranslation(s), false);
                    }
                    return true;
                }
            } else {
                player.sendStatusMessage(new TextComponentTranslation(TextFormatting.RED + "The Manometer doesn't have any charge!"), false);
            }
        }
    }
    return false;
}
Also used : IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IManoMeasurable(me.desht.pneumaticcraft.api.tileentity.IManoMeasurable) ArrayList(java.util.ArrayList) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with IPressurizable

use of me.desht.pneumaticcraft.api.item.IPressurizable in project pnc-repressurized by TeamPneumatic.

the class CommonHUDHandler method tickEnd.

@SubscribeEvent
public void tickEnd(TickEvent.PlayerTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        EntityPlayer player = event.player;
        if (this == PneumaticCraftRepressurized.proxy.getCommonHudHandler()) {
            getHandlerForPlayer(player).tickEnd(event);
        } else {
            ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
            if (helmetStack.getItem() == Itemss.PNEUMATIC_HELMET) {
                helmetPressure = ((IPressurizable) helmetStack.getItem()).getPressure(helmetStack);
                if (ticksExisted == 0) {
                    checkHelmetInventory(helmetStack);
                }
                ticksExisted++;
                if (!player.world.isRemote) {
                    if (ticksExisted > getStartupTime() && !player.capabilities.isCreativeMode) {
                        ((IPressurizable) helmetStack.getItem()).addAir(helmetStack, (int) -UpgradeRenderHandlerList.instance().getAirUsage(player, false));
                    }
                }
            } else {
                ticksExisted = 0;
            }
            if (!player.world.isRemote)
                handleHacking(player);
        }
    }
}
Also used : IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IPressurizable

use of me.desht.pneumaticcraft.api.item.IPressurizable in project pnc-repressurized by TeamPneumatic.

the class GuiPneumaticInventoryItem method addPressureStatInfo.

@Override
protected void addPressureStatInfo(List<String> pressureStatText) {
    pressureStatText.add("\u00a77Current Pressure:");
    ItemStack stack = te.getPrimaryInventory().getStackInSlot(TileEntityChargingStation.CHARGE_INVENTORY_INDEX);
    float curPressure = ((IPressurizable) itemStack.getItem()).getPressure(stack);
    int volume = ItemPneumaticArmor.getUpgrades(EnumUpgrade.VOLUME, stack) * PneumaticValues.VOLUME_VOLUME_UPGRADE + getDefaultVolume();
    pressureStatText.add("\u00a70" + (double) Math.round(curPressure * 10) / 10 + " bar.");
    pressureStatText.add("\u00a77Current Air:");
    pressureStatText.add("\u00a70" + (double) Math.round(curPressure * volume) + " mL.");
    pressureStatText.add("\u00a77Volume:");
    pressureStatText.add("\u00a70" + getDefaultVolume() + " mL.");
    if (volume > getDefaultVolume()) {
        pressureStatText.add("\u00a70" + (double) Math.round(volume - getDefaultVolume()) + " mL. (Volume Upgrades)");
        pressureStatText.add("\u00a70--------+");
        pressureStatText.add("\u00a70" + (double) Math.round(volume) + " mL.");
    }
}
Also used : IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IPressurizable

use of me.desht.pneumaticcraft.api.item.IPressurizable in project pnc-repressurized by TeamPneumatic.

the class GuiChargingStation method addProblems.

@Override
protected void addProblems(List<String> textList) {
    super.addProblems(textList);
    ItemStack chargeStack = te.getPrimaryInventory().getStackInSlot(TileEntityChargingStation.CHARGE_INVENTORY_INDEX);
    if (chargeStack.isEmpty()) {
        textList.add("\u00a77No items to (dis)charge");
        textList.addAll(PneumaticCraftUtils.convertStringIntoList("\u00a70Put a pneumatic item in the charge slot.", GuiConstants.MAX_CHAR_PER_LINE_LEFT));
    } else if (!(chargeStack.getItem() instanceof IPressurizable)) {
        textList.addAll(PneumaticCraftUtils.convertStringIntoList("\u00a77The inserted item can't be (dis)charged", GuiConstants.MAX_CHAR_PER_LINE_LEFT));
        textList.addAll(PneumaticCraftUtils.convertStringIntoList("\u00a70Put a pneumatic item in the charge slot.", GuiConstants.MAX_CHAR_PER_LINE_LEFT));
    } else {
        IPressurizable chargeItem = (IPressurizable) chargeStack.getItem();
        if (chargeItem.getPressure(chargeStack) > te.getPressure() + 0.01F && chargeItem.getPressure(chargeStack) <= 0) {
            textList.addAll(PneumaticCraftUtils.convertStringIntoList("\u00a77The inserted item can't be discharged", GuiConstants.MAX_CHAR_PER_LINE_LEFT));
            textList.add("\u00a70The item is empty.");
        } else if (chargeItem.getPressure(chargeStack) < te.getPressure() - 0.01F && chargeItem.getPressure(chargeStack) >= chargeItem.maxPressure(chargeStack)) {
            textList.addAll(PneumaticCraftUtils.convertStringIntoList("\u00a77The inserted item can't be charged", GuiConstants.MAX_CHAR_PER_LINE_LEFT));
            textList.add("\u00a70The item is full.");
        } else if (!te.charging && !te.disCharging) {
            textList.addAll(PneumaticCraftUtils.convertStringIntoList("\u00a77The inserted item can't be (dis)charged", GuiConstants.MAX_CHAR_PER_LINE_LEFT));
            textList.add("\u00a70The pressures have equalized.");
        }
    }
}
Also used : IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IPressurizable (me.desht.pneumaticcraft.api.item.IPressurizable)9 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)3 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)3 IManoMeasurable (me.desht.pneumaticcraft.api.tileentity.IManoMeasurable)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 IHeatExchangerLogic (me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)1 IAirHandler (me.desht.pneumaticcraft.api.tileentity.IAirHandler)1 IHeatExchanger (me.desht.pneumaticcraft.api.tileentity.IHeatExchanger)1 IPneumaticMachine (me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine)1 Entity (net.minecraft.entity.Entity)1 EntityItem (net.minecraft.entity.item.EntityItem)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IItemHandler (net.minecraftforge.items.IItemHandler)1