Search in sources :

Example 1 with PropertiesBackpack

use of net.mcft.copy.betterstorage.misc.PropertiesBackpack in project BetterStorage by copygirl.

the class ItemBackpack method damageArmor.

@Override
public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
    if (!takesDamage(stack, source))
        return;
    stack.damageItem(damage, entity);
    if (stack.stackSize > 0)
        return;
    PropertiesBackpack backpackData = ItemBackpack.getBackpackData(entity);
    if (backpackData.contents != null)
        for (ItemStack s : backpackData.contents) WorldUtils.dropStackFromEntity(entity, s, 2.0F);
    entity.renderBrokenItemStack(stack);
}
Also used : PropertiesBackpack(net.mcft.copy.betterstorage.misc.PropertiesBackpack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with PropertiesBackpack

use of net.mcft.copy.betterstorage.misc.PropertiesBackpack in project BetterStorage by copygirl.

the class ItemBackpack method getBackpackData.

public static PropertiesBackpack getBackpackData(EntityLivingBase entity) {
    PropertiesBackpack backpackData = EntityUtils.getOrCreateProperties(entity, PropertiesBackpack.class);
    if (!backpackData.initialized) {
        updateHasItems(entity, backpackData);
        backpackData.initialized = true;
    }
    return backpackData;
}
Also used : PropertiesBackpack(net.mcft.copy.betterstorage.misc.PropertiesBackpack)

Example 3 with PropertiesBackpack

use of net.mcft.copy.betterstorage.misc.PropertiesBackpack 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 4 with PropertiesBackpack

use of net.mcft.copy.betterstorage.misc.PropertiesBackpack 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 5 with PropertiesBackpack

use of net.mcft.copy.betterstorage.misc.PropertiesBackpack in project BetterStorage by copygirl.

the class ModelBackpackArmor method setLivingAnimations.

@Override
public void setLivingAnimations(EntityLivingBase entity, float par2, float par3, float partialTicks) {
    float angle = 0;
    if (entity != null) {
        PropertiesBackpack backpack = ItemBackpack.getBackpackData(entity);
        angle = backpack.prevLidAngle + (backpack.lidAngle - backpack.prevLidAngle) * partialTicks;
        angle = 1.0F - angle;
        angle = 1.0F - angle * angle;
    }
    if (baseModel.top != null)
        baseModel.top.rotateAngleX = (float) (angle * Math.PI / 4.0);
}
Also used : PropertiesBackpack(net.mcft.copy.betterstorage.misc.PropertiesBackpack)

Aggregations

PropertiesBackpack (net.mcft.copy.betterstorage.misc.PropertiesBackpack)9 ItemStack (net.minecraft.item.ItemStack)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 InventoryStacks (net.mcft.copy.betterstorage.inventory.InventoryStacks)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ArrayList (java.util.ArrayList)1 EntityFrienderman (net.mcft.copy.betterstorage.entity.EntityFrienderman)1 ItemBackpack (net.mcft.copy.betterstorage.item.ItemBackpack)1 EntityLiving (net.minecraft.entity.EntityLiving)1 ChestGenHooks (net.minecraftforge.common.ChestGenHooks)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1