Skip to content

Commit

Permalink
fix bows shooting infinite arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed May 8, 2024
1 parent 3239393 commit f9258cd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
41 changes: 30 additions & 11 deletions patches/server/0092-Infinity-bow-settings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,46 @@ Subject: [PATCH] Infinity bow settings


diff --git a/src/main/java/net/minecraft/world/item/BowItem.java b/src/main/java/net/minecraft/world/item/BowItem.java
index 5ca843df5b4caa668953e5e36a9b20fabeb35046..4ae6b98b6a0d41e949b055f0678200a672a1df38 100644
index 5ca843df5b4caa668953e5e36a9b20fabeb35046..abe6da2d70e8080461f70014757c1e1b5878bbf7 100644
--- a/src/main/java/net/minecraft/world/item/BowItem.java
+++ b/src/main/java/net/minecraft/world/item/BowItem.java
@@ -29,7 +29,7 @@ public class BowItem extends ProjectileWeaponItem {
int i = this.getUseDuration(stack) - remainingUseTicks;
float f = getPowerForTime(i);
if (!((double)f < 0.1)) {
- List<ItemStack> list = draw(stack, itemStack, player);
+ List<ItemStack> list = draw(stack, itemStack, player, !((itemStack.is(Items.ARROW) && world.purpurConfig.infinityWorksWithNormalArrows) || (itemStack.is(Items.TIPPED_ARROW) && world.purpurConfig.infinityWorksWithTippedArrows) || (itemStack.is(Items.SPECTRAL_ARROW) && world.purpurConfig.infinityWorksWithSpectralArrows)));
if (!world.isClientSide() && !list.isEmpty()) {
this.shoot(world, player, player.getUsedItemHand(), stack, list, f * 3.0F, 1.0F, f == 1.0F, null);
}
@@ -81,7 +81,7 @@ public class BowItem extends ProjectileWeaponItem {
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
ItemStack itemStack = user.getItemInHand(hand);
boolean bl = !user.getProjectile(itemStack).isEmpty();
- if (!user.hasInfiniteMaterials() && !bl) {
+ if (!(world.purpurConfig.infinityWorksWithoutArrows && net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.INFINITY, itemStack) > 0) && !user.hasInfiniteMaterials() && !bl) {
+ if (!(world.purpurConfig.infinityWorksWithoutArrows && net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantments.INFINITY, itemStack) > 0) && !user.hasInfiniteMaterials() && !bl) { // Purpur
return InteractionResultHolder.fail(itemStack);
} else {
user.startUsingItem(hand);
diff --git a/src/main/java/net/minecraft/world/item/ProjectileWeaponItem.java b/src/main/java/net/minecraft/world/item/ProjectileWeaponItem.java
index d27e83c08c45b8514207f26e48ceb1a91ded94be..d6d91de1639a180eb39bb85ac825e992c477d0f9 100644
--- a/src/main/java/net/minecraft/world/item/ProjectileWeaponItem.java
+++ b/src/main/java/net/minecraft/world/item/ProjectileWeaponItem.java
@@ -135,7 +135,13 @@ public abstract class ProjectileWeaponItem extends Item {
}

protected static boolean hasInfiniteArrows(ItemStack weaponStack, ItemStack projectileStack, boolean creative) {
- return creative || projectileStack.is(Items.ARROW) && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY, weaponStack) > 0;
+ // Purpur start
+ return hasInfiniteArrows(weaponStack, projectileStack, creative, null);
+ }
+ protected static boolean hasInfiniteArrows(ItemStack weaponStack, ItemStack projectileStack, boolean creative, @javax.annotation.Nullable Level level) {
+ boolean canBeInfinity = level == null ? projectileStack.is(Items.ARROW) : ((projectileStack.is(Items.ARROW) && level.purpurConfig.infinityWorksWithNormalArrows) || (projectileStack.is(Items.TIPPED_ARROW) && level.purpurConfig.infinityWorksWithTippedArrows) || (projectileStack.is(Items.SPECTRAL_ARROW) && level.purpurConfig.infinityWorksWithSpectralArrows));
+ return creative || canBeInfinity && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY, weaponStack) > 0;
+ // Purpur end
}

protected static List<ItemStack> draw(ItemStack weaponStack, ItemStack projectileStack, LivingEntity shooter) {
@@ -161,7 +167,7 @@ public abstract class ProjectileWeaponItem extends Item {
}

protected static ItemStack useAmmo(ItemStack weaponStack, ItemStack projectileStack, LivingEntity shooter, boolean multishot) {
- boolean flag1 = !multishot && !ProjectileWeaponItem.hasInfiniteArrows(weaponStack, projectileStack, shooter.hasInfiniteMaterials());
+ boolean flag1 = !multishot && !ProjectileWeaponItem.hasInfiniteArrows(weaponStack, projectileStack, shooter.hasInfiniteMaterials(), shooter.level()); // Purpur
ItemStack itemstack2;

if (!flag1) {
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index 636f1a2962ee48a42a644b241569f08e7d57097c..b66182a7b52d16aac78b61cd9c077236a2abbe33 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0150-Projectile-offset-config.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Subject: [PATCH] Projectile offset config


diff --git a/src/main/java/net/minecraft/world/item/BowItem.java b/src/main/java/net/minecraft/world/item/BowItem.java
index 4ae6b98b6a0d41e949b055f0678200a672a1df38..ff39d3614f360918d74b54b817bc227f89d34c9c 100644
index abe6da2d70e8080461f70014757c1e1b5878bbf7..8bca38ec152f9612298bf6b3e10e7e0566ec3b78 100644
--- a/src/main/java/net/minecraft/world/item/BowItem.java
+++ b/src/main/java/net/minecraft/world/item/BowItem.java
@@ -31,7 +31,7 @@ public class BowItem extends ProjectileWeaponItem {
if (!((double)f < 0.1)) {
List<ItemStack> list = draw(stack, itemStack, player, !((itemStack.is(Items.ARROW) && world.purpurConfig.infinityWorksWithNormalArrows) || (itemStack.is(Items.TIPPED_ARROW) && world.purpurConfig.infinityWorksWithTippedArrows) || (itemStack.is(Items.SPECTRAL_ARROW) && world.purpurConfig.infinityWorksWithSpectralArrows)));
List<ItemStack> list = draw(stack, itemStack, player);
if (!world.isClientSide() && !list.isEmpty()) {
- this.shoot(world, player, player.getUsedItemHand(), stack, list, f * 3.0F, 1.0F, f == 1.0F, null);
+ this.shoot(world, player, player.getUsedItemHand(), stack, list, f * 3.0F, (float) world.purpurConfig.bowProjectileOffset, f == 1.0F, null); // Purpur
Expand Down

0 comments on commit f9258cd

Please sign in to comment.