Search in sources :

Example 1 with IManoMeasurable

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

the class ItemManometer method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(ItemStack iStack, EntityPlayer player, EntityLivingBase entity) {
    if (!player.worldObj.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.addChatComponentMessage(new ChatComponentTranslation(s));
                    }
                    return true;
                }
            } else {
                player.addChatComponentMessage(new ChatComponentTranslation(EnumChatFormatting.RED + "The Manometer doesn't have any charge!"));
            }
        }
    }
    return false;
}
Also used : IPressurizable(pneumaticCraft.api.item.IPressurizable) IManoMeasurable(pneumaticCraft.api.tileentity.IManoMeasurable) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ArrayList(java.util.ArrayList)

Example 2 with IManoMeasurable

use of pneumaticCraft.api.tileentity.IManoMeasurable 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

ArrayList (java.util.ArrayList)2 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)2 IPressurizable (pneumaticCraft.api.item.IPressurizable)2 IManoMeasurable (pneumaticCraft.api.tileentity.IManoMeasurable)2 TileEntity (net.minecraft.tileentity.TileEntity)1 IChatComponent (net.minecraft.util.IChatComponent)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)1 IHeatExchanger (pneumaticCraft.api.tileentity.IHeatExchanger)1 IPneumaticMachine (pneumaticCraft.api.tileentity.IPneumaticMachine)1