Skip to content

Commit

Permalink
Backport "shoot used arrows" config option
Browse files Browse the repository at this point in the history
  • Loading branch information
NeRdTheNed committed Mar 21, 2023
1 parent 950be70 commit 19cc3d5
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 64 deletions.
206 changes: 142 additions & 64 deletions src/main/java/iDiamondhunter/morebows/CustomBow.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,120 @@ public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer play

/** Flag to indicate that the player is in Creative mode or has infinity on this bow */
final boolean infiniteArrows = player.capabilities.isCreativeMode || (EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0);
ItemStack ammo = null;
int ammoSlot = -1;

if (player.inventory.hasItem(Items.arrow)) {
final int length = player.inventory.mainInventory.length;

for (int i = 0; i < length; ++i) {
if ((player.inventory.mainInventory[i] != null) && (player.inventory.mainInventory[i].getItem() == Items.arrow)) {
ammo = player.inventory.mainInventory[i];
ammoSlot = i;
break;
}
}
}

if (ammo == null) {
ammo = new ItemStack(Items.arrow, 64);
}

final int ammoCount = infiniteArrows ? 64 : ammo.stackSize;
final int usedAmmo;
final int shotArrows;
final int maxAmmo;

if (multiShot) {
if (bowType == ARROW_TYPE_ENDER) {
maxAmmo = 6;
} else {
maxAmmo = !world.isRemote && (itemRand.nextInt(4) == 0) ? 3 : 2;
}
} else {
maxAmmo = 1;
}

if (MoreBows.useAmmoForShotArrows) {
usedAmmo = ammoCount > maxAmmo ? maxAmmo : ammoCount;
shotArrows = usedAmmo;
} else {
usedAmmo = 1;
shotArrows = maxAmmo;
}

final EntityArrow[] arrs;

// Create the arrows to fire
if (multiShot) { // Bows that shoot multiple arrows
final int pickupStatus = (MoreBows.useAmmoForShotArrows) && !infiniteArrows ? 1 : 2;

if (bowType == ARROW_TYPE_ENDER) { // Ender bow
arrs = new EntityArrow[] {
new CustomArrow(world, player, shotVelocity * 2.0F, ARROW_TYPE_ENDER),
new CustomArrow(world, player, shotVelocity * 1.0F, ARROW_TYPE_ENDER),
new CustomArrow(world, player, shotVelocity * 1.2F, ARROW_TYPE_ENDER),
new CustomArrow(world, player, shotVelocity * 1.5F, ARROW_TYPE_ENDER),
new CustomArrow(world, player, shotVelocity * 1.75F, ARROW_TYPE_ENDER),
new CustomArrow(world, player, shotVelocity * 1.825F, ARROW_TYPE_ENDER)
};
arrs[1].canBePickedUp = 2;
arrs[2].canBePickedUp = 2;
arrs[3].canBePickedUp = 2;
arrs[4].canBePickedUp = 2;
arrs[5].canBePickedUp = 2;
} else {
if (itemRand.nextInt(4) == 0) { // Multi bow
arrs = new EntityArrow[] {
new EntityArrow(world, player, shotVelocity * 2.0F),
new EntityArrow(world, player, shotVelocity * 1.65F),
new EntityArrow(world, player, shotVelocity * 1.275F)
};
arrs[2].canBePickedUp = 2;
} else {
arrs = new EntityArrow[] {
new EntityArrow(world, player, shotVelocity * 2.0F),
new EntityArrow(world, player, shotVelocity * 1.65F)
};
arrs = new EntityArrow[shotArrows];

for (int i = 0; i < shotArrows; ++i) {
final float velocityChoice;

switch (i) {
case 1:
velocityChoice = shotVelocity * 1.0F;
break;

case 2:
velocityChoice = shotVelocity * 1.2F;
break;

case 3:
velocityChoice = shotVelocity * 1.5F;
break;

case 4:
velocityChoice = shotVelocity * 1.75F;
break;

case 5:
velocityChoice = shotVelocity * 1.825F;
break;

default:
velocityChoice = shotVelocity * 2.0F;
break;
}

if (i > 0) {
arrs[i] = new CustomArrow(world, player, velocityChoice, ARROW_TYPE_ENDER);
arrs[i].canBePickedUp = pickupStatus;
} else {
arrs[i] = new CustomArrow(world, player, velocityChoice, ARROW_TYPE_ENDER);
}
}
} else {
arrs = new EntityArrow[shotArrows];

for (int i = 0; i < shotArrows; ++i) {
final float velocityChoice;

arrs[1].canBePickedUp = 2;
switch (i) {
case 1:
velocityChoice = shotVelocity * 1.65F;
break;

case 2:
velocityChoice = shotVelocity * 1.275F;
break;

default:
velocityChoice = shotVelocity * 2.0F;
break;
}

if (i > 0) {
arrs[i] = new EntityArrow(world, player, velocityChoice);
arrs[i].canBePickedUp = pickupStatus;
} else {
arrs[i] = new EntityArrow(world, player, velocityChoice);
}
}
}
} else if (bowType == ARROW_TYPE_NOT_CUSTOM) { // "Standard" style bows that do not shoot multiple arrows or have a custom arrow type. Note to self: this is after the multi-arrow bows due to the multi bow having arrows of a normal type.
arrs = new EntityArrow[] { new EntityArrow(world, player, shotVelocity * 2.0F) };
Expand Down Expand Up @@ -210,7 +290,11 @@ public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer play
}

if (!infiniteArrows) {
player.inventory.consumeInventoryItem(Items.arrow);
ammo.stackSize -= usedAmmo;

if ((ammo.stackSize <= 0) && (ammoSlot >= 0)) {
player.inventory.mainInventory[ammoSlot] = null;
}
}

stack.damageItem(1, player);
Expand All @@ -221,40 +305,31 @@ public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer play
if (bowType == ARROW_TYPE_ENDER) { // Ender bow
world.spawnEntityInWorld(new ArrowSpawner(world, player.posX, player.posY, player.posZ, shotVelocity, arrs));
} else { // Multi bow
world.spawnEntityInWorld(arrs[0]);
world.spawnEntityInWorld(arrs[1]);
/**
* This was some code that checked the rotationYaw of the shooting player, but didn't change anything.
* TODO figure out which is supposed to be changed and to what
*
* <pre>
* if (arrs[1].shootingEntity.rotationYaw > 180) {
* arrs[1].posX = arrs[1].posX + (arrs[1].shootingEntity.rotationYaw / 180);
* } else {
* arrs[1].posX = arrs[1].posX + (arrs[1].shootingEntity.rotationYaw / 180);
* }
* </pre>
*/
arrs[1].posX = arrs[1].posX + (arrs[1].shootingEntity.rotationYaw / 180.0F);
arrs[0].setDamage(arrs[0].getDamage() * 1.5D);
arrs[1].setDamage(arrs[1].getDamage() * 1.3D);

if (arrs.length > 2) {
world.spawnEntityInWorld(arrs[2]);
/**
* This was some code that checked the rotationYaw of the shooting player, but didn't change anything.
* TODO figure out which is supposed to be changed and to what
*
* <pre>
* if (arrs[2].shootingEntity.rotationYaw > 180) {
* arrs[2].posX = arrs[2].posX - (arrs[2].shootingEntity.rotationYaw / 180);
* } else {
* arrs[2].posX = arrs[2].posX - (arrs[2].shootingEntity.rotationYaw / 180);
* }
* </pre>
*/
arrs[2].posX = arrs[2].posX - (arrs[2].shootingEntity.rotationYaw / 180.0F);
arrs[2].setDamage(arrs[2].getDamage() * 1.15D);
for (int i = 0; i < shotArrows; ++i) {
final EntityArrow arr = arrs[i];
world.spawnEntityInWorld(arr);
final double damageMultiChoice;

switch (i) {
case 1:
damageMultiChoice = 1.3;
break;

case 2:
damageMultiChoice = 1.15;
break;

default:
damageMultiChoice = 1.5;
break;
}

if ((i > 0) && (arr.shootingEntity != null)) {
final double negate = ((i & 1) << 1) - 1;
arr.posX += (arr.shootingEntity.rotationYaw / 180.0) * negate;
}

arr.setDamage(arr.getDamage() * damageMultiChoice);
}
}
} else { // Other bows
Expand All @@ -267,9 +342,12 @@ public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer play
// Play the "bow shot" sound
if (multiShot && (bowType != ARROW_TYPE_ENDER)) { // Multi bow
world.playSoundAtEntity(player, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
world.playSoundEffect(player.posX + (player.rotationYaw / 180.0F), player.posY, player.posZ, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));

if (arrs.length > 2) {
if (shotArrows > 1) {
world.playSoundEffect(player.posX + (player.rotationYaw / 180.0F), player.posY, player.posZ, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
}

if (shotArrows > 2) {
world.playSoundEffect(player.posX - (player.rotationYaw / 180.0F), player.posY, player.posZ, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
}
} else { // Other bows
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/iDiamondhunter/morebows/MoreBows.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class MoreBows {
public static boolean oldFrostArrowMobSlowdown;
/** MoreBows config setting: If true, render frost arrows as snow cubes. If false, render as snowballs. */
public static boolean oldFrostArrowRendering;
/** MoreBows config setting: If true, use as many arrows as possible, and shoot used arrows. If false, use 1 arrow, and shoot multiple arrows. */
public static boolean useAmmoForShotArrows;

/*
* Hardcoded magic numbers, because Enums (as they're classes) require a large amount of file space, and I'm targeting 64kb as the compiled .jar size.
Expand Down Expand Up @@ -123,6 +125,7 @@ private static final void conf() {
frostArrowsShouldBeCold = config.get(Configuration.CATEGORY_GENERAL, "frostArrowsShouldBeCold", true).getBoolean();
oldFrostArrowMobSlowdown = config.get(Configuration.CATEGORY_GENERAL, "oldFrostArrowMobSlowdown", false).getBoolean();
oldFrostArrowRendering = config.get(Configuration.CATEGORY_GENERAL, "oldFrostArrowRendering", false).getBoolean();
useAmmoForShotArrows = config.get(Configuration.CATEGORY_GENERAL, "useAmmoForShotArrows", false).getBoolean();
config.save();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/morebows/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ oldFrostArrowMobSlowdown.tooltip=If this is enabled, frost arrows will slow Enti
oldFrostArrowMobSlowdown=Old frost arrow mob slowdown
oldFrostArrowRendering.tooltip=If this is enabled, frost arrows will render as cubes.
oldFrostArrowRendering=Old frost arrow rendering
useAmmoForShotArrows.tooltip=Changes how multi-shot bows handle shooting additional arrows. If this is enabled, use as many arrows as possible, and shoot used arrows. If this is disabled, use 1 arrow, and shoot multiple arrows.
useAmmoForShotArrows=Use ammo for the amount of shot arrows

0 comments on commit 19cc3d5

Please sign in to comment.