當前位置: 首頁>>代碼示例>>Java>>正文


Java LivingHurtEvent.getAmount方法代碼示例

本文整理匯總了Java中net.minecraftforge.event.entity.living.LivingHurtEvent.getAmount方法的典型用法代碼示例。如果您正苦於以下問題:Java LivingHurtEvent.getAmount方法的具體用法?Java LivingHurtEvent.getAmount怎麽用?Java LivingHurtEvent.getAmount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraftforge.event.entity.living.LivingHurtEvent的用法示例。


在下文中一共展示了LivingHurtEvent.getAmount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onHurtEvent

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public static void onHurtEvent(LivingHurtEvent event)
{
    EntityLivingBase entity = event.getEntityLiving();
    DamageSource damageSource = event.getSource();
    float damage = event.getAmount();
    if(entity != null)
    {
        IAttributeInstance damageRate = null;
        if(isPhysicalDamage(damageSource))
            damageRate = entity.getEntityAttribute(PHYSICAL_DAMAGE_RATE);
        if(damageSource.isFireDamage())
            damageRate = entity.getEntityAttribute(FIRE_DAMAGE_RATE);

        if(damageRate != null)
            damage *= damageRate.getAttributeValue();
    }
    event.setAmount(damage);
}
 
開發者ID:DaedalusGame,項目名稱:Soot,代碼行數:20,代碼來源:Attributes.java

示例2: onHitEntity

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onHitEntity(LivingHurtEvent event) {
	
	if (event.getAmount() <= 0 || event.getEntityLiving() instanceof EntityPlayer) return;
	
	if (!(event.getSource().getSourceOfDamage() instanceof EntityPlayer)) return;
	
	ItemStack transformer = BaublesApi.getBaublesHandler((EntityPlayer)event.getSource().getSourceOfDamage()).getStackInSlot(6);
	if (transformer == null || (transformer != null && transformer.getItem() != this)) return;
	
	Random rand = new Random();
	if (rand.nextInt(100) != 0) return;
	
	EntityLivingBase elb = event.getEntityLiving();
	List<String> entities = new ArrayList<String>(EntityList.ENTITY_EGGS.keySet());
	String randomString = entities.get(rand.nextInt(entities.size()));
	Entity entity = EntityList.createEntityByName(randomString, elb.worldObj);
	if (!entity.isNonBoss()) return;
	entity.setPositionAndRotation(elb.posX, elb.posY, elb.posZ, elb.rotationYaw, elb.rotationPitch);
	
	elb.worldObj.spawnEntityInWorld(entity);
	elb.setDead();
}
 
開發者ID:bafomdad,項目名稱:uniquecrops,代碼行數:24,代碼來源:EmblemTransformation.java

示例3: postInit

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void postInit(LivingHurtEvent e) {

	DamageSource source = e.getSource();

	Iterable<ItemStack> armorStacks = e.getEntityLiving().getArmorInventoryList();

	// boolean hasHeavyArmor = false;
	float reduction = 0;

	for (ItemStack armorStack : armorStacks) {
		if (isHeavyArmor(armorStack)) {
			if (source.isProjectile() || source.isExplosion()) {
				reduction += 0.2;
			}
		}
	}

	if (reduction > 0) {
		float newDamage = (1 - reduction) * e.getAmount();
		System.out.println("Heavy armor reduction: [" + reduction + "] IN[" + e.getAmount() + "] OUT[" + newDamage + "]");
		e.setAmount(newDamage);
	}
}
 
開發者ID:ToroCraft,項目名稱:ToroQuest,代碼行數:25,代碼來源:ItemReinforcedDiamondArmor.java

示例4: onPlayerHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onPlayerHurt(LivingHurtEvent event) {
  if (event.getEntityLiving().getHealth() - event.getAmount() <= 0 && event.getEntityLiving() instanceof EntityPlayer) {
    EntityPlayer p = (EntityPlayer) event.getEntityLiving();
    for (int i = 0; i < p.inventory.getSizeInventory(); ++i) {
      ItemStack s = p.inventory.getStackInSlot(i);
      if (s.getItem() instanceof ItemSoulstone) {
        UtilChat.addChatMessage(p, event.getEntityLiving().getName() + UtilChat.lang("item.soulstone.used"));
        p.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
        UtilSound.playSound(p, SoundEvents.BLOCK_GLASS_BREAK);
        p.setHealth(6);// 3 hearts
        int time = Const.TICKS_PER_SEC * 30;
        p.addPotionEffect(new PotionEffect(MobEffects.FIRE_RESISTANCE, time));
        time = Const.TICKS_PER_SEC * 60;//a full minute
        p.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, time));
        p.addPotionEffect(new PotionEffect(MobEffects.ABSORPTION, time, 4));
        //and bad luck lasts much longer
        time = Const.TICKS_PER_SEC * 60 * 10;
        p.addPotionEffect(new PotionEffect(MobEffects.UNLUCK, time));
        p.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, time, 1));
        event.setCanceled(true);
        break;
      }
    }
  }
}
 
開發者ID:PrinceOfAmber,項目名稱:Cyclic,代碼行數:27,代碼來源:ItemSoulstone.java

示例5: onHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
	Entity attacker = source.getImmediateSource();
	int redo = 5 - amplifier;
	if (attacker != null && (redo < 0 || attacker.world.rand.nextInt(redo) == 0)) {
		float damage = event.getAmount();
		attacker.attackEntityFrom(DamageSource.causeThornsDamage(affected), damage);
	}
}
 
開發者ID:Um-Mitternacht,項目名稱:Bewitchment,代碼行數:10,代碼來源:ShellArmorBrew.java

示例6: PlayerPunchedEvent

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
public PlayerPunchedEvent(LivingHurtEvent event, EntityPlayer attacker)
{
    super(event.getEntityLiving());
    this.source = event.getSource();
    this.amount = event.getAmount();
    this.attacker = attacker;
    this.event = event;
}
 
開發者ID:kenijey,項目名稱:harshencastle,代碼行數:9,代碼來源:PlayerPunchedEvent.java

示例7: playerHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public static void playerHurt(LivingHurtEvent event)
{
	if(!(event.getEntityLiving() instanceof EntityPlayer))
		return;

	List<ItemStack> stackList = EntityUtil.getFullPlayerInventory((EntityPlayer) event.getEntityLiving());

	for(ItemStack stack : stackList)
	{
		if(!stack.isEmpty())
		{
			if(stack.getItem() instanceof ItemAnimaShield)
			{
				ItemAnimaShield item = (ItemAnimaShield) stack.getItem();

				if(!item.isOn(stack))
					continue;

				if(item.getCurrentCharge(stack) > 0 && item.getShieldCharge(stack) > 0)
				{
					float amountTaken = event.getAmount();
					float shieldScaled = item.getShieldCharge(stack) / 10;

					float remain = Math.max(0, amountTaken - shieldScaled);

					event.setAmount(remain);
					item.depleteShield(stack, amountTaken * 10);
					item.removeCharge(stack, (int) (amountTaken * 40));

					if(item.getShieldCharge(stack) == 0)
					{
						item.getShield(stack).onDeplete(stack, event.getEntityLiving());
					}
				}
				return;
			}
		}
	}
}
 
開發者ID:Lemonszz,項目名稱:Anima-Mundi,代碼行數:41,代碼來源:ShieldEvents.java

示例8: livingAttack

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority=EventPriority.HIGH)
public void livingAttack(LivingHurtEvent event) {
	if(event.isCanceled() || event.getSource().isUnblockable())
		return;
	if(event.getEntityLiving().hasCapability(RIG.RIG_ITEM, null)) {
		ItemStack rig=event.getEntityLiving().getCapability(RIG.RIG_ITEM, null).getStackInSlot(0);
		if(rig.hasTagCompound()) {
			int reslevel=1+rig.getTagCompound().getInteger("ResU");
			if(event.getAmount() > 1f)
				event.setAmount(Math.max(1f,event.getAmount() - reslevel * 0.5f));
			
		}
	}
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:15,代碼來源:RIGEvents.java

示例9: onLivingHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event)
{
	if (event.getEntityLiving() instanceof EntityPlayer)
	{
		PlayerAether playerAether = PlayerAether.get((EntityPlayer) event.getEntityLiving());

		if (playerAether != null && playerAether.isWearingObsidianSet())
		{
			float original = event.getAmount();
			event.setAmount(original / 2);
		}
	}
}
 
開發者ID:Modding-Legacy,項目名稱:Aether-Legacy,代碼行數:15,代碼來源:PlayerAetherEvents.java

示例10: onLivingHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent event) {
    if (!event.getEntity().worldObj.isRemote) {
        if (event.getEntity() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) event.getEntity();
            // Exclude Creative Players
            if (player.isCreative()) {
                return;
            }

            // Check Armor in Inventory
            for (ItemStack stack : player.getArmorInventoryList()) {
                if (stack != null && stack.getItem() == this) {
                    if (player.experienceTotal > event.getAmount()) {
                        float amount = event.getAmount();
                        // Reduce the attack amount
                        event.setAmount(amount * (1 - reduction));
                        // Take the experience
                        int exp = (int) (amount * reduction);
                        player.experience -= exp / (float) player.xpBarCap();
                        for (player.experienceTotal -= exp; player.experience <= 0.0F;
                             player.experience /= player.xpBarCap()) {
                            player.experience = (player.experience + 1.0F) * player.xpBarCap();
                            player.removeExperienceLevel(1);
                        }
                    } else {
                        // Reduce the attack amount
                        event.setAmount(event.getAmount() - player.experienceTotal);
                        // Take the experience
                        player.experienceLevel = 0;
                        player.experience = 0.0F;
                        player.experienceTotal = 0;
                    }
                    return;
                }
            }
        }
    }
}
 
開發者ID:InfinityStudio,項目名稱:InspiringWorld,代碼行數:40,代碼來源:ItemAbyssArmor.java

示例11: onLivingHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onLivingHurt (LivingHurtEvent event) {

    if (event.getEntityLiving() instanceof EntityPlayer) {

        final EntityPlayer entityBase = (EntityPlayer) event.getEntityLiving();

        // Focus Sash
        if (entityBase instanceof EntityPlayer && itemFocusSash.hasItem(entityBase) && entityBase.getHealth() >= entityBase.getMaxHealth() && event.getAmount() >= entityBase.getHealth()) {

            event.setAmount(entityBase.getHealth() - 1f);
            entityBase.sendMessage(new TextComponentTranslation("chat.darkutils.focussash", TextFormatting.GREEN));
        }
    }

    // Agression Charm
    if (event.getSource() != null && event.getSource().getTrueSource() instanceof EntityPlayer) {

        final EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();

        if (itemAgressionCharm.hasItem(player)) {
            for (final EntityLivingBase entity : player.getEntityWorld().getEntitiesWithinAABB(event.getEntityLiving().getClass(), player.getEntityBoundingBox().expand(32, 32, 32))) {
                entity.setRevengeTarget(player);
            }
        }
    }
}
 
開發者ID:Darkhax-Minecraft,項目名稱:Dark-Utilities,代碼行數:28,代碼來源:FeatureCharms.java

示例12: onLivingHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent evt) {
    EntityLivingBase ent = evt.getEntityLiving();
    World world = ent.getEntityWorld();
    if(!world.isRemote) {
        int count = ent.getRNG().nextInt(2) + (int)(evt.getAmount()*1.5f);
        float x = (float) ent.posX;
        float y = (float) ent.posY+ ent.height/2f;
        float z = (float) ent.posZ;
        MCDoom.network.sendToAll(new MessageSpawnGoreParticles(count, x, y, z));
    }
}
 
開發者ID:jglrxavpok,項目名稱:MCDoom,代碼行數:13,代碼來源:MCDoomGoreHandler.java

示例13: getDamage

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void getDamage(LivingHurtEvent attackEvent) {
    if (attackEvent.getSource() != null && attackEvent.getSource().getEntity() instanceof EntityPlayer) {
        ItemStack tool = ((EntityPlayer) attackEvent.getSource().getEntity()).inventory.getCurrentItem();
        int sharpness = getEffectStrength(tool, EnumRainbowColor.VIOLET, EnumRainbowColor.VIOLET);
        if (sharpness > 0) {
            attackEvent.setAmount((float) (attackEvent.getAmount() + .5 * sharpness));
        }

        int dullness = getEffectStrength(tool, EnumRainbowColor.VIOLET, EnumRainbowColor.GREEN);
        if (dullness > 0) {
            attackEvent.setAmount(attackEvent.getAmount() - dullness);
            if (attackEvent.getAmount() < 0) {
                attackEvent.setAmount(0);

            }
        }
    }
    if (attackEvent.getEntity() instanceof EntityPlayer) {
        ItemStack heldStack = ((EntityPlayer) attackEvent.getEntity()).inventory.getCurrentItem();
        if (heldStack != null) {
            int protection = getEffectStrength(heldStack, EnumRainbowColor.RED, EnumRainbowColor.VIOLET);
            if (protection > 0) {
                attackEvent.setAmount((float) (attackEvent.getAmount() * Math.pow(.9, protection)));
            }
        }
    }
}
 
開發者ID:AdlyTempleton,項目名稱:Aura-Cascade,代碼行數:29,代碼來源:EnchantEventHandler.java

示例14: onHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onHurt(final LivingHurtEvent e) {
	if (!(e.getEntityLiving() instanceof EntityPlayer)) return;
	EntityPlayer player = (EntityPlayer)e.getEntityLiving();

	final int enchantmentLevels = countLastStandEnchantmentLevels(player);

	if (enchantmentLevels > 0) {
		final float playerHealth = player.getHealth();
		final float healthAvailable = playerHealth - e.getAmount();

		if (healthAvailable < 1f) {
			final int xpAvailable = EnchantmentUtils.getPlayerXP(player);

			float xpRequired = reductionCalculator.evaluate(
					env -> {
						env.setGlobalSymbol(VAR_ENCH_LEVEL, Double.valueOf(enchantmentLevels));
						env.setGlobalSymbol(VAR_PLAYER_XP, Double.valueOf(xpAvailable));
						env.setGlobalSymbol(VAR_PLAYER_HP, Double.valueOf(playerHealth));
						env.setGlobalSymbol(VAR_DAMAGE, Double.valueOf(e.getAmount()));
					},
					() -> {
						float xp = 1f - healthAvailable;
						xp *= 50;
						xp /= enchantmentLevels;
						xp = Math.max(1, xp);
						return Double.valueOf(xp);
					}).floatValue();

			if (xpAvailable >= xpRequired) {
				player.setHealth(1f);
				EnchantmentUtils.addPlayerXP(player, -(int)xpRequired);
				e.setAmount(0);
				e.setCanceled(true);
			}
		}
	}
}
 
開發者ID:OpenMods,項目名稱:OpenBlocks,代碼行數:39,代碼來源:LastStandEnchantmentsHandler.java

示例15: onLivingHurt

import net.minecraftforge.event.entity.living.LivingHurtEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOWEST) //so all other can modify their damage first, and we apply after that
public static void onLivingHurt(LivingHurtEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    float amountToDamage = event.getAmount();
    if (entity.getEntityWorld().isRemote || !(entity instanceof EntityPlayer))
        return;
    EntityPlayer player = (EntityPlayer) entity;
    AbstractPlayerDamageModel damageModel = PlayerDataManager.getDamageModel(player);
    DamageSource source = event.getSource();

    if (amountToDamage == Float.MAX_VALUE) {
        damageModel.forEach(damageablePart -> damageablePart.currentHealth = 0F);
        if (player instanceof EntityPlayerMP)
            Arrays.stream(EnumPlayerPart.VALUES).forEach(part -> FirstAid.NETWORKING.sendTo(new MessageReceiveDamage(part, Float.MAX_VALUE, 0F), (EntityPlayerMP) player));
        event.setCanceled(true);
        CommonUtils.killPlayer(player, source);
        return;
    }

    amountToDamage = ArmorUtils.applyGlobalPotionModifiers(player, source, amountToDamage);

    //VANILLA COPY - combat tracker and exhaustion
    if (amountToDamage != 0.0F) {
        player.addExhaustion(source.getHungerDamage());
        //2nd param is actually never queried, no need to worry about wrong values
        player.getCombatTracker().trackDamage(source, -1, amountToDamage);
    }

    boolean addStat = amountToDamage < 3.4028235E37F;
    IDamageDistribution damageDistribution = FirstAidRegistryImpl.INSTANCE.getDamageDistribution(source);

    if (source.isProjectile()) {
        Pair<Entity, RayTraceResult> rayTraceResult = hitList.remove(player);
        if (rayTraceResult != null) {
            Entity entityProjectile = rayTraceResult.getLeft();
            EntityEquipmentSlot slot = ProjectileHelper.getPartByPosition(entityProjectile, player);
            if (slot != null)
                damageDistribution = new PreferredDamageDistribution(slot);
        }
    }

    float left = damageDistribution.distributeDamage(amountToDamage, player, source, addStat);
    if (left > 0) {
        damageDistribution = RandomDamageDistribution.NEAREST_KILL;
        damageDistribution.distributeDamage(left, player, source, addStat);
    }

    event.setCanceled(true);
    if (damageModel.isDead(player))
        CommonUtils.killPlayer(player, source);

    hitList.remove(player);
}
 
開發者ID:ichttt,項目名稱:FirstAid,代碼行數:54,代碼來源:EventHandler.java


注:本文中的net.minecraftforge.event.entity.living.LivingHurtEvent.getAmount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。