Java 类net.minecraftforge.event.entity.player.AttackEntityEvent 实例源码

项目:Adventurers-Toolbox    文件:SpecialToolAbilityHandler.java   
@SubscribeEvent
public void onWitherBoneAttackEvent(AttackEntityEvent event) {

    EntityPlayer player = event.getEntityPlayer();
    ItemStack stack = player.getHeldItemMainhand();

    boolean flag = false;

    if (stack.getItem() instanceof IHaftTool) {
        if (IHaftTool.getHaftMat(stack) == ModMaterials.HAFT_WITHER_BONE) {
            flag = true;
        }
    }

    if (flag) {
        if (player.dimension != DimensionType.NETHER.getId()) {
            stack.damageItem(7, player);
        }
    }
}
项目:BetterWithAddons    文件:ButcherHandler.java   
@SubscribeEvent
public void playerTick(AttackEntityEvent attackEvent)
{
    Entity target = attackEvent.getTarget();
    EntityLivingBase attacker = attackEvent.getEntityLiving();
    if(attacker == null || target == null)
        return;
    World world = attacker.getEntityWorld();
    BlockPos pos = EntityUtil.getEntityFloor(target,2);

    if(!world.isRemote)
    {
        IBlockState state = world.getBlockState(pos);
        if(isChopBlock(state) && isSuitableWeapon(attacker.getHeldItemMainhand()))
        {
            attacker.addPotionEffect(new PotionEffect(MobEffects.STRENGTH,200));
            attacker.addPotionEffect(new PotionEffect(MobEffects.HUNGER,200));
            splatter(world,pos,1);
        }
    }
}
项目:Toms-Mod    文件:EventHandler.java   
@SubscribeEvent
public void onAttack(AttackEntityEvent event) {
    if (!event.getEntityLiving().getHeldItemMainhand().isEmpty()) {
        if (disabledItems.contains(event.getEntityLiving().getHeldItemMainhand().getItem())) {
            event.setCanceled(true);
            if (event.getTarget().canBeAttackedWithItem()) {
                if (!event.getTarget().hitByEntity(event.getEntity())) {
                    event.getEntityPlayer().setLastAttackedEntity(event.getTarget());
                    event.getEntityPlayer().world.playSound((EntityPlayer) null, event.getEntityPlayer().posX, event.getEntityPlayer().posY, event.getEntityPlayer().posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, event.getEntityPlayer().getSoundCategory(), 1.0F, 1.0F);
                    event.getTarget().attackEntityFrom(DamageSource.causePlayerDamage(event.getEntityPlayer()), event.getEntityPlayer().getCooledAttackStrength(1F));
                    event.getEntityPlayer().addExhaustion(0.1F);
                }
            }
        }
    }
}
项目:Survivalist    文件:TorchFireEventHandling.java   
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent ev)
{
    if (!ev.getTarget().isImmuneToFire() && !ev.getTarget().world.isRemote)
    {
        ItemStack stack = ev.getEntityPlayer().getHeldItem(EnumHand.MAIN_HAND);
        if (stack.getCount() > 0 && stack.getItem() instanceof ItemBlock)
        {
            ItemBlock b = (ItemBlock) stack.getItem();
            Block bl = b.getBlock();
            if (bl == Blocks.TORCH)
            {
                ev.getTarget().setFire(2);
                if (rnd.nextFloat() > 0.25)
                {
                    stack.grow(-1);
                    if (stack.getCount() <= 0)
                    {
                        ev.getEntityPlayer().inventory.setInventorySlotContents(ev.getEntityPlayer().inventory.currentItem, ItemStack.EMPTY);
                    }
                }
            }
        }
    }
}
项目:Cyclic    文件:EnchantVenom.java   
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent event) {
  if (event.getTarget() instanceof EntityLivingBase == false) {
    return;
  }
  EntityLivingBase target = (EntityLivingBase) event.getTarget();
  EntityPlayer attacker = event.getEntityPlayer();
  ItemStack main = attacker.getHeldItemMainhand();
  ItemStack off = attacker.getHeldItemOffhand();
  int mainLevel = -1, offLevel = -1;
  if (main != null && EnchantmentHelper.getEnchantments(main).containsKey(this)) {
    mainLevel = EnchantmentHelper.getEnchantments(main).get(this);
  }
  if (off != null && EnchantmentHelper.getEnchantments(off).containsKey(this)) {
    offLevel = EnchantmentHelper.getEnchantments(off).get(this);
  }
  int level = Math.max(mainLevel, offLevel);
  if (level > 0) {
    // we -1  since potion level 1 is Poison II
    //so that means enchantment I giving poison I means this
    UtilEntity.addOrMergePotionEffect(target, new PotionEffect(MobEffects.POISON, durationTicksPerLevel * level, level - 1));
  }
}
项目:Fidelis    文件:Fidelis.java   
@SubscribeEvent
public void onAttack(AttackEntityEvent event){
    if(event.entityPlayer != null && event.entityPlayer.getHeldItem() != null)
        if(event.entityPlayer.getHeldItem().hasTagCompound())
            if(event.entityPlayer.getHeldItem().getTagCompound().hasKey("Fidelis"))
            {
                String fidelisID = event.entityPlayer.getHeldItem().getTagCompound().getString("Fidelis");
                if(event.entityPlayer.getGameProfile().getId().toString().equals(fidelisID))
                    return;
                else if(fidelisID.equals(""))
                {
                    event.entityPlayer.getHeldItem().getTagCompound().setString("Fidelis", event.entityPlayer.getGameProfile().getId().toString());
                    event.entityPlayer.getHeldItem().getTagCompound().setString("FidelisDisplay", event.entityPlayer.getDisplayName());
                }
                else
                    event.setCanceled(true);
            }
}
项目:HarderStart    文件:HS_PlayerAttackEntity.java   
/**
 * Makes stick truly a rudimentary weapon TODO add damage to stick info
 * 
 * @param event
 */
@SubscribeEvent(priority = EventPriority.NORMAL)
public void playerAttackEvent(AttackEntityEvent event)
{
    EntityPlayer player = event.entityPlayer;
    ItemStack itemstack = player.getCurrentEquippedItem();

    if (player != null)
    {
        if (!player.capabilities.disableDamage && itemstack != null)
        {
            if (OreDictionary.itemMatches(new ItemStack(Items.stick), itemstack, true))
            {
                event.target.attackEntityFrom(DamageSource.causePlayerDamage(player), 2.0F);
            }
        }
    }

    return;
}
项目:GriefGuardian    文件:ClaimGuardEventHandler.java   
@SubscribeEvent
public void onEntityAttacked(AttackEntityEvent event){
    if (event.entityPlayer.worldObj.isRemote)
        return;

    if (event.target instanceof EntityPlayer)
        if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(event.entityPlayer, PermissionsMutex.HARM_PLAYERS, event.target.posX, event.target.posY, event.target.posZ))
            event.setCanceled(true);

    if (event.target instanceof EntityCreature)
        if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(event.entityPlayer, PermissionsMutex.HARM_CREATURES, event.target.posX, event.target.posY, event.target.posZ))
            event.setCanceled(true);

    if (event.target instanceof EntityMob)
        if (!ClaimsList.For(event.entity.worldObj).actionIsTrusted(event.entityPlayer, PermissionsMutex.HARM_MONSTERS, event.target.posX, event.target.posY, event.target.posZ))
            event.setCanceled(true);        
}
项目:SimpleTransmutations    文件:EntityLivingHandler.java   
@ForgeSubscribe
public void onAttackEntityEvent(AttackEntityEvent event)
{
    if (!event.entityPlayer.worldObj.isRemote && event.target.getEntityName() != null)
    {       
        player = (EntityPlayer) event.entityPlayer;

        stack = player.getCurrentEquippedItem();

        if (stack != null && stack.itemID == ItemInfo.ESSENCE_CONTAINER_ID + 256)
        {
            for (String s : ModItem.essenceNames)
            {
                if (!usedEssenceContainer && s.equals(event.target.getEntityName()))
                {
                    usedEssenceContainer = true;
                    entity = s;
                }
            }
        }       
        else if (stack != null && stack.itemID != ItemInfo.ESSENCE_CONTAINER_ID + 256)
        {
            usedEssenceContainer = false;
        }
    }
}
项目:pnc-repressurized    文件:PlayerAttackSensor.java   
@Override
public int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range) {
    if (event instanceof AttackEntityEvent) {
        return 15;
    }
    return 0;
}
项目:HardcoreRevival    文件:RestrictionHandler.java   
@SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onAttack(AttackEntityEvent event) {
        EntityPlayer player = event.getEntityPlayer();
        if (player != null && player.getHealth() <= 0f) {
//          if(ModConfig.allowUnarmedMelee && player.getHeldItemMainhand().isEmpty()) {
//              return;
//          }
            event.setCanceled(true);
        }
    }
项目:TextDisplayer    文件:FightingParser.java   
@SubscribeEvent
public void onDamage(AttackEntityEvent entityEvent) {
    if (entityEvent.target instanceof EntityPlayer) {

        // Making sure the player isn't fake (Delivery man etc)
        if (entityEvent.target.getUniqueID().toString().charAt(14) != '4') {
            return;
        }

        this.lastDamaged = (EntityPlayer) entityEvent.target;
        timer = 120;
    }
}
项目:CustomWorldGen    文件:ForgeHooks.java   
public static boolean onPlayerAttackTarget(EntityPlayer player, Entity target)
{
    if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, target))) return false;
    ItemStack stack = player.getHeldItemMainhand();
    if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return false;
    return true;
}
项目:Possessed    文件:ZombieHandler.java   
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent event) {
    if (event.getTarget() instanceof EntityLivingBase) {
        EntityLivingBase target = (EntityLivingBase) event.getTarget();
        EntityPlayer player = event.getEntityPlayer();
        if (this.isActive(player)) {
            PossessivePlayer possessivePlayer = PossessHandler.get(player);
            EntityZombie possessing = (EntityZombie) possessivePlayer.getPossessing();
            if (possessing.getZombieType() == ZombieType.HUSK) {
                target.addPotionEffect(new PotionEffect(MobEffects.HUNGER, 140));
            }
        }
    }
}
项目:Possessed    文件:SkeletonHandler.java   
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent event) {
    if (event.getTarget() instanceof EntityLivingBase) {
        EntityLivingBase target = (EntityLivingBase) event.getTarget();
        EntityPlayer player = event.getEntityPlayer();
        if (this.isActive(player)) {
            PossessivePlayer possessivePlayer = PossessHandler.get(player);
            EntitySkeleton possessing = (EntitySkeleton) possessivePlayer.getPossessing();
            if (possessing.getSkeletonType() == SkeletonType.WITHER) {
                target.addPotionEffect(new PotionEffect(MobEffects.WITHER, 100, 1));
            }
        }
    }
}
项目:MidgarCrusade    文件:JoueurEvent.java   
@SideOnly(Side.CLIENT)
@SubscribeEvent
   public void onAttackClient(AttackEntityEvent event)
{
    ClientPlayerBaseMagic p;

    p = Main.getPlayerClient();
    if (p.getClasse() instanceof ClasseChampion && !event.target.isDead)
    {
        p.increase_energy(40 + p.getPlayer().worldObj.rand.nextInt(40));
        p.last_hit = System.currentTimeMillis();
    }
}
项目:ShearMadness    文件:CommonForgeEventProxy.java   
@SuppressWarnings("BooleanVariableAlwaysNegated")
@SubscribeEvent(priority = EventPriority.HIGH)
public void onAttack(AttackEntityEvent event)
{
    //Process for chiseling a sheep
    final Entity sheep = event.getTarget();
    if (sheep == null) return;

    final EntityPlayer entityPlayer = event.getEntityPlayer();
    ItemStack activeStack = entityPlayer.inventory.getCurrentItem();
    boolean attackedWithChisel = false;
    if (activeStack != null && ChiselLibrary.isChisel(activeStack.getItem()))
    {
        attackedWithChisel = true;
    } else
    {
        activeStack = entityPlayer.inventory.offHandInventory[0];
        if (activeStack != null && ChiselLibrary.isChisel(activeStack.getItem()))
        {
            attackedWithChisel = true;
        }
    }
    if (!attackedWithChisel)
    {
        return;
    }

    if (!sheep.hasCapability(Capability.CHISELED_SHEEP, null)) {
        return;
    }

    event.setCanceled(true);

    Chiseling.chiselSheep(sheep, entityPlayer, activeStack);
}
项目:blockbuster    文件:ActionHandler.java   
/**
 * Event listener for Action.ATTACK
 */
@SubscribeEvent
public void onPlayerAttack(AttackEntityEvent event)
{
    EntityPlayer player = event.getEntityPlayer();
    List<Action> events = CommonProxy.manager.getActions(player);

    if (!player.worldObj.isRemote && events != null && !Blockbuster.proxy.config.record_attack_on_swipe)
    {
        events.add(new AttackAction());
    }
}
项目:morecommands    文件:CommandSuperpunch.java   
@Override
public void onEvent(AttackEntityEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP) {
        ServerPlayerSettings settings = getPlayerSettings((EntityPlayerMP) event.getEntity());

        if (settings.superpunch > 0) {
            event.setCanceled(true);
            this.attackWithSuperpunch((EntityPlayer) event.getEntity(), event.getTarget(), settings.superpunch);
        }
    }
}
项目:Cyclic    文件:EnchantLifeLeech.java   
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent event) {
  if (event.getTarget() instanceof EntityLivingBase == false) {
    return;
  }
  //    EntityLivingBase target = (EntityLivingBase) event.getTarget();
  EntityPlayer attacker = event.getEntityPlayer();
  int level = getCurrentLevelTool(attacker);
  if (level > 0 && attacker.getHealth() < attacker.getMaxHealth()) {
    UtilParticle.spawnParticle(attacker.getEntityWorld(), EnumParticleTypes.HEART, attacker.getPosition().up(2));
    attacker.heal(level);
  }
}
项目:toolscompressor    文件:ItemCompressedTools.java   
@SubscribeEvent
public void onAttack(AttackEntityEvent event){
    if(event.entityPlayer.getCurrentEquippedItem() != null){
        if(event.entityPlayer.getCurrentEquippedItem().getItem() == MainToolsCompressor.compressedTool){
            ItemStack itemstack = event.entityPlayer.getCurrentEquippedItem();
            if(!isFixed(itemstack))
                itemstack.setItemDamage(getMetaFromTool(itemstack, getToolWithMostDamage(itemstack)));
        }
    }
}
项目:ClaimIO    文件:EventBus.java   
@SubscribeEvent
public void onEntityAttack(AttackEntityEvent event) {
    if (event.entity instanceof EntityAmbientCreature || event.entity instanceof EntityAnimal || event.entity instanceof EntityPlayer) {
        EntityPlayerMP player = (EntityPlayerMP) event.entityPlayer;
        if (CoreClaim.claimManager.checkEventCancel(event.entityPlayer, (int) event.entity.posX, (int) event.entity.posZ)) {
            event.setCanceled(true);
            Utils.messageToPlayer(player, EnumChatFormatting.RED + "Oh snap, you are not allowed to harm this entity!");
        }
    }
}
项目:ArmorA    文件:CharmEventHandler.java   
@SubscribeEvent
public void playerAttacks(AttackEntityEvent event) {
    if (event.entityPlayer.worldObj.isRemote)
        return;

    EntityPlayer player = event.entityPlayer;
    InventoryPlayer inv = player.inventory;
    if (!EntityUtil.isFakePlayer(player))
        activateCharms(inv, player, CharmEventType.ATTACKING, event, event.target);
}
项目:Progression    文件:FilterLastHitEntity.java   
@SubscribeEvent(priority = EventPriority.LOW)
public void onEvent(AttackEntityEvent event) {
    if (!event.getTarget().getEntityWorld().isRemote) {
        if (event.getTarget() instanceof EntityLivingBase) {
            cache.put(PlayerHelper.getUUIDForPlayer(event.getEntityPlayer()), (EntityLivingBase) event.getTarget());
        }
    }
}
项目:Gadomancy    文件:IntegrationThaumicHorizions.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(AttackEntityEvent e) {
    EntityPlayer player = e.entityPlayer;
    if(!e.target.worldObj.isRemote && e.target instanceof EntityGolemTH
            && player.isSneaking()) {
        e.setCanceled(true);

        ItemStack stack = player.getCurrentEquippedItem();
        if (stack != null && stack.getItem().onLeftClickEntity(stack, player, e.target)
                && e.target.isDead) {
            CommonProxy.EVENT_HANDLER_GOLEM.on(new PlaySoundAtEntityEvent(e.target, "thaumcraft:zap", 0.5f, 1.0f));
        }
    }
}
项目:Gadomancy    文件:EventHandlerGolem.java   
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(AttackEntityEvent event) {
    ItemStack heldItem = event.entityPlayer.getHeldItem();
    if(heldItem != null && heldItem.getItem() == ConfigItems.itemGolemBell && event.target instanceof EntityGolemBase
            && !event.target.worldObj.isRemote && !event.target.isDead) {
        event.target.captureDrops = true;
        markedGolems.put((EntityGolemBase) event.target, event.entityPlayer);
    }
}
项目:mcpvp-mod    文件:AssistTrackerCTF.java   
public static void onAttack(AttackEntityEvent event) {
    if (!(event.target instanceof EntityPlayer)) return;
    String name = ((EntityPlayer)event.target).getDisplayName();

    // Check for the same team to avoid medic healing causing problems.
    if (TeamCTF.getTeam(name).equals(TeamCTF.usersTeam())) return;

    // Add to the playersHit list with the current system time.
    playersHit.put(name, System.currentTimeMillis());
}
项目:NausicaaMod    文件:NausicaaEventHandler.java   
@SubscribeEvent
public void entityattack(AttackEntityEvent event) {
    if (Main.debug) System.out.println(event.target.toString());
    if (event.target instanceof Ohmu) if (event.entityPlayer.worldObj.isRemote) {
        ExtendedPlayer props = ExtendedPlayer.get(event.entityPlayer);
        System.out.println("before: " + props.toString());
        props.changeKindness(-20);
        // props.changeKindness(-1);
        System.out.println("after: " + props.toString());
    }

}
项目:Quantum-Anomalies    文件:EnchantmentListener.java   
@SubscribeEvent
public void playerAttackedEntity(AttackEntityEvent event) {
    if (event.entityLiving instanceof EntityPlayer) {                                                                               //Allow for revenge attacks
        PropertiesDeceptionTarget target = (PropertiesDeceptionTarget) event.target.getExtendedProperties("deception");
        if (target != null)
            target.injectTarget(event.entityLiving, false);
    }
}
项目:Zombie-Total-Conversion-Craft    文件:PlayerManager.java   
@SuppressWarnings("unused")
@SubscribeEvent
public void onAttackEntity(AttackEntityEvent event) {
    if (event.entityPlayer != null &&
        event.entityPlayer.getHeldItem() != null &&
        ItemWeapon.class.isAssignableFrom(event.entityPlayer.getHeldItem().getItem().getClass())
        ) {
        event.setCanceled(true);
    }
}
项目:ZeldaSwordSkills    文件:ZSSCombatEvents.java   
/**
 * Using this event to set attack time on the server side only in order
 * to prevent left-click processing on blocks with ISmashBlock items
 */
@SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true)
public void onPlayerAttack(AttackEntityEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        setPlayerAttackTime(event.entityPlayer);
    }
}
项目:Battlegear2    文件:BattlemodeHookContainerClass.java   
/**
 * Cancel the attack if the player reach is lowered by some types of items, or if barehanded
 * Note: Applies to either hands, since item is hotswap before this event for offhand weapons
 * @param event for the player attacking an entity
 */
@SubscribeEvent
public void attackEntity(AttackEntityEvent event){
    if(((IBattlePlayer) event.getEntityPlayer()).getSpecialActionTimer() > 0){
        event.setCanceled(true);
        return;
    }
    double reachMod = maxReachDistance(event.getEntityPlayer());
    if (reachMod < event.getEntityPlayer().getDistanceToEntity(event.getTarget())) {
        event.setCanceled(true);
    }
}
项目:PneumaticCraft    文件:PlayerAttackSensor.java   
@Override
public int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range){
    if(event instanceof AttackEntityEvent) {
        return 15;
    }
    return 0;
}
项目:MineCamera    文件:EventLoader.java   
@SubscribeEvent
public void AttackEntity(AttackEntityEvent event) {
    if (event.getEntityPlayer().getEntityData().hasKey("renderViewCamera"))
        event.setCanceled(true);
}
项目:pnc-repressurized    文件:EventHandlerUniversalSensor.java   
@SubscribeEvent
public void onPlayerAttack(AttackEntityEvent event) {
    sendEventToSensors(event.getEntity().world, event);
}
项目:HardcoreRevival    文件:RescueHandler.java   
@SubscribeEvent
public void onAttack(AttackEntityEvent event) {
    // Stop rescuing if the player does something other than rescuing
    abortRescue(event.getEntityPlayer());
}
项目:bit-client    文件:EntityHitEventDispatcher.java   
public EntityHitEventDispatcher() {
    register(this, MinecraftForge.EVENT_BUS, AttackEntityEvent.class);
}
项目:bit-client    文件:EntityHitEventDispatcher.java   
@Override
public void nullify() {
    unregister(this, MinecraftForge.EVENT_BUS, AttackEntityEvent.class);
}
项目:bit-client    文件:EntityHitEventDispatcher.java   
@Override
public void invoke(Event e) {
    AttackEntityEvent event = (AttackEntityEvent) e;
    if (event.target != null) new EntityHitEvent(event.target).call();
}
项目:Possessed    文件:BlazeHandler.java   
@SubscribeEvent
public void onAttack(AttackEntityEvent event) {
    if (this.isActive(event.getEntityPlayer())) {
        event.getTarget().setFire(5);
    }
}