mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 00:47:42 +01:00
fix up patch
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: granny <granny@purpurmc.org>
|
||||
Date: Mon, 16 Oct 2023 21:54:47 -0700
|
||||
Subject: [PATCH] config for turning bundles into functional quivers
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index 53ff232129443ba3242cfc57fc57026bf76d96e8..f5b78ae87457c0d3a550082fdf8640267f413130 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -4495,6 +4495,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
}
|
||||
|
||||
public ItemStack getProjectile(ItemStack stack) {
|
||||
+ // Purpur start
|
||||
+ return getProjectile(stack, false);
|
||||
+ }
|
||||
+ public ItemStack getProjectile(ItemStack stack, boolean useBundleItemStack) {
|
||||
+ // Purpur end
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/monster/Monster.java b/src/main/java/net/minecraft/world/entity/monster/Monster.java
|
||||
index e60e6b3e5ae5a468cfe649ed2222412f3bc8b268..265437318f3db4331d9062d99c980f80a19211c7 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/monster/Monster.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/monster/Monster.java
|
||||
@@ -144,6 +144,12 @@ public abstract class Monster extends PathfinderMob implements Enemy {
|
||||
|
||||
@Override
|
||||
public ItemStack getProjectile(ItemStack stack) {
|
||||
+ // Purpur start
|
||||
+ return getProjectile(stack, false);
|
||||
+ }
|
||||
+ @Override
|
||||
+ public ItemStack getProjectile(ItemStack stack, boolean useBundleItemStack) {
|
||||
+ // Purpur end
|
||||
if (stack.getItem() instanceof ProjectileWeaponItem) {
|
||||
Predicate<ItemStack> predicate = ((ProjectileWeaponItem)stack.getItem()).getSupportedHeldProjectiles();
|
||||
ItemStack itemStack = ProjectileWeaponItem.getHeldProjectile(this, predicate);
|
||||
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 845c4af5d5d38d54de4a1b20fe32bf5dd4776a29..15763ebc6c1ba3ba47d8110cf87fd4869660b2f4 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
@@ -2349,6 +2349,12 @@ public abstract class Player extends LivingEntity {
|
||||
|
||||
@Override
|
||||
public ItemStack getProjectile(ItemStack stack) {
|
||||
+ // Purpur start
|
||||
+ return getProjectile(stack, false);
|
||||
+ }
|
||||
+ @Override
|
||||
+ public ItemStack getProjectile(ItemStack stack, boolean useBundleItemStack) {
|
||||
+ // Purpur end
|
||||
if (!(stack.getItem() instanceof ProjectileWeaponItem)) {
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
@@ -2363,6 +2369,38 @@ 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) {
|
||||
+ net.minecraft.world.item.component.BundleContents bundleContents = itemstack2.get(net.minecraft.core.component.DataComponents.BUNDLE_CONTENTS);
|
||||
+ if (bundleContents == null || bundleContents.isEmpty()) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ Optional<ItemStack> first = bundleContents.itemCopyStream().filter(predicate).findFirst();
|
||||
+
|
||||
+ if (first.isEmpty()) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ ItemStack itemStack = first.get();
|
||||
+ if (useBundleItemStack) {
|
||||
+ net.minecraft.world.item.component.BundleContents.Mutable mutable = new net.minecraft.world.item.component.BundleContents.Mutable(bundleContents);
|
||||
+ ItemStack itemStack2 = mutable.removeOne(itemStack);
|
||||
+ if (itemStack2 == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ itemStack2.shrink(1);
|
||||
+ if (itemStack2.getCount() != 0) {
|
||||
+ mutable.tryInsert(itemStack2);
|
||||
+ }
|
||||
+ itemstack2.set(net.minecraft.core.component.DataComponents.BUNDLE_CONTENTS, mutable.toImmutable());
|
||||
+ }
|
||||
+ itemStack.setCount(1);
|
||||
+ return itemStack;
|
||||
+ }
|
||||
+ // 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 ff39d3614f360918d74b54b817bc227f89d34c9c..4544835f2fe916e81f2932c1c6117bc9c1faa3ae 100644
|
||||
--- a/src/main/java/net/minecraft/world/item/BowItem.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/BowItem.java
|
||||
@@ -24,7 +24,7 @@ public class BowItem extends ProjectileWeaponItem {
|
||||
@Override
|
||||
public void releaseUsing(ItemStack stack, Level world, LivingEntity user, int remainingUseTicks) {
|
||||
if (user instanceof Player player) {
|
||||
- ItemStack itemStack = player.getProjectile(stack);
|
||||
+ ItemStack itemStack = player.getProjectile(stack, true); // Purpur
|
||||
if (!itemStack.isEmpty()) {
|
||||
int i = this.getUseDuration(stack) - remainingUseTicks;
|
||||
float f = getPowerForTime(i);
|
||||
diff --git a/src/main/java/net/minecraft/world/item/CrossbowItem.java b/src/main/java/net/minecraft/world/item/CrossbowItem.java
|
||||
index 78f124f5204e4af9318ca3eeced6b1e3353b210f..40c6076a9cb17ac8120181dab77290bb0131b121 100644
|
||||
--- a/src/main/java/net/minecraft/world/item/CrossbowItem.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/CrossbowItem.java
|
||||
@@ -62,7 +62,7 @@ public class CrossbowItem extends ProjectileWeaponItem {
|
||||
if (chargedProjectiles != null && !chargedProjectiles.isEmpty()) {
|
||||
this.performShooting(world, user, hand, itemStack, getShootingPower(chargedProjectiles), (float) world.purpurConfig.crossbowProjectileOffset, null); // Purpur
|
||||
return InteractionResultHolder.consume(itemStack);
|
||||
- } else if (!user.getProjectile(itemStack).isEmpty()) {
|
||||
+ } else if (!user.getProjectile(itemStack).isEmpty()) { // Purpur
|
||||
this.startSoundPlayed = false;
|
||||
this.midLoadSoundPlayed = false;
|
||||
user.startUsingItem(hand);
|
||||
@@ -107,7 +107,7 @@ public class CrossbowItem extends ProjectileWeaponItem {
|
||||
return CrossbowItem.tryLoadProjectiles(shooter, crossbow, true);
|
||||
}
|
||||
private static boolean tryLoadProjectiles(LivingEntity shooter, ItemStack crossbow, boolean consume) {
|
||||
- List<ItemStack> list = draw(crossbow, shooter.getProjectile(crossbow), shooter, (org.purpurmc.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY, crossbow) > 0) || consume);
|
||||
+ List<ItemStack> list = draw(crossbow, shooter.getProjectile(crossbow, true), shooter, (org.purpurmc.purpur.PurpurConfig.allowCrossbowInfinity && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY, crossbow) > 0) || consume); // Purpur
|
||||
// Paper end - Add EntityLoadCrossbowEvent
|
||||
if (!list.isEmpty()) {
|
||||
crossbow.set(DataComponents.CHARGED_PROJECTILES, ChargedProjectiles.of(list));
|
||||
diff --git a/src/main/java/net/minecraft/world/item/component/BundleContents.java b/src/main/java/net/minecraft/world/item/component/BundleContents.java
|
||||
index 00efca5920cefe60eb26654c2cdc69fb62894924..d4ce443420c9a3e2b7f0a0065f0024c756f70012 100644
|
||||
--- a/src/main/java/net/minecraft/world/item/component/BundleContents.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/component/BundleContents.java
|
||||
@@ -119,7 +119,12 @@ public final class BundleContents implements TooltipComponent {
|
||||
}
|
||||
|
||||
private int findStackIndex(ItemStack stack) {
|
||||
- if (!stack.isStackable()) {
|
||||
+ // Purpur start
|
||||
+ return this.findStackIndex(stack, false);
|
||||
+ }
|
||||
+ private int findStackIndex(ItemStack stack, boolean skipStackableCheck) {
|
||||
+ if (!skipStackableCheck && !stack.isStackable()) {
|
||||
+ // Purpur end
|
||||
return -1;
|
||||
} else {
|
||||
for (int i = 0; i < this.items.size(); i++) {
|
||||
@@ -169,10 +174,19 @@ public final class BundleContents implements TooltipComponent {
|
||||
|
||||
@Nullable
|
||||
public ItemStack removeOne() {
|
||||
+ // Purpur start
|
||||
+ return this.removeOne(null);
|
||||
+ }
|
||||
+ @Nullable
|
||||
+ public ItemStack removeOne(ItemStack itemStack2) {
|
||||
+ // Purpur end
|
||||
if (this.items.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
- ItemStack itemStack = this.items.remove(0).copy();
|
||||
+ // Purpur start
|
||||
+ int stackIndex = itemStack2 != null ? this.findStackIndex(itemStack2, true) : -1;
|
||||
+ ItemStack itemStack = this.items.remove(stackIndex == -1 ? 0 : stackIndex).copy();
|
||||
+ // Purpur end
|
||||
this.weight = this.weight.subtract(BundleContents.getWeight(itemStack).multiplyBy(Fraction.getFraction(itemStack.getCount(), 1)));
|
||||
return itemStack;
|
||||
}
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index d8de8710d9b8cf2ae5c434b2b0b27e76ffbbe4bf..36d1d235c627bd4b9a45c332fca31c83549ccfe6 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -259,6 +259,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 -> {
|
||||
@@ -310,6 +312,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;
|
||||
@@ -1,131 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: granny <granny@purpurmc.org>
|
||||
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<ItemStack> 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<CompoundTag> 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<CompoundTag> getMatchingItem(ItemStack stack, ListTag items) {
|
||||
+ public static Optional<CompoundTag> 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<ItemStack> getContents(ItemStack stack) {
|
||||
+ public static Stream<ItemStack> 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;
|
||||
Reference in New Issue
Block a user