use of tonius.simplyjetpacks.item.meta.PackBase in project SimplyJetpacks by Tonius.
the class PlatingReturnHandler method onItemCrafted.
@SubscribeEvent
public void onItemCrafted(ItemCraftedEvent evt) {
if (evt.player.worldObj.isRemote || !(evt.crafting.getItem() instanceof ItemPack)) {
return;
}
PackBase outputPack = ((ItemPack) evt.crafting.getItem()).getPack(evt.crafting);
if (outputPack.isArmored) {
return;
}
for (int i = 0; i < evt.craftMatrix.getSizeInventory(); i++) {
ItemStack input = evt.craftMatrix.getStackInSlot(i);
if (input == null || !(input.getItem() instanceof ItemPack)) {
continue;
}
PackBase inputPack = ((ItemPack) input.getItem()).getPack(input);
if (inputPack != null && inputPack.isArmored && inputPack.platingMeta != null) {
EntityItem item = evt.player.entityDropItem(new ItemStack(ModItems.armorPlatings, 1, inputPack.platingMeta), 0.0F);
item.delayBeforeCanPickup = 0;
break;
}
}
}
use of tonius.simplyjetpacks.item.meta.PackBase in project SimplyJetpacks by Tonius.
the class UpgradingRecipe method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
int addedEnergy = 0;
ParticleType particleType = null;
NBTTagCompound tags = null;
boolean enderiumUpgrade = false;
ItemStack slotStack;
for (int i = 0; i < inventoryCrafting.getSizeInventory(); i++) {
slotStack = inventoryCrafting.getStackInSlot(i);
if (slotStack != null && slotStack.getItem() != null) {
if (slotStack.getItem() instanceof ItemPack) {
tags = (NBTTagCompound) NBTHelper.getNBT(slotStack).copy();
}
if (slotStack.getItem() instanceof IEnergyContainerItem) {
addedEnergy += ((IEnergyContainerItem) slotStack.getItem()).getEnergyStored(slotStack);
} else if (slotStack.getItem() == ModItems.particleCustomizers) {
particleType = ParticleType.values()[slotStack.getItemDamage()];
} else if (ModItems.enderiumUpgrade != null && slotStack.getItem() == ModItems.enderiumUpgrade.getItem() && slotStack.getItemDamage() == ModItems.enderiumUpgrade.getItemDamage()) {
enderiumUpgrade = true;
}
}
}
ItemStack result = new ItemStack((Item) this.resultItem, 1, this.resultMeta);
if (tags != null) {
result.setTagCompound(tags);
}
NBTHelper.getNBT(result).setInteger("Energy", Math.min(addedEnergy, this.resultItem.getMaxEnergyStored(result)));
if (this.resultItem instanceof ItemJetpack && particleType != null) {
((ItemJetpack) this.resultItem).getPack(result).setParticleType(result, particleType);
}
if (enderiumUpgrade && this.resultItem instanceof ItemPack) {
PackBase pack = ((ItemPack) this.resultItem).getPack(result);
if (pack instanceof JetPlate) {
((JetPlate) pack).setEnderiumUpgrade(result, true);
}
}
return result;
}
use of tonius.simplyjetpacks.item.meta.PackBase in project SimplyJetpacks by Tonius.
the class ItemJetpackFueller method onUsingTick.
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
if (blockPos == null || blockPos.sideHit < 0) {
player.setItemInUse(null, 1);
} else {
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
if (player.worldObj.isRemote) {
return;
}
ItemStack chestplate = player.getCurrentArmor(2);
if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
return;
}
ItemPack packItem = (ItemPack) chestplate.getItem();
PackBase pack = packItem.getPack(chestplate);
if (pack == null) {
return;
}
FuelType fuelType = pack.fuelType;
ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
int pulled = 0;
if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
IEnergyProvider energyTile = (IEnergyProvider) tile;
pulled = energyTile.extractEnergy(pullSide, toPull, false);
} else if (fuelType == FuelType.FLUID) {
if (tile instanceof IFluidHandler) {
IFluidHandler fluidTile = (IFluidHandler) tile;
FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
return;
}
fluid = fluidTile.drain(pullSide, toPull, true);
pulled = fluid.amount;
}
}
if (pulled > 0) {
packItem.addFuel(chestplate, pulled, false);
}
}
}
use of tonius.simplyjetpacks.item.meta.PackBase in project SimplyJetpacks by Tonius.
the class GuiHandler method getServerGuiElement.
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch(ID) {
case PACK:
ItemStack chestplate = player.getCurrentArmor(2);
if (chestplate != null && chestplate.getItem() instanceof ItemPack) {
ItemPack packItem = (ItemPack) chestplate.getItem();
PackBase pack = packItem.getPack(chestplate);
if (pack != null) {
return new ContainerPack(chestplate, packItem, pack);
}
}
}
return null;
}
use of tonius.simplyjetpacks.item.meta.PackBase in project SimplyJetpacks by Tonius.
the class GuiHandler method getClientGuiElement.
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch(ID) {
case PACK:
ItemStack chestplate = player.getCurrentArmor(2);
if (chestplate != null && chestplate.getItem() instanceof ItemPack) {
ItemPack packItem = (ItemPack) chestplate.getItem();
PackBase pack = packItem.getPack(chestplate);
if (pack != null) {
return new GuiPack(new ContainerPack(chestplate, packItem, pack));
}
}
}
return null;
}
Aggregations