Search in sources :

Example 1 with PackBase

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;
        }
    }
}
Also used : PackBase(tonius.simplyjetpacks.item.meta.PackBase) ItemPack(tonius.simplyjetpacks.item.ItemPack) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with PackBase

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;
}
Also used : ItemJetpack(tonius.simplyjetpacks.item.ItemPack.ItemJetpack) JetPlate(tonius.simplyjetpacks.item.meta.JetPlate) PackBase(tonius.simplyjetpacks.item.meta.PackBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ParticleType(tonius.simplyjetpacks.setup.ParticleType) ItemPack(tonius.simplyjetpacks.item.ItemPack) ItemStack(net.minecraft.item.ItemStack) IEnergyContainerItem(cofh.api.energy.IEnergyContainerItem)

Example 3 with PackBase

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);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IEnergyProvider(cofh.api.energy.IEnergyProvider) FluidStack(net.minecraftforge.fluids.FluidStack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) FuelType(tonius.simplyjetpacks.setup.FuelType) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 4 with PackBase

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;
}
Also used : ContainerPack(tonius.simplyjetpacks.gui.ContainerPack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) ItemPack(tonius.simplyjetpacks.item.ItemPack) ItemStack(net.minecraft.item.ItemStack)

Example 5 with PackBase

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;
}
Also used : ContainerPack(tonius.simplyjetpacks.gui.ContainerPack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) GuiPack(tonius.simplyjetpacks.gui.GuiPack) ItemPack(tonius.simplyjetpacks.item.ItemPack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)5 PackBase (tonius.simplyjetpacks.item.meta.PackBase)5 ItemPack (tonius.simplyjetpacks.item.ItemPack)4 ContainerPack (tonius.simplyjetpacks.gui.ContainerPack)2 IEnergyContainerItem (cofh.api.energy.IEnergyContainerItem)1 IEnergyProvider (cofh.api.energy.IEnergyProvider)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 EntityItem (net.minecraft.entity.item.EntityItem)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1 GuiPack (tonius.simplyjetpacks.gui.GuiPack)1 ItemJetpack (tonius.simplyjetpacks.item.ItemPack.ItemJetpack)1 JetPlate (tonius.simplyjetpacks.item.meta.JetPlate)1 FuelType (tonius.simplyjetpacks.setup.FuelType)1 ParticleType (tonius.simplyjetpacks.setup.ParticleType)1