Ammo reinforced modifier support (#140)

This commit is contained in:
Nova authored and GitHub committed 2024-12-21 10:28:08 -06:00
1 parent a3dae07fb5
commit 012e6fe2cd
3 files changed
+22 -7

No files matched your search

@@ -107,10 +107,10 @@ public abstract class AmmoWeapon extends AmmoItem implements IBattlegearWeapon,
}
protected void launchProjectile(ItemStack stack, World world, EntityPlayer player, int time) {
ItemStack reference = stack.copy();
reference.stackSize = 1;
// spawn projectile on server
if (!world.isRemote) {
ItemStack reference = stack.copy();
reference.stackSize = 1;
((IAmmo) reference.getItem()).setAmmo(1, reference);
Entity projectile = createProjectile(reference, world, player, getAccuracy(stack, time), time);
@@ -118,7 +118,14 @@ public abstract class AmmoWeapon extends AmmoItem implements IBattlegearWeapon,
}
// reduce ammo
if (!player.capabilities.isCreativeMode) this.consumeAmmo(1, stack);
if (!player.capabilities.isCreativeMode) {
if (reference.hasTagCompound()) {
if (random.nextInt(10)
< 10 - reference.getTagCompound().getCompoundTag("InfiTool").getInteger("Unbreaking")) {
this.consumeAmmo(1, stack);
}
}
}
}
protected abstract Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy,
@@ -199,8 +199,12 @@ public abstract class ProjectileWeapon extends ToolCore implements IBattlegearWe
// use up ammo
if (!player.capabilities.isCreativeMode) {
if (ammo.getItem() instanceof IAmmo) ((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
else player.inventory.consumeInventoryItem(ammo.getItem());
if (ammo.getItem() instanceof IAmmo) {
if (ammo.hasTagCompound()) {
int ammoReinforced = ammo.getTagCompound().getCompoundTag("InfiTool").getInteger("Unbreaking");
if (random.nextInt(10) < 10 - ammoReinforced) ((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
} else player.inventory.consumeInventoryItem(ammo.getItem());
}
}
// FIREEEEEEE
@@ -145,8 +145,12 @@ public class Crossbow extends ProjectileWeapon {
tags.setBoolean("Loaded", true);
// remove loaded item
if (ammo.getItem() instanceof IAmmo) ((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
else {
if (ammo.getItem() instanceof IAmmo) {
if (ammo.hasTagCompound()) {
int ammoReinforced = ammo.getTagCompound().getCompoundTag("InfiTool").getInteger("Unbreaking");
if (random.nextInt(10) < 10 - ammoReinforced) ((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
}
} else {
player.inventory.consumeInventoryItem(ammo.getItem());
}