Trickshot - Sentient Arrows Implementation (#1540)

* The onArrowFire event handler for LivingArmour now checks whether the arrows were fired from a sentient bow, and if they are it calls a getDuplicateArrows method in ItemSentientBow. Said method gets the will and potion types, without changing the bow's durability or consuming will or arrows.

* Extra line breaks removed
This commit is contained in:
Phil 2019-02-13 19:27:41 -05:00 committed by Nick Ignoffo
parent 4a59dede53
commit 2d49fab893
2 changed files with 39 additions and 2 deletions

View file

@ -305,6 +305,33 @@ public class ItemSentientBow extends ItemBow implements IMultiWillTool, ISentien
return entityArrow;
}
public EntitySentientArrow getDuplicateArrow(ItemStack bowStack, World world, EntityPlayer player, double reimburseMultiplier) {
EnumDemonWillType willType = this.getCurrentType(bowStack);
ItemStack arrow = this.getFiredArrow(player);
ItemArrow itemarrow = ((ItemArrow) (arrow.getItem() instanceof ItemArrow ? arrow.getItem() : Items.ARROW));
EntitySentientArrow entityArrow;
double reimburseAmount = (this.getDropOfActivatedBow(bowStack) * world.rand.nextDouble() + this.getStaticDropOfActivatedBow(bowStack)) * reimburseMultiplier;
if (itemarrow == Items.ARROW) {
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(willType, player);
entityArrow = new EntitySentientArrow(world, player, willType, reimburseAmount, getLevel(soulsRemaining), (PotionType) null);
} else if (itemarrow == Items.TIPPED_ARROW) {
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(willType, player);
entityArrow = new EntitySentientArrow(world, player, willType, reimburseAmount, getLevel(soulsRemaining), arrow);
} else if (itemarrow == Items.SPECTRAL_ARROW) {
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(willType, player);
entityArrow = new EntitySentientArrow(world, player, willType, reimburseAmount, getLevel(soulsRemaining), new PotionType(new PotionEffect(MobEffects.GLOWING, 200, 0)));
} else {
double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(willType, player);
entityArrow = new EntitySentientArrow(world, player, willType, reimburseAmount, getLevel(soulsRemaining), itemarrow.createArrow(world, bowStack, player));
}
player.addStat(StatList.getObjectUseStats(this));
return entityArrow;
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {

View file

@ -5,6 +5,7 @@ import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
import WayofTime.bloodmagic.item.soul.ItemSentientBow;
import WayofTime.bloodmagic.livingArmour.LivingArmour;
import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeCrippledArm;
import WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeQuenched;
@ -314,6 +315,7 @@ public class LivingArmourHandler
World world = event.getEntityPlayer().getEntityWorld();
ItemStack stack = event.getBow();
EntityPlayer player = event.getEntityPlayer();
boolean sentientShot = false;
if (world.isRemote)
return;
@ -338,13 +340,21 @@ public class LivingArmourHandler
if (velocity > 1.0F)
velocity = 1.0F;
if (event.getBow().getItem() instanceof ItemSentientBow) {
sentientShot = true;
}
int extraArrows = ((LivingArmourUpgradeArrowShot) upgrade).getExtraArrows();
for (int n = 0; n < extraArrows; n++)
{
ItemStack arrowStack = new ItemStack(Items.ARROW);
ItemArrow itemarrow = (ItemArrow) ((stack.getItem() instanceof ItemArrow ? arrowStack.getItem() : Items.ARROW));
EntityArrow entityarrow = itemarrow.createArrow(world, arrowStack, player);
EntityArrow entityarrow;
if (sentientShot) { // if the arrow was fired from a sentient bow
ItemSentientBow sentientBow = (ItemSentientBow) stack.getItem();
entityarrow = sentientBow.getDuplicateArrow(stack, world, player, 1 / extraArrows);
} else {
entityarrow = itemarrow.createArrow(world, arrowStack, player);
}
entityarrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, velocity * 3.0F, 1.0F);
entityarrow.addTag("arrow_shot");
float velocityModifier = 0.6f * velocity;