From 1426e49164325d2880496b9370ed06635bdb8525 Mon Sep 17 00:00:00 2001 From: Tobias Gremeyer Date: Fri, 1 Feb 2019 02:17:00 +0100 Subject: [PATCH] Potion tipped & modded arrows now get the will effects applied alongside them. (#1424) * Potion tipped arrows now get the will effects applied alongside them - Destructive releases a splash potion at the target location - potion amplifiers are increased if the potion effect is already applied by the will type (poison, levitation, slowness) * On hold for now, I'll do the commands first (I've had enough of arrows for this week). * Revert Sentient Bow/Arrow to handle only potion arrows and fire regular modded arrows. * Removed last remnants of modded arrow creation code. * arrowHit() now supports modded Arrows (onUpdate() has the issue of TNT arrows exploding indefinitely atm) * Crashes when firing a TNT arrow from the SimplyArrows mod with destructive will infused sentient bow * Fixed potion arrows. Modded arrows now work fully when hitting the ground (no splash visual effect). * Added scaling for explosive potion arrows + cleanup --- .../projectile/EntitySentientArrow.java | 320 +++++++++++++----- .../bloodmagic/item/soul/ItemSentientBow.java | 241 ++++++------- 2 files changed, 330 insertions(+), 231 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySentientArrow.java b/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySentientArrow.java index 1e91024e..aa90eaa3 100644 --- a/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySentientArrow.java +++ b/src/main/java/WayofTime/bloodmagic/entity/projectile/EntitySentientArrow.java @@ -1,59 +1,94 @@ package WayofTime.bloodmagic.entity.projectile; -import java.util.Locale; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.monster.IMob; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.projectile.EntityTippedArrow; -import net.minecraft.init.Items; -import net.minecraft.init.MobEffects; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.PotionEffect; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.World; import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.soul.PlayerDemonWillHandler; import WayofTime.bloodmagic.util.Constants; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.entity.projectile.EntityTippedArrow; +import net.minecraft.init.Items; +import net.minecraft.init.MobEffects; +import net.minecraft.init.PotionTypes; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.potion.PotionType; +import net.minecraft.potion.PotionUtils; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; -public class EntitySentientArrow extends EntityTippedArrow -{ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Locale; + +public class EntitySentientArrow extends EntityTippedArrow { + public PotionType potion = PotionTypes.EMPTY; public double reimbursedAmountOnHit = 0; public EnumDemonWillType type = EnumDemonWillType.DEFAULT; public int currentLevel = 0; - public float[] destructiveExplosionRadius = { 0.5f, 1, 1.5f, 2, 2.5f, 3, 3.5f }; - public int[] poisonDuration = { 50, 100, 150, 80, 120, 160, 200 }; - public int[] poisonLevel = { 0, 0, 0, 1, 1, 1, 1 }; - public int[] levitationDuration = { 20, 40, 60, 80, 100, 120, 160 }; - public int[] levitationLevel = { 0, 0, 0, 1, 1, 1, 2 }; - public int[] slownessDuration = { 40, 60, 100, 150, 200, 250, 300 }; - public int[] slownessLevel = { 0, 0, 0, 1, 1, 1, 2 }; + public ItemStack itemStack; + public Class specialArrowClass; + public float[] destructiveExplosionRadius = {0.5f, 1, 1.5f, 2, 2.5f, 3, 3.5f}; + public int[] poisonDuration = {50, 100, 150, 80, 120, 160, 200}; + public int[] poisonLevel = {0, 0, 0, 1, 1, 1, 1}; + public int[] levitationDuration = {20, 40, 60, 80, 100, 120, 160}; + public int[] levitationLevel = {0, 0, 0, 1, 1, 1, 2}; + public int[] slownessDuration = {40, 60, 100, 150, 200, 250, 300}; + public int[] slownessLevel = {0, 0, 0, 1, 1, 1, 2}; + public EntityArrow specialEntity; + public MethodHandle specialHitMH; + public Method specialHit; - public EntitySentientArrow(World worldIn) - { + public EntitySentientArrow(World worldIn) { super(worldIn); } - public EntitySentientArrow(World worldIn, double x, double y, double z) - { + public EntitySentientArrow(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } - public EntitySentientArrow(World worldIn, EntityLivingBase shooter, EnumDemonWillType type, double reinburseAmount, int currentLevel) - { + public EntitySentientArrow(World worldIn, EntityLivingBase shooter, EnumDemonWillType type, double reimburseAmount, int currentLevel) { super(worldIn, shooter); - this.reimbursedAmountOnHit = reinburseAmount; + this.reimbursedAmountOnHit = reimburseAmount; this.type = type; this.currentLevel = currentLevel; } - public void reimbursePlayer(EntityLivingBase hitEntity, float damage) - { - if (this.shootingEntity instanceof EntityPlayer) - { - if (hitEntity.getEntityWorld().getDifficulty() != EnumDifficulty.PEACEFUL && !(hitEntity instanceof IMob)) - { + public EntitySentientArrow(World worldIn, EntityLivingBase shooter, EnumDemonWillType type, double reimburseAmount, int currentLevel, PotionType potion) { + super(worldIn, shooter); + this.reimbursedAmountOnHit = reimburseAmount; + this.type = type; + this.currentLevel = currentLevel; + this.potion = potion; + } + + public EntitySentientArrow(World worldIn, EntityLivingBase shooter, EnumDemonWillType type, double reimburseAmount, int currentLevel, ItemStack itemStack) { + super(worldIn, shooter); + this.reimbursedAmountOnHit = reimburseAmount; + this.type = type; + this.currentLevel = currentLevel; + this.potion = PotionUtils.getPotionFromItem(itemStack); + } + + public EntitySentientArrow(World worldIn, EntityLivingBase shooter, EnumDemonWillType type, double reimburseAmount, int currentLevel, EntityArrow specialArrow) { + super(worldIn, shooter); + this.reimbursedAmountOnHit = reimburseAmount; + this.type = type; + this.currentLevel = currentLevel; + this.specialEntity = specialArrow; + this.specialArrowClass = specialArrow.getClass(); + } + + public void reimbursePlayer(EntityLivingBase hitEntity, float damage) { + if (this.shootingEntity instanceof EntityPlayer) { + if (hitEntity.getEntityWorld().getDifficulty() != EnumDifficulty.PEACEFUL && !(hitEntity instanceof IMob)) { return; } @@ -62,68 +97,169 @@ public class EntitySentientArrow extends EntityTippedArrow } @Override - protected void arrowHit(EntityLivingBase living) - { - super.arrowHit(living); - - switch (type) - { - case CORROSIVE: - living.addPotionEffect(new PotionEffect(MobEffects.POISON, currentLevel >= 0 ? poisonDuration[currentLevel] : 0, currentLevel >= 0 ? poisonLevel[currentLevel] : 0)); - break; - case DEFAULT: - break; - case DESTRUCTIVE: - this.world.createExplosion(this, this.posX, this.posY, this.posZ, currentLevel >= 0 ? destructiveExplosionRadius[currentLevel] : 0, false); - break; - case STEADFAST: - living.addPotionEffect(new PotionEffect(MobEffects.LEVITATION, currentLevel >= 0 ? levitationDuration[currentLevel] : 0, currentLevel >= 0 ? levitationLevel[currentLevel] : 0)); - break; - case VENGEFUL: - living.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, currentLevel >= 0 ? slownessDuration[currentLevel] : 0, currentLevel >= 0 ? slownessLevel[currentLevel] : 0)); - break; - default: - break; - } - } - - @Override - public void onUpdate() - { - super.onUpdate(); - - if (!this.world.isRemote && this.inGround && this.timeInGround > 0) - { - switch (type) - { - case DESTRUCTIVE: - this.world.createExplosion(this, this.posX, this.posY, this.posZ, currentLevel >= 0 ? destructiveExplosionRadius[currentLevel] : 0, false); - this.setDead(); - break; + protected void arrowHit(EntityLivingBase living) { + int amp = -1; + switch (type) { case CORROSIVE: + if (this.potion != null) + for (PotionEffect i : this.potion.getEffects()) { + if (i.getEffectName().equals("poison")) { + amp = i.getAmplifier(); + continue; + } + living.addPotionEffect(new PotionEffect(i.getPotion(), i.getDuration(), i.getAmplifier())); + } + living.addPotionEffect(new PotionEffect(MobEffects.POISON, currentLevel >= 0 ? (amp > -1 && poisonLevel[currentLevel] != amp) ? poisonDuration[currentLevel] / 2 : poisonDuration[currentLevel] : 0, currentLevel >= 0 ? (amp > -1) ? Math.max(poisonLevel[currentLevel], amp) + 1 : poisonLevel[currentLevel] : 0)); break; case DEFAULT: + if (this.potion != null) + for (PotionEffect i : this.potion.getEffects()) { + living.addPotionEffect(new PotionEffect(i.getPotion(), i.getDuration(), i.getAmplifier())); + } + break; + case DESTRUCTIVE: + this.world.createExplosion(this, this.posX, this.posY, this.posZ, currentLevel >= 0 ? destructiveExplosionRadius[currentLevel] : 0, false); + createPotionFromArrow(living); break; case STEADFAST: + if (this.potion != null) + for (PotionEffect i : this.potion.getEffects()) { + if (i.getEffectName().equals("levitation")) { + amp = i.getAmplifier(); + continue; + } + living.addPotionEffect(new PotionEffect(i.getPotion(), i.getDuration(), i.getAmplifier())); + } + living.addPotionEffect(new PotionEffect(MobEffects.LEVITATION, currentLevel >= 0 ? (amp > -1 && levitationLevel[currentLevel] != amp) ? levitationDuration[currentLevel] / 2 : levitationDuration[currentLevel] : 0, currentLevel >= 0 ? (amp > -1) ? Math.max(levitationLevel[currentLevel], amp) + 1 : levitationLevel[currentLevel] : 0)); break; case VENGEFUL: + if (this.potion != null) + for (PotionEffect i : this.potion.getEffects()) { + if (i.getEffectName().equals("slowness")) { + amp = i.getAmplifier(); + continue; + } + living.addPotionEffect(new PotionEffect(i.getPotion(), i.getDuration(), i.getAmplifier())); + } + living.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, currentLevel >= 0 ? (amp > -1 && slownessLevel[currentLevel] != amp) ? slownessDuration[currentLevel] / 2 : slownessDuration[currentLevel] : 0, currentLevel >= 0 ? (amp > -1) ? Math.max(slownessLevel[currentLevel], amp) + 1 : slownessLevel[currentLevel] : 0)); break; default: break; + } + if (this.specialArrowClass != null) { + try { + this.specialHit = this.specialArrowClass.getMethod("arrowHit", EntityLivingBase.class); + this.specialHitMH = MethodHandles.lookup().unreflect(this.specialHit).bindTo(this.specialEntity); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } finally { + try { + if (this.specialHitMH != null) + this.specialHitMH.invoke(living); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } } } -// else if (this.inGround && this.timeInGround != 0 && !this.customPotionEffects.isEmpty() && this.timeInGround >= 600) -// { -// this.world.setEntityState(this, (byte)0); -// this.potion = PotionTypes.EMPTY; -// this.customPotionEffects.clear(); -// this.dataManager.set(COLOR, Integer.valueOf(-1)); -// } } @Override - public void writeEntityToNBT(NBTTagCompound tag) - { + public void onUpdate() { + super.onUpdate(); + switch (type) { + case DESTRUCTIVE: + if (this.potion != null) { + this.spawnPotionParticles(2); + } + if (!this.world.isRemote && this.inGround) { + this.world.createExplosion(this, this.posX, this.posY, this.posZ, currentLevel >= 0 ? destructiveExplosionRadius[currentLevel] : 0, false); + if (this.potion != null && this.specialArrowClass == null) { + createPotionFromArrow(null); + this.setDead(); + } + } + break; + case CORROSIVE: + this.spawnPotionParticles(2); + + break; + case DEFAULT: + if (this.potion != null) { + this.spawnPotionParticles(2); + } + break; + case STEADFAST: + if (this.potion != null) { + this.spawnPotionParticles(2); + } + break; + case VENGEFUL: + if (this.potion != null) { + this.spawnPotionParticles(2); + } + break; + default: + break; + } + + if (this.specialArrowClass != null) { + if (!this.world.isRemote) { + this.specialEntity.posX = this.posX; + this.specialEntity.posY = this.posY; + this.specialEntity.posZ = this.posZ; + + this.specialEntity.onUpdate(); + if (this.inGround) { + this.setDead(); + this.specialEntity.setDead(); + } + } + } + } + + //TODO: Potion splash (for destructive will fired tipped arrows) currently does not have a visual effect. + private void createPotionFromArrow(EntityLivingBase living) { + if (this.potion != null) { + float radius = currentLevel >= 0 ? destructiveExplosionRadius[currentLevel] : 0; + AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().grow(radius * 2, radius, radius * 2); + List list = this.world.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb); + + if (!list.isEmpty()) { + for (EntityLivingBase entitylivingbase : list) { + if (entitylivingbase.canBeHitWithPotion()) { + double d0 = this.getDistanceSq(entitylivingbase); + + if (d0 < 16.0D) { + double d1 = 1.0D - Math.sqrt(d0) / 4.0D; + + if (entitylivingbase == living) { + d1 = 1.0D; + } + + for (PotionEffect potioneffect : this.potion.getEffects()) { + Potion potion = potioneffect.getPotion(); + + if (potion.isInstant()) { + potion.affectEntity(this, this.shootingEntity, entitylivingbase, potioneffect.getAmplifier(), d1); + } else { + int i = (int) (d1 * (double) potioneffect.getDuration() + 0.5D); + + if (i > 20) { + entitylivingbase.addPotionEffect(new PotionEffect(potion, i, potioneffect.getAmplifier(), potioneffect.getIsAmbient(), potioneffect.doesShowParticles())); + } + } + } + } + } + } + } + } + } + + @Override + public void writeEntityToNBT(NBTTagCompound tag) { super.writeEntityToNBT(tag); tag.setDouble("reimbursement", reimbursedAmountOnHit); @@ -132,8 +268,7 @@ public class EntitySentientArrow extends EntityTippedArrow } @Override - public void readEntityFromNBT(NBTTagCompound tag) - { + public void readEntityFromNBT(NBTTagCompound tag) { super.readEntityFromNBT(tag); reimbursedAmountOnHit = tag.getDouble("reimbursement"); @@ -142,8 +277,21 @@ public class EntitySentientArrow extends EntityTippedArrow } @Override - protected ItemStack getArrowStack() - { + protected ItemStack getArrowStack() { return new ItemStack(Items.ARROW); } + + public void spawnPotionParticles(int particleCount) { + int i = this.getColor(); + + if (i != -1 && particleCount > 0) { + double d0 = (double) (i >> 16 & 255) / 255.0D; + double d1 = (double) (i >> 8 & 255) / 255.0D; + double d2 = (double) (i >> 0 & 255) / 255.0D; + + for (int j = 0; j < particleCount; ++j) { + this.world.spawnParticle(EnumParticleTypes.SPELL_MOB, this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width, this.posY + this.rand.nextDouble() * (double) this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width, d0, d1, d2); + } + } + } } diff --git a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientBow.java b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientBow.java index fc9b195f..e6df6969 100644 --- a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientBow.java +++ b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientBow.java @@ -19,6 +19,7 @@ import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.entity.projectile.EntityTippedArrow; import net.minecraft.init.Enchantments; import net.minecraft.init.Items; +import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.IItemPropertyGetter; @@ -26,6 +27,8 @@ import net.minecraft.item.ItemArrow; import net.minecraft.item.ItemBow; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.PotionEffect; +import net.minecraft.potion.PotionType; import net.minecraft.stats.StatList; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumHand; @@ -41,67 +44,56 @@ import java.util.Locale; public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentientTool, IVariantProvider//, IMeshProvider { - public static int[] soulBracket = new int[] { 16, 60, 200, 400, 1000, 2000, 4000 }; - public static double[] defaultDamageAdded = new double[] { 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75 }; - public static float[] velocityAdded = new float[] { 0.25f, 0.5f, 0.75f, 1, 1.25f, 1.5f, 1.75f }; - public static double[] soulDrainPerSwing = new double[] { 0.05, 0.1, 0.2, 0.4, 0.75, 1, 1.5 }; //TODO - public static double[] soulDrop = new double[] { 2, 4, 7, 10, 13, 16, 24 }; - public static double[] staticDrop = new double[] { 1, 1, 2, 3, 3, 3, 4 }; + public static int[] soulBracket = new int[] {16, 60, 200, 400, 1000, 2000, 4000}; + public static double[] defaultDamageAdded = new double[] {0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75}; + public static float[] velocityAdded = new float[] {0.25f, 0.5f, 0.75f, 1, 1.25f, 1.5f, 1.75f}; + public static double[] soulDrainPerSwing = new double[] {0.05, 0.1, 0.2, 0.4, 0.75, 1, 1.5}; //TODO + public static double[] soulDrop = new double[] {2, 4, 7, 10, 13, 16, 24}; + public static double[] staticDrop = new double[] {1, 1, 2, 3, 3, 3, 4}; public static float soullessShotVelocity = 2.5F; - public ItemSentientBow() - { + public ItemSentientBow() { + super(); setUnlocalizedName(BloodMagic.MODID + ".sentientBow"); setCreativeTab(BloodMagic.TAB_BM); - this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter() - { + this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) - public float apply(ItemStack stack, World world, EntityLivingBase entityIn) - { - if (entityIn == null) - { + public float apply(ItemStack stack, World world, EntityLivingBase entityIn) { + if (entityIn == null) { return 0.0F; - } else - { + } else { ItemStack itemstack = entityIn.getActiveItemStack(); return !itemstack.isEmpty() && itemstack.getItem() == RegistrarBloodMagicItems.SENTIENT_BOW ? (float) (stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F : 0.0F; } } }); - this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter() - { + this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) - public float apply(ItemStack stack, World world, EntityLivingBase entityIn) - { + public float apply(ItemStack stack, World world, EntityLivingBase entityIn) { return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F; } }); - this.addPropertyOverride(new ResourceLocation("type"), new IItemPropertyGetter() - { + this.addPropertyOverride(new ResourceLocation("type"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) - public float apply(ItemStack stack, World world, EntityLivingBase entityIn) - { + public float apply(ItemStack stack, World world, EntityLivingBase entityIn) { return ((ItemSentientBow) RegistrarBloodMagicItems.SENTIENT_BOW).getCurrentType(stack).ordinal(); } }); } @Override - public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) - { + public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { return RegistrarBloodMagicItems.ITEM_DEMON_CRYSTAL == repair.getItem() || super.getIsRepairable(toRepair, repair); } - public void recalculatePowers(ItemStack stack, World world, EntityPlayer player) - { + public void recalculatePowers(ItemStack stack, World world, EntityPlayer player) { EnumDemonWillType type = PlayerDemonWillHandler.getLargestWillType(player); double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player); recalculatePowers(stack, type, soulsRemaining); } - public void recalculatePowers(ItemStack stack, EnumDemonWillType type, double will) - { + public void recalculatePowers(ItemStack stack, EnumDemonWillType type, double will) { this.setCurrentType(stack, will > 0 ? type : EnumDemonWillType.DEFAULT); int level = getLevel(will); // @@ -122,13 +114,10 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien setDamageAdded(stack, level >= 0 ? getDamageModifier(type, level) : 0); } - private int getLevel(double soulsRemaining) - { + private int getLevel(double soulsRemaining) { int lvl = -1; - for (int i = 0; i < soulBracket.length; i++) - { - if (soulsRemaining >= soulBracket[i]) - { + for (int i = 0; i < soulBracket.length; i++) { + if (soulsRemaining >= soulBracket[i]) { lvl = i; } } @@ -137,49 +126,42 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien } @Override - public EnumDemonWillType getCurrentType(ItemStack stack) - { + public EnumDemonWillType getCurrentType(ItemStack stack) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); - if (!tag.hasKey(Constants.NBT.WILL_TYPE)) - { + if (!tag.hasKey(Constants.NBT.WILL_TYPE)) { return EnumDemonWillType.DEFAULT; } return EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE).toUpperCase(Locale.ENGLISH)); } - public double getDamageModifier(EnumDemonWillType type, int willBracket) - { - switch (type) - { - case VENGEFUL: - return 0; - case DEFAULT: - case CORROSIVE: - case DESTRUCTIVE: - case STEADFAST: - return defaultDamageAdded[willBracket]; + public double getDamageModifier(EnumDemonWillType type, int willBracket) { + switch (type) { + case VENGEFUL: + return 0; + case DEFAULT: + case CORROSIVE: + case DESTRUCTIVE: + case STEADFAST: + return defaultDamageAdded[willBracket]; } return 0; } - public float getVelocityModifier(EnumDemonWillType type, int willBracket) - { - switch (type) - { - case VENGEFUL: - return velocityAdded[willBracket]; - default: - return 0; + public float getVelocityModifier(EnumDemonWillType type, int willBracket) { + switch (type) { + case VENGEFUL: + return velocityAdded[willBracket]; + default: + return 0; } } - public void setDamageAdded(ItemStack stack, double damage) - { + public void setDamageAdded(ItemStack stack, double damage) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -187,8 +169,7 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien tag.setDouble("damage", damage); } - public double getDamageAdded(ItemStack stack) - { + public double getDamageAdded(ItemStack stack) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -196,8 +177,7 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien return tag.getDouble("damage"); } - public void setVelocityOfArrow(ItemStack stack, float velocity) - { + public void setVelocityOfArrow(ItemStack stack, float velocity) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -205,22 +185,19 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien tag.setFloat("velocity", velocity); } - public float getVelocityOfArrow(ItemStack stack) - { + public float getVelocityOfArrow(ItemStack stack) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); - if (tag.hasKey("velocity")) - { + if (tag.hasKey("velocity")) { return tag.getFloat("velocity"); } return 3; } - public void setCurrentType(ItemStack stack, EnumDemonWillType type) - { + public void setCurrentType(ItemStack stack, EnumDemonWillType type) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -228,16 +205,14 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien tag.setString(Constants.NBT.WILL_TYPE, type.toString()); } - public double getDrainOfActivatedBow(ItemStack stack) - { + public double getDrainOfActivatedBow(ItemStack stack) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); return tag.getDouble(Constants.NBT.SOUL_SWORD_ACTIVE_DRAIN); } - public void setDrainOfActivatedBow(ItemStack stack, double drain) - { + public void setDrainOfActivatedBow(ItemStack stack, double drain) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -245,16 +220,14 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien tag.setDouble(Constants.NBT.SOUL_SWORD_ACTIVE_DRAIN, drain); } - public double getStaticDropOfActivatedBow(ItemStack stack) - { + public double getStaticDropOfActivatedBow(ItemStack stack) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); return tag.getDouble(Constants.NBT.SOUL_SWORD_STATIC_DROP); } - public void setStaticDropOfActivatedBow(ItemStack stack, double drop) - { + public void setStaticDropOfActivatedBow(ItemStack stack, double drop) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -262,16 +235,14 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien tag.setDouble(Constants.NBT.SOUL_SWORD_STATIC_DROP, drop); } - public double getDropOfActivatedBow(ItemStack stack) - { + public double getDropOfActivatedBow(ItemStack stack) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); return tag.getDouble(Constants.NBT.SOUL_SWORD_DROP); } - public void setDropOfActivatedBow(ItemStack stack, double drop) - { + public void setDropOfActivatedBow(ItemStack stack, double drop) { NBTHelper.checkNBT(stack); NBTTagCompound tag = stack.getTagCompound(); @@ -280,28 +251,25 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien } @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) - { + public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); this.recalculatePowers(stack, world, player); return super.onItemRightClick(world, player, hand); } @Override - public void gatherVariants(@Nonnull Int2ObjectMap variants) - { + public void gatherVariants(@Nonnull Int2ObjectMap variants) { variants.put(0, "inventory"); } - public EntityTippedArrow getArrowEntity(World world, ItemStack stack, EntityLivingBase target, EntityLivingBase user, float velocity) - { + public EntityTippedArrow getArrowEntity(World world, ItemStack stack, EntityLivingBase target, EntityLivingBase user, float velocity) { EnumDemonWillType type = this.getCurrentType(stack); double amount = user instanceof EntityPlayer ? (this.getDropOfActivatedBow(stack) * world.rand.nextDouble() + this.getStaticDropOfActivatedBow(stack)) : 0; float newArrowVelocity = velocity * getVelocityOfArrow(stack); double soulsRemaining = user instanceof EntityPlayer ? (PlayerDemonWillHandler.getTotalDemonWill(type, (EntityPlayer) user)) : 0; - EntitySentientArrow entityArrow = new EntitySentientArrow(world, user, type, amount, getLevel(soulsRemaining)); + EntitySentientArrow entityArrow = new EntitySentientArrow(world, user, type, amount, getLevel(soulsRemaining), (PotionType) null); double d0 = target.posX - user.posX; double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityArrow.posY; @@ -309,14 +277,12 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2); entityArrow.shoot(d0, d1 + d3 * 0.05, d2, newArrowVelocity, 0); - if (newArrowVelocity == 0) - { + if (newArrowVelocity == 0) { world.playSound(null, user.getPosition(), SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.NEUTRAL, 0.4F, 1.0F); return null; } - if (velocity == 1.0F) - { + if (velocity == 1.0F) { entityArrow.setIsCritical(true); } @@ -326,13 +292,11 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack); - if (k > 0) - { + if (k > 0) { entityArrow.setKnockbackStrength(k); } - if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) - { + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) { entityArrow.setFire(100); } @@ -342,10 +306,8 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien } @Override - public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) - { - if (entityLiving instanceof EntityPlayer) - { + public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) { + if (entityLiving instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entityLiving; boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0; ItemStack itemstack = this.getFiredArrow(player); @@ -355,21 +317,17 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien if (i < 0) return; - if (itemstack != null || flag) - { - if (itemstack == null) - { + if (itemstack != null || flag) { + if (itemstack == null) { itemstack = new ItemStack(Items.ARROW); } float arrowVelocity = getArrowVelocity(i); - if ((double) arrowVelocity >= 0.1D) - { + if ((double) arrowVelocity >= 0.1D) { boolean flag1 = flag && itemstack.getItem() == Items.ARROW; //Forge: Fix consuming custom arrows. - if (!world.isRemote) - { + if (!world.isRemote) { this.recalculatePowers(stack, world, player); EnumDemonWillType type = this.getCurrentType(stack); @@ -378,12 +336,20 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien double amount = (this.getDropOfActivatedBow(stack) * world.rand.nextDouble() + this.getStaticDropOfActivatedBow(stack)); float newArrowVelocity = arrowVelocity * getVelocityOfArrow(stack); - if (itemarrow == Items.ARROW) - { + if (itemarrow == Items.ARROW) { double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player); - entityArrow = new EntitySentientArrow(world, entityLiving, type, amount, getLevel(soulsRemaining)); - } else - entityArrow = itemarrow.createArrow(world, itemstack, player); + entityArrow = new EntitySentientArrow(world, entityLiving, type, amount, getLevel(soulsRemaining), (PotionType) null); + } else if (itemarrow == Items.TIPPED_ARROW) { + double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player); + entityArrow = new EntitySentientArrow(world, entityLiving, type, amount, getLevel(soulsRemaining), itemstack); + } else if (itemarrow == Items.SPECTRAL_ARROW) { + double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player); + entityArrow = new EntitySentientArrow(world, entityLiving, type, amount, getLevel(soulsRemaining), new PotionType(new PotionEffect(MobEffects.GLOWING, 200, 0))); + } else { + double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player); + entityArrow = new EntitySentientArrow(world, entityLiving, type, amount, getLevel(soulsRemaining), itemarrow.createArrow(world, stack, entityLiving)); + } + entityArrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, newArrowVelocity, 1.0F); if (Float.compare(getVelocityOfArrow(stack), soullessShotVelocity) < Float.MIN_NORMAL) @@ -391,8 +357,7 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien world.playSound(null, player.getPosition(), SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.NEUTRAL, 0.4F, 1.0F); } - if (arrowVelocity == 1.0F) - { + if (arrowVelocity == 1.0F) { entityArrow.setIsCritical(true); } @@ -402,20 +367,17 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack); - if (k > 0) - { + if (k > 0) { entityArrow.setKnockbackStrength(k); } - if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) - { + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) { entityArrow.setFire(100); } stack.damageItem(1, player); - if (flag1) - { + if (flag1) { entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY; } @@ -424,12 +386,10 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + arrowVelocity * 0.5F); - if (!flag1) - { + if (!flag1) { itemstack.shrink(1); - if (itemstack.isEmpty()) - { + if (itemstack.isEmpty()) { player.inventory.deleteStack(itemstack); } } @@ -440,22 +400,16 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien } } - protected ItemStack getFiredArrow(EntityPlayer player) - { - if (this.isArrow(player.getHeldItem(EnumHand.OFF_HAND))) - { + protected ItemStack getFiredArrow(EntityPlayer player) { + if (this.isArrow(player.getHeldItem(EnumHand.OFF_HAND))) { return player.getHeldItem(EnumHand.OFF_HAND); - } else if (this.isArrow(player.getHeldItem(EnumHand.MAIN_HAND))) - { + } else if (this.isArrow(player.getHeldItem(EnumHand.MAIN_HAND))) { return player.getHeldItem(EnumHand.MAIN_HAND); - } else - { - for (int i = 0; i < player.inventory.getSizeInventory(); ++i) - { + } else { + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { ItemStack itemstack = player.inventory.getStackInSlot(i); - if (this.isArrow(itemstack)) - { + if (this.isArrow(itemstack)) { return itemstack; } } @@ -465,17 +419,14 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien } @Override - public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player) - { + public boolean spawnSentientEntityOnDrop(ItemStack droppedStack, EntityPlayer player) { World world = player.getEntityWorld(); - if (!world.isRemote) - { + if (!world.isRemote) { this.recalculatePowers(droppedStack, world, player); EnumDemonWillType type = this.getCurrentType(droppedStack); double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player); - if (soulsRemaining < 1024) - { + if (soulsRemaining < 1024) { return false; }