Java 类net.minecraftforge.event.entity.living.LivingEntityUseItemEvent 实例源码

项目:Soot    文件:PotionFireLung.java   
@SubscribeEvent
public void onItemUse(LivingEntityUseItemEvent event)
{
    EntityLivingBase living = event.getEntityLiving();
    ItemStack stack = event.getItem();
    PotionEffect effect = living.getActivePotionEffect(this);

    if(ItemUtil.matchesOreDict(stack,"torch") && effect != null)
    {
        //TODO: Blow a cloud of fire out
        if(effect.getDuration() > 10)
        {
            PotionEffect reducedEffect = new PotionEffect(this, effect.getDuration() - 5, effect.getAmplifier(), effect.getIsAmbient(), effect.doesShowParticles());
            reducedEffect.setCurativeItems(effect.getCurativeItems());
            living.addPotionEffect(reducedEffect);
        }
        else
        {
            living.removePotionEffect(this);
        }
    }
}
项目:ExPetrum    文件:ExPHandlerServer.java   
@SubscribeEvent
public void onItemUseFinish(LivingEntityUseItemEvent.Tick event)
{
    if (event.getEntity() instanceof EntityPlayer && !event.getEntity().world.isRemote)
    {
        int useCurrent = event.getDuration();
        if (useCurrent == 1)
        {
            IExPPlayer data = IExPPlayer.of((EntityPlayer) event.getEntity());
            if (data != null)
            {
                PlayerManager.handlePlayerEatenFood((EntityPlayer) event.getEntity(), data, event.getItem());
            }
        }
    }
}
项目:LittleThings-old    文件:FoodEvents.java   
@SubscribeEvent
public void OnFinish(LivingEntityUseItemEvent.Finish e) //Why not PlayerUseItemEvent.Finish... FORGE 1.9
{
    if (e.getEntity() instanceof EntityPlayer && e.getItem() != null && e.getItem().getItem() instanceof ItemFood) {
        ItemFood food = (ItemFood) e.getItem().getItem();
        World world = e.getEntity().getEntityWorld();

        if (!world.isRemote) {
            String unlocName = food.getUnlocalizedName().substring(5).toLowerCase();
            if (unlocName.startsWith("raw") || unlocName.endsWith("raw") || unlocName.equals("fish")) {
                if (world.rand.nextFloat() > 0.3F)
                    ((EntityPlayer) e.getEntity()).addPotionEffect(new PotionEffect(MobEffects.hunger, 600, 0));
            }
        }
    }
}
项目:CrystalMod    文件:EventHandler.java   
@SubscribeEvent
public void finishUse(LivingEntityUseItemEvent.Finish event){
    EntityLivingBase entity = event.getEntityLiving();
    ItemStack stack = event.getItem();

    if(entity.isInsideOfMaterial(Material.WATER)){
        if(ItemStackTools.isValid(stack) && stack.getItem() == Items.GLASS_BOTTLE){
            //Restore to full air
            entity.setAir(300);
            ItemStack waterbottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER);
            if(ItemStackTools.getStackSize(stack) > 1){
            event.setResultStack(ItemUtil.consumeItem(stack));
            if(entity instanceof EntityPlayer){
                if(!((EntityPlayer)entity).inventory.addItemStackToInventory(waterbottle)){
                    ItemUtil.spawnItemInWorldWithoutMotion(entity.getEntityWorld(), waterbottle, new BlockPos(entity));
                }
            } else {
                ItemUtil.spawnItemInWorldWithoutMotion(entity.getEntityWorld(), waterbottle, new BlockPos(entity));
            }
            } else {
                event.setResultStack(waterbottle);
            }
        }
    }
}
项目:ImmersiveFloofs    文件:ImmersiveFloofs.java   
@SubscribeEvent
public void onMilkDrink(LivingEntityUseItemEvent.Finish e) {
    if (milkResets && e.getItem().getItem() instanceof ItemBucketMilk && FloofBullet.oldPartCache.containsKey(e.getEntityLiving().getPersistentID())) {
        UUID uuid = e.getEntityLiving().getPersistentID();
        PartsData oldParts = FloofBullet.oldPartCache.get(uuid);
        boolean remove = oldParts == null;
        if (remove) {
            Tails.proxy.removePartsData(uuid);
        }
        else {
            Tails.proxy.addPartsData(uuid, oldParts);
        }
        if (FMLCommonHandler.instance().getSide() == Side.SERVER) {
            Tails.networkWrapper.sendToAll(new PlayerDataMessage(uuid, oldParts, remove));
        }
    }
}
项目:UHC-Reloaded    文件:GoldenSkull.java   
@SubscribeEvent
public void eatApple(LivingEntityUseItemEvent.Start event) {
    if (event.getItem().getItem() != Items.GOLDEN_APPLE || !(event.getEntityLiving() instanceof EntityPlayer)) {
        return;
    }

    EntityPlayer player = (EntityPlayer) event.getEntityLiving();
    if (ConfigHandler.antiCheatMode && event.getItem().getItemDamage() == 1) {
        player.sendMessage(new TextComponentTranslation("message.uhcreloaded.apple.enchanted"));
        event.setCanceled(true);
        return;
    }
    if (!event.getItem().hasTagCompound()) {
        return;
    }
    NBTTagCompound tag = event.getItem().getTagCompound();
    if (tag.getBoolean("golden_skull")) {
        player.addPotionEffect(new PotionEffect(
            MobEffects.HEALTH_BOOST, 1, ConfigHandler.healAmountSkull - 4
        ));
    }
}
项目:MineCraft    文件:EnchantmentArrowFast.java   
@SubscribeEvent
public void decreaseBowUseDuration(LivingEntityUseItemEvent.Tick event) {
    if (event.getItem() == null) {
        return;
    }

    if (event.getItem().getItem() != Items.BOW) {
        return;
    }

    int level = EnchantmentHelper.getEnchantmentLevel(CodingPiratesMod.haste,
            event.getItem());

    switch (level) {
    case 1:
        event.setDuration(event.getDuration() - 1);
        break;
    case 2:
        event.setDuration(event.getDuration() - 2);
        break;
    default:
        break;
    }
}
项目:trumpet-skeleton    文件:TrumpetSkeleton.java   
@SubscribeEvent
public void onActiveItemUseTick(LivingEntityUseItemEvent.Tick event) {
    ItemStack stack = event.getItem();
    if (stack.getItem() == TrumpetSkeletonItems.TRUMPET) {
        if (event.getDuration() == stack.getMaxItemUseDuration() - 10) {
            EntityLivingBase user = event.getEntityLiving();
            World world = user.world;

            user.playSound(TrumpetSkeletonSoundEvents.ITEM_TRUMPET_USE, 1.0F, 0.9F + world.rand.nextFloat() * 0.2F);
            if (!world.isRemote) {
                List<EntityLivingBase> spookedEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, user.getEntityBoundingBox().grow(10.0D));
                for (EntityLivingBase spookedEntity : spookedEntities) {
                    if (spookedEntity == user) continue;
                    double deltaX = user.posX - spookedEntity.posX;
                    double deltaZ = user.posZ - spookedEntity.posZ;
                    double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
                    if (distance > 0.25D) {
                        spookedEntity.knockBack(user, 0.5F, deltaX / distance, deltaZ / distance);
                    }
                    spookedEntity.setRevengeTarget(user);
                }
                stack.damageItem(1, user);
            }
        } else if (event.getDuration() <= stack.getMaxItemUseDuration() - 15) {
            event.setCanceled(true);
        }
    }
}
项目:JustJunk    文件:EventHandlerCommon.java   
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onLivingEntityUseItemEventFinish(LivingEntityUseItemEvent.Finish event) {
    if (the_item.equals("item.apple")){
        if (!event.getEntityLiving().world.isRemote){
            EntityItem item = new EntityItem(event.getEntityLiving().world, event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, new ItemStack(ModItems.applecore, 1));
            event.getEntityLiving().world.spawnEntity(item);
        }
    }
}
项目:HardcoreRevival    文件:RescueHandler.java   
@SubscribeEvent
public void onItemUse(LivingEntityUseItemEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        // Stop rescuing if the player does something other than rescuing
        abortRescue((EntityPlayer) event.getEntityLiving());
    }
}
项目:HardcoreRevival    文件:RestrictionHandler.java   
@SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onPlayerUse(LivingEntityUseItemEvent event) {
        if (event.isCancelable() && event.getEntityLiving() instanceof EntityPlayer) {
//          if(ModConfig.allowBows && event.getItem().getItem() instanceof ItemBow) {
//              return;
//          }
            if (event.getEntityLiving().getHealth() <= 0f) {
                event.setCanceled(true);
            }
        }
    }
项目:CrystalMod    文件:EventHandler.java   
@SubscribeEvent
public void startUse(LivingEntityUseItemEvent.Start event){
    EntityLivingBase entity = event.getEntityLiving();
    ItemStack stack = event.getItem();

    if(entity.isInsideOfMaterial(Material.WATER)){
        if(ItemStackTools.isValid(stack) && stack.getItem() == Items.GLASS_BOTTLE){
            event.setDuration(32);
        }
    }
}
项目:CrystalMod    文件:EventHandler.java   
@SubscribeEvent
public void monitorUse(LivingEntityUseItemEvent.Tick event){
    EntityLivingBase entity = event.getEntityLiving();
    ItemStack stack = event.getItem();

    if(!entity.isInsideOfMaterial(Material.WATER)){
        if(ItemStackTools.isValid(stack) && stack.getItem() == Items.GLASS_BOTTLE){
            event.setDuration(-1);
            event.setCanceled(true);
        }
    }
}
项目:Inhuman-Resources    文件:PotionRedstoneNeedle.java   
private void stopItemUse(LivingEntityUseItemEvent event)
{
    PotionEffect effect = event.getEntityLiving().getActivePotionEffect(PotionRegistry.REDSTONE_NEEDLE);
    if (effect == null)
        return;
    if (effect.getAmplifier() >= 4)
        event.setCanceled(true);
}
项目:Dark-Utilities    文件:FeatureCharms.java   
@SubscribeEvent
public void onItemUse (LivingEntityUseItemEvent.Tick event) {

    // Gluttony Charm
    if (event.getEntityLiving() instanceof EntityPlayer && itemGluttonyCharm.hasItem((EntityPlayer) event.getEntityLiving()) && !event.getItem().isEmpty() && event.getItem().getItem() instanceof ItemFood) {
        event.setDuration(0);
    }
}
项目:Battlegear2    文件:BowHookContainerClass2.java   
@SubscribeEvent(priority = EventPriority.LOW)
public void onBowStartDraw(LivingEntityUseItemEvent.Start use){
    if(use.getDuration() > 1 && BattlegearUtils.isBow(use.getItem().getItem())){
        int lvl = mods.battlegear2.api.EnchantmentHelper.getEnchantmentLevel(BaseEnchantment.bowCharge, use.getItem());
        if(lvl > 0){
            use.setDuration(use.getDuration()- lvl*20000);
            if(use.getDuration() <=0){
                use.setDuration(1);
            }
        }
    }
}
项目:JustJunk    文件:EventHandlerCommon.java   
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onLivingEntityUseItemEventStart(LivingEntityUseItemEvent.Start event){
    // System.out.println("Item: " + event.getItem().getUnlocalizedName());
    the_item = event.getItem().getUnlocalizedName();
}
项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static int onItemUseStart(EntityLivingBase entity, ItemStack item, int duration)
{
    LivingEntityUseItemEvent event = new LivingEntityUseItemEvent.Start(entity, item, duration);
    return MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getDuration();
}
项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static int onItemUseTick(EntityLivingBase entity, ItemStack item, int duration)
{
    LivingEntityUseItemEvent event = new LivingEntityUseItemEvent.Tick(entity, item, duration);
    return MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getDuration();
}
项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static boolean onUseItemStop(EntityLivingBase entity, ItemStack item, int duration)
{
    return MinecraftForge.EVENT_BUS.post(new LivingEntityUseItemEvent.Stop(entity, item, duration));
}
项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static ItemStack onItemUseFinish(EntityLivingBase entity, ItemStack item, int duration, ItemStack result)
{
    LivingEntityUseItemEvent.Finish event = new LivingEntityUseItemEvent.Finish(entity, item, duration, result);
    MinecraftForge.EVENT_BUS.post(event);
    return event.getResultStack();
}
项目:Inhuman-Resources    文件:PotionRedstoneNeedle.java   
@SubscribeEvent
public void onItemUse(LivingEntityUseItemEvent.Start event)
{
    stopItemUse(event);
}
项目:Inhuman-Resources    文件:PotionRedstoneNeedle.java   
@SubscribeEvent
public void onItemUse(LivingEntityUseItemEvent.Tick event)
{
    stopItemUse(event);
}
项目:Inhuman-Resources    文件:PotionStun.java   
@SubscribeEvent
public void onItemUse(LivingEntityUseItemEvent.Start event)
{
    stopItemUse(event);
}
项目:Inhuman-Resources    文件:PotionStun.java   
@SubscribeEvent
public void onItemUse(LivingEntityUseItemEvent.Tick event)
{
    stopItemUse(event);
}
项目:Inhuman-Resources    文件:PotionStun.java   
private void stopItemUse(LivingEntityUseItemEvent event)
{
    PotionEffect effect = event.getEntityLiving().getActivePotionEffect(PotionRegistry.STUN);
    if (effect == null) return;
    event.setCanceled(true);
}
项目:Progression    文件:TriggerItemEaten.java   
@SubscribeEvent
public void onEvent(LivingEntityUseItemEvent.Finish event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        ProgressionAPI.registry.fireTrigger(((EntityPlayer)event.getEntityLiving()), getProvider().getUnlocalisedName(), event.getItem());
    }
}