Search in sources :

Example 1 with ItemBackpack

use of net.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.

the class CommonProxy method onPlayerTick.

@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {
    if (event.side == Side.SERVER && event.phase == Phase.END) {
        //Cleanup in case the backpack is not equipped correctly, due to changing the backpackChestplate setting.
        ItemStack stack = event.player.getEquipmentInSlot(EquipmentSlot.CHEST);
        if (stack != null && stack.getItem() instanceof ItemBackpack && !BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
            //First thing that never should happen...
            event.player.setCurrentItemOrArmor(EquipmentSlot.CHEST, null);
            ItemBackpack.setBackpack(event.player, stack, ItemBackpack.getBackpackData(event.player).contents);
        } else if ((stack == null || (stack.getItem() != null && !(stack.getItem() instanceof ItemBackpack))) && ItemBackpack.getBackpackData(event.player).backpack != null && BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
            //And that.
            ItemStack backpack = ItemBackpack.getBackpack(event.player);
            //Not really a good practice, I'd say.
            ItemBackpack.getBackpackData(event.player).backpack = null;
            if (stack != null) {
                //Drop the armor if the player had some and decided to switch the setting anyways.
                WorldUtils.dropStackFromEntity(event.player, stack, 4.0F);
            }
            event.player.setCurrentItemOrArmor(EquipmentSlot.CHEST, backpack);
        }
    }
}
Also used : ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with ItemBackpack

use of net.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.

the class SlotArmorBackpack method isItemValid.

@Override
public boolean isItemValid(ItemStack stack) {
    if (stack == null)
        return false;
    EntityPlayer player = ((InventoryPlayer) inventory).player;
    Item item = stack.getItem();
    if ((item instanceof ItemBackpack) && !ItemBackpack.canEquipBackpack(player))
        return false;
    return item.isValidArmor(stack, armorType, player);
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Item(net.minecraft.item.Item) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack)

Example 3 with ItemBackpack

use of net.mcft.copy.betterstorage.item.ItemBackpack 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 ItemBackpack

use of net.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.

the class ClientProxy method onRenderPlayerSpecialsPre.

@SubscribeEvent
public void onRenderPlayerSpecialsPre(RenderPlayerEvent.Specials.Pre event) {
    ItemStack backpack = ItemBackpack.getBackpackData(event.entityPlayer).backpack;
    if (backpack != null) {
        EntityPlayer player = event.entityPlayer;
        float partial = event.partialRenderTick;
        ItemBackpack backpackType = (ItemBackpack) backpack.getItem();
        int color = backpackType.getColor(backpack);
        ModelBackpackArmor model = (ModelBackpackArmor) backpackType.getArmorModel(player, backpack, 0);
        model.onGround = ReflectionUtils.invoke(RendererLivingEntity.class, event.renderer, "func_77040_d", "renderSwingProgress", EntityLivingBase.class, float.class, player, partial);
        model.setLivingAnimations(player, 0, 0, partial);
        RenderUtils.bindTexture(new ResourceLocation(backpackType.getArmorTexture(backpack, player, 0, null)));
        RenderUtils.setColorFromInt((color >= 0) ? color : 0xFFFFFF);
        model.render(player, 0, 0, 0, 0, 0, 0);
        if (color >= 0) {
            RenderUtils.bindTexture(new ResourceLocation(backpackType.getArmorTexture(backpack, player, 0, "overlay")));
            GL11.glColor3f(1.0F, 1.0F, 1.0F);
            model.render(player, 0, 0, 0, 0, 0, 0);
        }
        if (backpack.isItemEnchanted()) {
            float f9 = player.ticksExisted + partial;
            RenderUtils.bindTexture(Resources.enchantedEffect);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glColor4f(0.5F, 0.5F, 0.5F, 1.0F);
            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDepthMask(false);
            for (int k = 0; k < 2; ++k) {
                GL11.glDisable(GL11.GL_LIGHTING);
                float f11 = 0.76F;
                GL11.glColor4f(0.5F * f11, 0.25F * f11, 0.8F * f11, 1.0F);
                GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
                GL11.glMatrixMode(GL11.GL_TEXTURE);
                GL11.glLoadIdentity();
                float f12 = f9 * (0.001F + k * 0.003F) * 20.0F;
                float f13 = 0.33333334F;
                GL11.glScalef(f13, f13, f13);
                GL11.glRotatef(30.0F - k * 60.0F, 0.0F, 0.0F, 1.0F);
                GL11.glTranslatef(0.0F, f12, 0.0F);
                GL11.glMatrixMode(GL11.GL_MODELVIEW);
                model.render(player, 0, 0, 0, 0, 0, 0);
            }
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glDepthMask(true);
            GL11.glLoadIdentity();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }
    } else
        backpack = ItemBackpack.getBackpack(event.entityPlayer);
    if (backpack != null)
        event.renderCape = false;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack) ItemStack(net.minecraft.item.ItemStack) ModelBackpackArmor(net.mcft.copy.betterstorage.client.model.ModelBackpackArmor) RendererLivingEntity(net.minecraft.client.renderer.entity.RendererLivingEntity) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 5 with ItemBackpack

use of net.mcft.copy.betterstorage.item.ItemBackpack in project BetterStorage by copygirl.

the class BetterStorageItems method initialize.

public static void initialize() {
    key = MiscUtils.conditionalNew(ItemKey.class, GlobalConfig.keyEnabled);
    lock = MiscUtils.conditionalNew(ItemLock.class, GlobalConfig.lockEnabled);
    keyring = MiscUtils.conditionalNew(ItemKeyring.class, GlobalConfig.keyringEnabled);
    cardboardSheet = MiscUtils.conditionalNew(ItemCardboardSheet.class, GlobalConfig.cardboardSheetEnabled);
    masterKey = MiscUtils.conditionalNew(ItemMasterKey.class, GlobalConfig.masterKeyEnabled);
    drinkingHelmet = MiscUtils.conditionalNew(ItemDrinkingHelmet.class, GlobalConfig.drinkingHelmetEnabled);
    slimeBucket = MiscUtils.conditionalNew(ItemBucketSlime.class, GlobalConfig.slimeBucketEnabled);
    presentBook = new ItemPresentBook();
    itemBackpack = MiscUtils.conditionalNew(ItemBackpack.class, GlobalConfig.backpackEnabled);
    itemEnderBackpack = MiscUtils.conditionalNew(ItemEnderBackpack.class, GlobalConfig.enderBackpackEnabled);
    cardboardHelmet = conditionalNewArmor(GlobalConfig.cardboardHelmetEnabled, 0);
    cardboardChestplate = conditionalNewArmor(GlobalConfig.cardboardChestplateEnabled, 1);
    cardboardLeggings = conditionalNewArmor(GlobalConfig.cardboardLeggingsEnabled, 2);
    cardboardBoots = conditionalNewArmor(GlobalConfig.cardboardBootsEnabled, 3);
    cardboardSword = MiscUtils.conditionalNew(ItemCardboardSword.class, GlobalConfig.cardboardSwordEnabled);
    cardboardPickaxe = MiscUtils.conditionalNew(ItemCardboardPickaxe.class, GlobalConfig.cardboardPickaxeEnabled);
    cardboardShovel = MiscUtils.conditionalNew(ItemCardboardShovel.class, GlobalConfig.cardboardShovelEnabled);
    cardboardAxe = MiscUtils.conditionalNew(ItemCardboardAxe.class, GlobalConfig.cardboardAxeEnabled);
    cardboardHoe = MiscUtils.conditionalNew(ItemCardboardHoe.class, GlobalConfig.cardboardHoeEnabled);
    anyCardboardItemsEnabled = ((BetterStorageItems.cardboardHelmet != null) || (BetterStorageItems.cardboardChestplate != null) || (BetterStorageItems.cardboardLeggings != null) || (BetterStorageItems.cardboardBoots != null) || (BetterStorageItems.cardboardSword != null) || (BetterStorageItems.cardboardPickaxe != null) || (BetterStorageItems.cardboardAxe != null) || (BetterStorageItems.cardboardShovel != null) || (BetterStorageItems.cardboardHoe != null));
    if (cardboardSheet != null)
        OreDictionary.registerOre("sheetCardboard", cardboardSheet);
    Addon.initializeItemsAll();
}
Also used : ItemBucketSlime(net.mcft.copy.betterstorage.item.ItemBucketSlime) ItemCardboardSword(net.mcft.copy.betterstorage.item.cardboard.ItemCardboardSword) ItemCardboardSheet(net.mcft.copy.betterstorage.item.cardboard.ItemCardboardSheet) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack) ItemCardboardAxe(net.mcft.copy.betterstorage.item.cardboard.ItemCardboardAxe) ItemMasterKey(net.mcft.copy.betterstorage.item.locking.ItemMasterKey) ItemPresentBook(net.mcft.copy.betterstorage.item.ItemPresentBook) ItemKeyring(net.mcft.copy.betterstorage.item.locking.ItemKeyring) ItemKey(net.mcft.copy.betterstorage.item.locking.ItemKey) ItemLock(net.mcft.copy.betterstorage.item.locking.ItemLock) ItemCardboardPickaxe(net.mcft.copy.betterstorage.item.cardboard.ItemCardboardPickaxe) ItemEnderBackpack(net.mcft.copy.betterstorage.item.ItemEnderBackpack) ItemCardboardShovel(net.mcft.copy.betterstorage.item.cardboard.ItemCardboardShovel) ItemCardboardHoe(net.mcft.copy.betterstorage.item.cardboard.ItemCardboardHoe) ItemDrinkingHelmet(net.mcft.copy.betterstorage.item.ItemDrinkingHelmet)

Aggregations

ItemBackpack (net.mcft.copy.betterstorage.item.ItemBackpack)6 ItemStack (net.minecraft.item.ItemStack)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ModelBackpack (net.mcft.copy.betterstorage.client.model.ModelBackpack)1 ModelBackpackArmor (net.mcft.copy.betterstorage.client.model.ModelBackpackArmor)1 EntityFrienderman (net.mcft.copy.betterstorage.entity.EntityFrienderman)1 InventoryStacks (net.mcft.copy.betterstorage.inventory.InventoryStacks)1 ItemBucketSlime (net.mcft.copy.betterstorage.item.ItemBucketSlime)1 ItemDrinkingHelmet (net.mcft.copy.betterstorage.item.ItemDrinkingHelmet)1 ItemEnderBackpack (net.mcft.copy.betterstorage.item.ItemEnderBackpack)1 ItemPresentBook (net.mcft.copy.betterstorage.item.ItemPresentBook)1 ItemCardboardAxe (net.mcft.copy.betterstorage.item.cardboard.ItemCardboardAxe)1 ItemCardboardHoe (net.mcft.copy.betterstorage.item.cardboard.ItemCardboardHoe)1 ItemCardboardPickaxe (net.mcft.copy.betterstorage.item.cardboard.ItemCardboardPickaxe)1 ItemCardboardSheet (net.mcft.copy.betterstorage.item.cardboard.ItemCardboardSheet)1 ItemCardboardShovel (net.mcft.copy.betterstorage.item.cardboard.ItemCardboardShovel)1 ItemCardboardSword (net.mcft.copy.betterstorage.item.cardboard.ItemCardboardSword)1