From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: granny Date: Mon, 16 Oct 2023 21:54:47 -0700 Subject: [PATCH] config for turning bundles into functional quivers bugs: [ ] - only draws bow if a block is not selected [ ] - will not draw bow if the player is holding shift while looking at an interactable block. diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java index 20c3d3c9d2150574e9b4761dc1bda11cee04862f..a169aea23e8e6d51285a8be624975c7a2ec61806 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java +++ b/src/main/java/net/minecraft/world/entity/player/Player.java @@ -2367,6 +2367,11 @@ public abstract class Player extends LivingEntity { @Override public ItemStack getProjectile(ItemStack stack) { + // Purpur start + return getProjectile(stack, false); + } + public ItemStack getProjectile(ItemStack stack, boolean useBundleItemStack) { + // Purpur end if (!(stack.getItem() instanceof ProjectileWeaponItem)) { return ItemStack.EMPTY; } else { @@ -2381,6 +2386,35 @@ public abstract class Player extends LivingEntity { for (int i = 0; i < this.inventory.getContainerSize(); ++i) { ItemStack itemstack2 = this.inventory.getItem(i); + // Purpur start + if ((this.level().purpurConfig.bowUseBundleAsQuiver || this.level().purpurConfig.crossbowUseBundleAsQuiver) && itemstack2.getItem() instanceof net.minecraft.world.item.BundleItem) { + CompoundTag compoundTag = itemstack2.getOrCreateTag(); + if (!compoundTag.contains("Items")) continue; + + Optional temp = net.minecraft.world.item.BundleItem.getContents(itemstack2).filter(predicate).findFirst(); + + if (temp.isEmpty()) continue; + + ItemStack itemStackTemp = temp.get(); + ListTag listTag = compoundTag.getList("Items", 10); + Optional optional = net.minecraft.world.item.BundleItem.getMatchingItem(itemStackTemp, listTag); + if (optional.isPresent()) { + CompoundTag compoundTag2 = optional.get(); + ItemStack storedItemStack = ItemStack.of(compoundTag2); + if (useBundleItemStack) { + storedItemStack.shrink(1); + storedItemStack.save(compoundTag2); + listTag.remove(compoundTag2); + listTag.add(0, compoundTag2); + } + storedItemStack.setCount(1); + return storedItemStack; + } + + continue; + } + // Purpur end + if (predicate.test(itemstack2)) { return itemstack2; } diff --git a/src/main/java/net/minecraft/world/item/BowItem.java b/src/main/java/net/minecraft/world/item/BowItem.java index d45a2f49c82d00801578c34e5f5277fc5e82be87..c645e4e131257403232b98d2bc43e59ba38ff8c1 100644 --- a/src/main/java/net/minecraft/world/item/BowItem.java +++ b/src/main/java/net/minecraft/world/item/BowItem.java @@ -27,7 +27,7 @@ public class BowItem extends ProjectileWeaponItem implements Vanishable { if (user instanceof Player) { Player entityhuman = (Player) user; boolean flag = entityhuman.getAbilities().instabuild || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0; - ItemStack itemstack1 = entityhuman.getProjectile(stack); + ItemStack itemstack1 = entityhuman.getProjectile(stack, !flag && world.purpurConfig.bowUseBundleAsQuiver); // Purpur if (!itemstack1.isEmpty() || flag) { if (itemstack1.isEmpty()) { diff --git a/src/main/java/net/minecraft/world/item/BundleItem.java b/src/main/java/net/minecraft/world/item/BundleItem.java index ac0bc87f60c4e1562d1301522183e449558d42f8..518623c93bcb0ce747f235b5ba15510a135456d3 100644 --- a/src/main/java/net/minecraft/world/item/BundleItem.java +++ b/src/main/java/net/minecraft/world/item/BundleItem.java @@ -147,7 +147,7 @@ public class BundleItem extends Item { } } - private static Optional getMatchingItem(ItemStack stack, ListTag items) { + public static Optional getMatchingItem(ItemStack stack, ListTag items) { // Purpur - private -> public return stack.is(Items.BUNDLE) ? Optional.empty() : items.stream().filter(CompoundTag.class::isInstance).map(CompoundTag.class::cast).filter((item) -> { return ItemStack.isSameItemSameTags(ItemStack.of(item), stack); }).findFirst(); @@ -216,7 +216,7 @@ public class BundleItem extends Item { } } - private static Stream getContents(ItemStack stack) { + public static Stream getContents(ItemStack stack) { // Purpur - private -> public CompoundTag compoundTag = stack.getTag(); if (compoundTag == null) { return Stream.empty(); diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java index 2c51a73ebfd05af21b0f5d731fc9f1df77fed1a1..5314725e75d6353304d963c372ecc34611ca0274 100644 --- a/src/main/java/net/minecraft/world/item/CrossbowItem.java +++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java @@ -115,7 +115,7 @@ public class CrossbowItem extends ProjectileWeaponItem implements Vanishable { int i = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.MULTISHOT, crossbow); int j = i == 0 ? 1 : 3; boolean flag = !consume || shooter instanceof Player && ((Player) shooter).getAbilities().instabuild || (org.purpurmc.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, crossbow) > 0); // Paper - add consume // Purpur - ItemStack itemstack1 = shooter.getProjectile(crossbow); + ItemStack itemstack1 = shooter.level().purpurConfig.crossbowUseBundleAsQuiver && shooter instanceof Player player ? player.getProjectile(crossbow, !flag) : shooter.getProjectile(crossbow); // Purpur ItemStack itemstack2 = itemstack1.copy(); for (int k = 0; k < j; ++k) { diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java index 64e172e6cbfb8134c2b36bce8279e1ef44085257..ae1cc8bd2347f57c84d2e4b0a8f1c070346f729d 100644 --- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -251,6 +251,8 @@ public class PurpurWorldConfig { public boolean snowballExtinguishesFire = false; public boolean snowballExtinguishesCandles = false; public boolean snowballExtinguishesCampfires = false; + public boolean bowUseBundleAsQuiver = false; + public boolean crossbowUseBundleAsQuiver = false; private void itemSettings() { itemImmuneToCactus.clear(); getList("gameplay-mechanics.item.immune.cactus", new ArrayList<>()).forEach(key -> { @@ -302,6 +304,8 @@ public class PurpurWorldConfig { snowballExtinguishesFire = getBoolean("gameplay-mechanics.item.snowball.extinguish.fire", snowballExtinguishesFire); snowballExtinguishesCandles = getBoolean("gameplay-mechanics.item.snowball.extinguish.candles", snowballExtinguishesCandles); snowballExtinguishesCampfires = getBoolean("gameplay-mechanics.item.snowball.extinguish.campfires", snowballExtinguishesCampfires); + bowUseBundleAsQuiver = getBoolean("gameplay-mechanics.item.bow.use-bundle-as-quiver", bowUseBundleAsQuiver); + crossbowUseBundleAsQuiver = getBoolean("gameplay-mechanics.item.crossbow.use-bundle-as-quiver", crossbowUseBundleAsQuiver); } public double minecartMaxSpeed = 0.4D;