本文整理匯總了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);
}
示例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();
}
示例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);
}
}
示例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;
}
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
}
}
}
示例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));
}
}
}
示例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);
}
}
}
示例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;
}
}
}
}
}
示例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);
}
}
}
}
示例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));
}
}
示例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)));
}
}
}
}
示例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);
}
}
}
}
示例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);
}