Search in sources :

Example 16 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class ModelDrinkingHelmet method render.

@Override
public void render(Entity entity, float v1, float v2, float v3, float v4, float v5, float v6) {
    ItemStack[] potions = new ItemStack[2];
    if (entity instanceof EntityLivingBase) {
        ItemStack drinkingHelmet = ItemDrinkingHelmet.getDrinkingHelmet((EntityLivingBase) entity);
        // rendering in the enchantment effect render pass. 
        if (!drinkingHelmet.isItemEnchanted() || (pass++ == 0))
            potions = ItemDrinkingHelmet.getPotions(drinkingHelmet);
        else if (pass > 2)
            pass = 0;
    }
    left.stack = potions[0];
    right.stack = potions[1];
    setRotationAngles(v1, v2, v3, v4, v5, v6, entity);
    bipedHead.render(v6);
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack)

Example 17 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class BackpackHandler method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
    EntityLivingBase entity = event.entityLiving;
    EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer) entity : null);
    ItemStack backpack = ItemBackpack.getBackpack(entity);
    PropertiesBackpack backpackData;
    if (backpack == null) {
        backpackData = EntityUtils.getProperties(entity, PropertiesBackpack.class);
        if (backpackData == null)
            return;
        // with a backpack, equip it with one.
        if (backpackData.spawnsWithBackpack) {
            ItemStack[] contents = null;
            if (entity instanceof EntityFrienderman) {
                backpack = new ItemStack(BetterStorageItems.itemEnderBackpack);
                // Remove drop chance for the backpack.
                ((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 0.0F);
            } else {
                backpack = new ItemStack(BetterStorageItems.itemBackpack, 1, RandomUtils.getInt(120, 240));
                ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
                if (RandomUtils.getBoolean(0.15)) {
                    // Give the backpack a random color.
                    int r = RandomUtils.getInt(32, 224);
                    int g = RandomUtils.getInt(32, 224);
                    int b = RandomUtils.getInt(32, 224);
                    int color = (r << 16) | (g << 8) | b;
                    StackUtils.set(backpack, color, "display", "color");
                }
                contents = new ItemStack[backpackType.getBackpackColumns() * backpackType.getBackpackRows()];
                // Set drop chance for the backpack to 100%.
                ((EntityLiving) entity).setEquipmentDropChance(EquipmentSlot.CHEST, 1.0F);
            }
            // If the entity spawned with enchanted armor,
            // move the enchantments over to the backpack.
            ItemStack armor = entity.getEquipmentInSlot(EquipmentSlot.CHEST);
            if (armor != null && armor.isItemEnchanted()) {
                NBTTagCompound compound = new NBTTagCompound();
                compound.setTag("ench", armor.getTagCompound().getTag("ench"));
                backpack.setTagCompound(compound);
            }
            if (contents != null) {
                // Add random items to the backpack.
                InventoryStacks inventory = new InventoryStacks(contents);
                // Add normal random backpack loot.
                WeightedRandomChestContent.generateChestContents(RandomUtils.random, randomBackpackItems, inventory, 20);
                // With a chance of 10%, add some random dungeon loot.
                if (RandomUtils.getDouble() < 0.1) {
                    ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
                    WeightedRandomChestContent.generateChestContents(RandomUtils.random, info.getItems(RandomUtils.random), inventory, 5);
                }
            }
            ItemBackpack.setBackpack(entity, backpack, contents);
            backpackData.spawnsWithBackpack = false;
        } else {
            // but still has some backpack data, drop the items.
            if (backpackData.contents != null) {
                for (ItemStack stack : backpackData.contents) WorldUtils.dropStackFromEntity(entity, stack, 1.5F);
                backpackData.contents = null;
            }
        }
    }
    ItemBackpack.getBackpackData(entity).update(entity);
    if (backpack != null)
        ((ItemBackpack) backpack.getItem()).onEquippedUpdate(entity, backpack);
}
Also used : EntityFrienderman(net.mcft.copy.betterstorage.entity.EntityFrienderman) EntityLiving(net.minecraft.entity.EntityLiving) EntityLivingBase(net.minecraft.entity.EntityLivingBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChestGenHooks(net.minecraftforge.common.ChestGenHooks) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PropertiesBackpack(net.mcft.copy.betterstorage.misc.PropertiesBackpack) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack) ItemStack(net.minecraft.item.ItemStack) InventoryStacks(net.mcft.copy.betterstorage.inventory.InventoryStacks) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 18 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class BackpackHandler method onPlayerRespawn.

@SubscribeEvent
public void onPlayerRespawn(PlayerRespawnEvent event) {
    // If the player dies when when keepInventory is on and respawns,
    // retrieve the backpack items from eir persistent NBT tag.
    NBTTagCompound entityData = event.player.getEntityData();
    if (!entityData.hasKey(EntityPlayer.PERSISTED_NBT_TAG))
        return;
    NBTTagCompound persistent = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
    if (!persistent.hasKey("Backpack"))
        return;
    NBTTagCompound compound = persistent.getCompoundTag("Backpack");
    PropertiesBackpack backpackData = ItemBackpack.getBackpackData(event.player);
    int size = compound.getInteger("count");
    ItemStack[] contents = new ItemStack[size];
    NbtUtils.readItems(contents, compound.getTagList("Items", NBT.TAG_COMPOUND));
    backpackData.contents = contents;
    if (compound.hasKey("Stack"))
        backpackData.backpack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Stack"));
    persistent.removeTag("Backpack");
    if (persistent.hasNoTags())
        entityData.removeTag(EntityPlayer.PERSISTED_NBT_TAG);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PropertiesBackpack(net.mcft.copy.betterstorage.misc.PropertiesBackpack) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 19 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class CardboardEnchantmentRecipe method makeEnchantedBook.

private ItemStack makeEnchantedBook(Enchantment ench, int level) {
    ItemStack book = new ItemStack(Items.enchanted_book);
    ((ItemEnchantedBook) book.getItem()).addEnchantment(book, new EnchantmentData(ench, level));
    return book;
}
Also used : ItemStack(net.minecraft.item.ItemStack) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook) EnchantmentData(net.minecraft.enchantment.EnchantmentData)

Example 20 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class CardboardEnchantmentRecipe method checkMatch.

@Override
public StationCrafting checkMatch(ItemStack[] input, RecipeBounds bounds) {
    // Quick check if input matches the recipe.
    boolean hasCardboardItems = false;
    int bookIndex = -1;
    ItemStack book = null;
    for (int i = 0; i < input.length; i++) {
        ItemStack stack = input[i];
        if (stack == null)
            continue;
        if (stack.getItem() instanceof ICardboardItem)
            hasCardboardItems = true;
        else if ((book == null) && (stack.getItem() == Items.enchanted_book)) {
            bookIndex = i;
            book = stack;
        } else
            return null;
    }
    if ((book == null) || !hasCardboardItems)
        return null;
    // Basic items match the recipe,
    // do more expensive stuff now.
    ItemStack[] output = new ItemStack[9];
    int experienceCost = 0;
    IRecipeInput[] requiredInput = new IRecipeInput[9];
    Collection<StackEnchantment> bookEnchantments = StackUtils.getEnchantments(book).values();
    for (int i = 0; i < input.length; i++) {
        ItemStack stack = input[i];
        if ((stack == null) || !(stack.getItem() instanceof ICardboardItem))
            continue;
        ItemStack outputStack = stack.copy();
        boolean canApply = false;
        Map<Integer, StackEnchantment> stackEnchants = StackUtils.getEnchantments(outputStack);
        int numEnchants = stackEnchants.size();
        for (StackEnchantment bookEnch : bookEnchantments) {
            if (!StackUtils.isEnchantmentCompatible(outputStack, stackEnchants.values(), bookEnch))
                continue;
            StackEnchantment stackEnch = stackEnchants.get(bookEnch.ench.effectId);
            // Calculate enchantment cost.
            int level = (bookEnch.getLevel() - ((stackEnch != null) ? stackEnch.getLevel() : 0));
            experienceCost += calculateCost(bookEnch, (stackEnch == null), numEnchants);
            // Set enchantment level of output item.
            if (stackEnch != null)
                stackEnch.setLevel(bookEnch.getLevel());
            else
                outputStack.addEnchantment(bookEnch.ench, bookEnch.getLevel());
            canApply = true;
        }
        // be applied on the item, the recipe is invalid.
        if (!canApply)
            return null;
        output[i] = outputStack;
        requiredInput[i] = new RecipeInputItemStack(StackUtils.copyStack(stack, 1), true);
    }
    requiredInput[bookIndex] = new RecipeInputItemStack(StackUtils.copyStack(book, 0, false));
    return new StationCrafting(output, requiredInput, experienceCost);
}
Also used : IRecipeInput(net.mcft.copy.betterstorage.api.crafting.IRecipeInput) StationCrafting(net.mcft.copy.betterstorage.api.crafting.StationCrafting) StackEnchantment(net.mcft.copy.betterstorage.utils.StackUtils.StackEnchantment) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack) ItemStack(net.minecraft.item.ItemStack) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2512 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)250 ArrayList (java.util.ArrayList)244 EntityItem (net.minecraft.entity.item.EntityItem)170 Slot (net.minecraft.inventory.Slot)164 TileEntity (net.minecraft.tileentity.TileEntity)155 EntityPlayer (net.minecraft.entity.player.EntityPlayer)153 Block (net.minecraft.block.Block)148 Item (net.minecraft.item.Item)118 BlockPos (net.minecraft.util.math.BlockPos)83 NBTTagList (net.minecraft.nbt.NBTTagList)74 IInventory (net.minecraft.inventory.IInventory)73 IBlockState (net.minecraft.block.state.IBlockState)70 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)67 FluidStack (net.minecraftforge.fluids.FluidStack)63 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)63 World (net.minecraft.world.World)56 List (java.util.List)55 ResourceLocation (net.minecraft.util.ResourceLocation)50 Entity (net.minecraft.entity.Entity)47