From 178abaf1cd66beec95db829f710e6adabcd5771a Mon Sep 17 00:00:00 2001 From: bconlon Date: Fri, 17 Jul 2020 15:30:22 -0700 Subject: [PATCH] Implemented some enchantment compatibility for certain Aether weapons. May be subject to later balancing. --- .../com/legacy/aether/AetherEventHandler.java | 9 ++- .../projectile/EntityPhoenixArrow.java | 76 +++++++++++++++++++ .../items/weapons/ItemElementalSword.java | 22 +++++- .../weapons/projectile/ItemPhoenixBow.java | 7 ++ 4 files changed, 111 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/legacy/aether/AetherEventHandler.java b/src/main/java/com/legacy/aether/AetherEventHandler.java index 7b4302e..07d1e87 100644 --- a/src/main/java/com/legacy/aether/AetherEventHandler.java +++ b/src/main/java/com/legacy/aether/AetherEventHandler.java @@ -14,6 +14,7 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.gameevent.PlayerEvent; import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.client.Minecraft; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityAgeable; import net.minecraft.entity.EntityList; @@ -281,7 +282,13 @@ AetherEventHandler { { if (event.target instanceof EntityLivingBase) { - event.target.setFire(30); + int defaultTime = 30; + int fireAspectModifier = EnchantmentHelper.getFireAspectModifier(event.entityPlayer); + if (fireAspectModifier > 0) + { + defaultTime += (fireAspectModifier * 4); + } + event.target.setFire(defaultTime); } } } diff --git a/src/main/java/com/legacy/aether/entities/projectile/EntityPhoenixArrow.java b/src/main/java/com/legacy/aether/entities/projectile/EntityPhoenixArrow.java index fa73d94..50995dc 100644 --- a/src/main/java/com/legacy/aether/entities/projectile/EntityPhoenixArrow.java +++ b/src/main/java/com/legacy/aether/entities/projectile/EntityPhoenixArrow.java @@ -1,17 +1,28 @@ package com.legacy.aether.entities.projectile; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import cpw.mods.fml.common.registry.IThrowableEntity; +import java.util.List; + public class EntityPhoenixArrow extends EntityArrow implements IThrowableEntity { private int timeInGround; private boolean hitGround; + public boolean isEnchanted = false; + public EntityPhoenixArrow(World worldIn) { super(worldIn); } @@ -22,6 +33,7 @@ public class EntityPhoenixArrow extends EntityArrow implements IThrowableEntity @Override public void onUpdate() { + if (this.arrowShake == 7) { this.hitGround = true; } @@ -39,6 +51,70 @@ public class EntityPhoenixArrow extends EntityArrow implements IThrowableEntity } super.onUpdate(); + + Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ); + Vec3 vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); + MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(vec31, vec3, false, true, false); + vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ); + vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); + + if (movingobjectposition != null) + { + vec3 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); + } + + Entity entity = null; + List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); + double d0 = 0.0D; + int i; + float f1; + + for (i = 0; i < list.size(); ++i) + { + Entity entity1 = (Entity)list.get(i); + + if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity)) + { + f1 = 0.3F; + AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand((double)f1, (double)f1, (double)f1); + MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3); + + if (movingobjectposition1 != null) + { + double d1 = vec31.distanceTo(movingobjectposition1.hitVec); + + if (d1 < d0 || d0 == 0.0D) + { + entity = entity1; + d0 = d1; + } + } + } + } + + if (entity != null) + { + movingobjectposition = new MovingObjectPosition(entity); + } + + if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) + { + EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit; + + if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer)) + { + movingobjectposition = null; + } + } + + if (movingobjectposition != null) { + if (movingobjectposition.entityHit != null) { + if (this.isEnchanted) { + movingobjectposition.entityHit.setFire(10); + } + } + } + } @Override diff --git a/src/main/java/com/legacy/aether/items/weapons/ItemElementalSword.java b/src/main/java/com/legacy/aether/items/weapons/ItemElementalSword.java index d3e048e..0959e9b 100644 --- a/src/main/java/com/legacy/aether/items/weapons/ItemElementalSword.java +++ b/src/main/java/com/legacy/aether/items/weapons/ItemElementalSword.java @@ -1,5 +1,7 @@ package com.legacy.aether.items.weapons; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.item.EnumRarity; @@ -27,13 +29,29 @@ public class ItemElementalSword extends ItemSword { @Override public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase entityliving1) { if (this == ItemsAether.flaming_sword) { - entityliving.setFire(30); + int defaultTime = 30; + int fireAspectModifier = EnchantmentHelper.getFireAspectModifier(entityliving1); + if (fireAspectModifier > 0) + { + defaultTime += (fireAspectModifier * 4); + } + entityliving.setFire(defaultTime); } else if (this == ItemsAether.lightning_sword) { EntityLightningBolt lightning = new EntityLightningBolt(entityliving1.worldObj, entityliving.posX, entityliving.posY, entityliving.posZ); entityliving1.worldObj.spawnEntityInWorld(lightning); } else if (this == ItemsAether.holy_sword && entityliving.isEntityUndead()) { - entityliving.attackEntityFrom(DamageSource.drown, 15.0F); + + float damage = 15.0F; + + int level = EnchantmentHelper.getEnchantmentLevel(Enchantment.smite.effectId, itemstack); + + if (level > 0) + { + damage += (level * 2.5); + } + + entityliving.attackEntityFrom(DamageSource.drown, damage); itemstack.damageItem(10, entityliving1); } diff --git a/src/main/java/com/legacy/aether/items/weapons/projectile/ItemPhoenixBow.java b/src/main/java/com/legacy/aether/items/weapons/projectile/ItemPhoenixBow.java index 08dc161..e7f093e 100644 --- a/src/main/java/com/legacy/aether/items/weapons/projectile/ItemPhoenixBow.java +++ b/src/main/java/com/legacy/aether/items/weapons/projectile/ItemPhoenixBow.java @@ -145,6 +145,13 @@ public class ItemPhoenixBow extends ItemBow { entityarrow.setKnockbackStrength(k); } + int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack); + + if (l > 0) + { + entityarrow.isEnchanted = true; + } + stack.damageItem(1, entityplayer); if (flag1) {