Search in sources :

Example 1 with EntityLiving

use of net.minecraft.entity.EntityLiving in project BetterStorage by copygirl.

the class CommonProxy method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
    if (event.entity.worldObj.isRemote || event.isCanceled())
        return;
    EntityPlayer player = event.entityPlayer;
    Entity target = event.target;
    ItemStack holding = player.getCurrentEquippedItem();
    if ((target.getClass() == EntityChicken.class) && (holding != null) && (holding.getItem() == Items.name_tag)) {
        EntityChicken chicken = (EntityChicken) target;
        if (!chicken.isDead && !chicken.isChild() && "Cluckington".equals(holding.getDisplayName()))
            EntityCluckington.spawn(chicken);
    }
    if ((BetterStorageItems.slimeBucket != null) && (target instanceof EntityLiving) && (holding != null) && (holding.getItem() == Items.bucket)) {
        ItemBucketSlime.pickUpSlime(player, (EntityLiving) target);
        if (player.getCurrentEquippedItem().getItem() instanceof ItemBucketSlime)
            preventSlimeBucketUse = true;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityChicken(net.minecraft.entity.passive.EntityChicken) EntityLiving(net.minecraft.entity.EntityLiving) ItemBucketSlime(net.mcft.copy.betterstorage.item.ItemBucketSlime) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with EntityLiving

use of net.minecraft.entity.EntityLiving in project BetterStorage by copygirl.

the class ItemBucketSlime method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    // instead of placing it in the world.
    if (player.isSneaking())
        return false;
    if (world.isRemote)
        return true;
    x += Facing.offsetsXForSide[side];
    y += Facing.offsetsYForSide[side];
    z += Facing.offsetsZForSide[side];
    String id = getSlimeId(stack);
    String name = StackUtils.get(stack, (String) null, "Slime", "name");
    Entity entity = EntityList.createEntityByName(id, world);
    Handler handler = getHandler(id);
    if ((entity != null) && (handler != null) && (entity instanceof EntityLiving)) {
        EntityLiving slime = (EntityLiving) entity;
        float rotation = MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F);
        slime.setLocationAndAngles(x + 0.5, y, z + 0.5, rotation, 0.0F);
        slime.rotationYawHead = slime.renderYawOffset = rotation;
        if (name != null)
            slime.setCustomNameTag(name);
        handler.setSize(slime, 1);
        NBTTagList effectList = (NBTTagList) StackUtils.getTag(stack, "Effects");
        if (effectList != null)
            for (int i = 0; i < effectList.tagCount(); i++) slime.addPotionEffect(PotionEffect.readCustomPotionEffectFromNBT(effectList.getCompoundTagAt(i)));
        world.spawnEntityInWorld(slime);
        slime.playSound("mob.slime.big", 1.2F, 0.6F);
        player.setCurrentItemOrArmor(EquipmentSlot.HELD, new ItemStack(Items.bucket));
    }
    return true;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) ItemStack(net.minecraft.item.ItemStack)

Example 3 with EntityLiving

use of net.minecraft.entity.EntityLiving 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 EntityLiving

use of net.minecraft.entity.EntityLiving in project SimplyJetpacks by Tonius.

the class EntityInteractHandler method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(EntityInteractEvent evt) {
    if (evt.entityPlayer.isSneaking() && (evt.target instanceof EntityZombie || evt.target instanceof EntitySkeleton)) {
        EntityLiving target = (EntityLiving) evt.target;
        ItemStack heldStack = evt.entityPlayer.getHeldItem();
        if (heldStack != null && heldStack.getItem() instanceof ItemJetpack) {
            if (!target.worldObj.isRemote) {
                target.dropEquipment(true, 3);
            }
            target.setCurrentItemOrArmor(3, heldStack.copy());
            target.equipmentDropChances[3] = 2.0F;
            target.persistenceRequired = true;
            evt.entityPlayer.getHeldItem().stackSize--;
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) ItemJetpack(tonius.simplyjetpacks.item.ItemPack.ItemJetpack) EntityZombie(net.minecraft.entity.monster.EntityZombie) EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 5 with EntityLiving

use of net.minecraft.entity.EntityLiving in project PneumaticCraft by MineMaarten.

the class HackableLivingDisarm method onHackFinished.

@Override
public void onHackFinished(Entity entity, EntityPlayer player) {
    if (!entity.worldObj.isRemote) {
        Random rand = new Random();
        if (fieldDropChance == null) {
            fieldDropChance = ReflectionHelper.findField(EntityLiving.class, "field_82174_bp", "equipmentDropChances");
        }
        try {
            float[] equipmentDropChances = (float[]) fieldDropChance.get(entity);
            for (int i = 0; i < ((EntityLiving) entity).getLastActiveItems().length; i++) {
                ItemStack stack = ((EntityLiving) entity).getLastActiveItems()[i];
                float equipmentDropChance = equipmentDropChances[i];
                boolean flag1 = equipmentDropChance > 1.0F;
                if (stack != null && rand.nextFloat() < equipmentDropChance) {
                    if (!flag1 && stack.isItemStackDamageable()) {
                        int k = Math.max(stack.getMaxDamage() - 25, 1);
                        int l = stack.getMaxDamage() - rand.nextInt(rand.nextInt(k) + 1);
                        if (l > k) {
                            l = k;
                        }
                        if (l < 1) {
                            l = 1;
                        }
                        stack.setItemDamage(l);
                    }
                    entity.entityDropItem(stack, 0.0F);
                }
                ((EntityLiving) entity).setCurrentItemOrArmor(i, null);
            }
            ((EntityLiving) entity).setCanPickUpLoot(false);
        } catch (Exception e) {
            Log.error("Reflection failed on HackableLivingDisarm");
            e.printStackTrace();
        }
    }
}
Also used : Random(java.util.Random) EntityLiving(net.minecraft.entity.EntityLiving) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityLiving (net.minecraft.entity.EntityLiving)44 Entity (net.minecraft.entity.Entity)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 ItemStack (net.minecraft.item.ItemStack)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 World (net.minecraft.world.World)6 Block (net.minecraft.block.Block)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 PotionEffect (net.minecraft.potion.PotionEffect)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 EntityCreature (net.minecraft.entity.EntityCreature)3 BlockPos (net.minecraft.util.math.BlockPos)3 Pos (com.builtbroken.mc.imp.transform.vector.Pos)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)2 EntityMob (net.minecraft.entity.monster.EntityMob)2 EntityZombie (net.minecraft.entity.monster.EntityZombie)2