use of pneumaticCraft.api.item.IPressurizable in project PneumaticCraft by MineMaarten.
the class RecipePneumaticHelmet method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory) {
if (!matches(inventory, null))
return null;
ItemStack output = getRecipeOutput();
int totalDamage = inventory.getStackInRowAndColumn(0, 0).getItemDamage() + inventory.getStackInRowAndColumn(2, 0).getItemDamage() + inventory.getStackInRowAndColumn(0, 1).getItemDamage() + inventory.getStackInRowAndColumn(2, 1).getItemDamage();
((IPressurizable) output.getItem()).addAir(output, PneumaticValues.PNEUMATIC_HELMET_VOLUME * 10 - totalDamage);
// output.setItemDamage(totalDamage);
return output;
}
use of pneumaticCraft.api.item.IPressurizable in project PneumaticCraft by MineMaarten.
the class TileEntityChargingStation method updateEntity.
@Override
public void updateEntity() {
disCharging = false;
charging = false;
List<IPressurizable> chargingItems = new ArrayList<IPressurizable>();
List<ItemStack> chargedStacks = new ArrayList<ItemStack>();
if (inventory[CHARGE_INVENTORY_INDEX] != null && inventory[CHARGE_INVENTORY_INDEX].getItem() instanceof IPressurizable) {
chargingItems.add((IPressurizable) inventory[CHARGE_INVENTORY_INDEX].getItem());
chargedStacks.add(inventory[CHARGE_INVENTORY_INDEX]);
}
if (this.getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
// creating a new word, 'entities padding'.
List<Entity> entitiesPadding = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 2, zCoord + 1));
for (Entity entity : entitiesPadding) {
if (entity instanceof IPressurizable) {
chargingItems.add((IPressurizable) entity);
chargedStacks.add(null);
} else if (entity instanceof EntityItem) {
ItemStack entityStack = ((EntityItem) entity).getEntityItem();
if (entityStack != null && 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 != null && stack.getItem() instanceof IPressurizable) {
chargingItems.add((IPressurizable) stack.getItem());
chargedStacks.add(stack);
}
}
}
}
}
int speedMultiplier = (int) getSpeedMultiplierFromUpgrades(getUpgradeSlots());
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(ForgeDirection.UNKNOWN) + 0.01F && chargingItem.getPressure(chargedItem) > 0F) {
if (!worldObj.isRemote) {
chargingItem.addAir(chargedItem, -1);
addAir(1, ForgeDirection.UNKNOWN);
}
disCharging = true;
renderAirProgress -= ANIMATION_AIR_SPEED;
if (renderAirProgress < 0.0F) {
renderAirProgress += 1F;
}
charged = true;
} else if (chargingItem.getPressure(chargedItem) < getPressure(ForgeDirection.UNKNOWN) - 0.01F && chargingItem.getPressure(chargedItem) < chargingItem.maxPressure(chargedItem)) {
// if there is pressure, and the item isn't fully charged yet..
if (!worldObj.isRemote) {
chargingItem.addAir(chargedItem, 1);
addAir(-1, ForgeDirection.UNKNOWN);
}
charging = true;
renderAirProgress += ANIMATION_AIR_SPEED;
if (renderAirProgress > 1.0F) {
renderAirProgress -= 1F;
}
charged = true;
}
}
if (!charged)
break;
}
if (!worldObj.isRemote && oldRedstoneStatus != shouldEmitRedstone()) {
oldRedstoneStatus = shouldEmitRedstone();
updateNeighbours();
}
super.updateEntity();
}
use of pneumaticCraft.api.item.IPressurizable 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;
}
use of pneumaticCraft.api.item.IPressurizable in project PneumaticCraft by MineMaarten.
the class CommonHUDHandler method tickEnd.
@SubscribeEvent
public void tickEnd(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
EntityPlayer player = event.player;
if (this == PneumaticCraft.proxy.getCommonHudHandler()) {
getHandlerForPlayer(player).tickEnd(event);
} else {
ItemStack helmetStack = player.getCurrentArmor(3);
if (helmetStack != null && helmetStack.getItem() == Itemss.pneumaticHelmet) {
helmetPressure = ((IPressurizable) helmetStack.getItem()).getPressure(helmetStack);
if (ticksExisted == 0) {
checkHelmetInventory(helmetStack);
}
ticksExisted++;
if (!player.worldObj.isRemote) {
if (ticksExisted > getStartupTime() && !player.capabilities.isCreativeMode) {
((IPressurizable) helmetStack.getItem()).addAir(helmetStack, (int) -UpgradeRenderHandlerList.instance().getAirUsage(player, false));
}
}
} else {
ticksExisted = 0;
}
if (!player.worldObj.isRemote)
handleHacking(player);
}
}
}
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;
}
Aggregations