PaperMC/patches/server/0425-Add-ignore-discounts-API.patch

151 lines
9.4 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Mon, 9 Nov 2020 20:44:51 +0100
Subject: [PATCH] Add ignore discounts API
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
2024-06-13 22:57:13 +02:00
index e23674dd5db3c429efd3b7c71fe36b420494c03a..9d5a5a7fff7f75871e167f83edb0e9d5348748d7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
2024-06-13 22:57:13 +02:00
@@ -493,6 +493,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
while (iterator.hasNext()) {
MerchantOffer merchantrecipe = (MerchantOffer) iterator.next();
+ if (merchantrecipe.ignoreDiscounts) continue; // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
merchantrecipe.addToSpecialPriceDiff(-Mth.floor((float) i * merchantrecipe.getPriceMultiplier()));
}
2024-06-13 22:57:13 +02:00
@@ -505,6 +506,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
while (iterator1.hasNext()) {
MerchantOffer merchantrecipe1 = (MerchantOffer) iterator1.next();
+ if (merchantrecipe1.ignoreDiscounts) continue; // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
double d0 = 0.3D + 0.0625D * (double) j;
int k = (int) Math.floor(d0 * (double) merchantrecipe1.getBaseCostA().getCount());
diff --git a/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java b/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
2024-04-26 06:27:19 +02:00
index 89982d25f60c8b60ba91e559ef88278f338fe215..0efc8d997b34302c3e0a5d7ec73a11a940dbeefe 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
+++ b/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java
2024-04-24 15:46:45 +02:00
@@ -33,6 +33,10 @@ public class MerchantOffer {
return merchantrecipe.priceMultiplier;
}), Codec.INT.lenientOptionalFieldOf("xp", 1).forGetter((merchantrecipe) -> {
return merchantrecipe.xp;
+ // Paper start
+ }), Codec.BOOL.lenientOptionalFieldOf("Paper.IgnoreDiscounts", false).forGetter((merchantrecipe) -> {
+ return merchantrecipe.ignoreDiscounts;
+ // Paper end
})).apply(instance, MerchantOffer::new);
});
public static final StreamCodec<RegistryFriendlyByteBuf, MerchantOffer> STREAM_CODEC = StreamCodec.of(MerchantOffer::writeToStream, MerchantOffer::createFromStream);
@@ -46,6 +50,7 @@ public class MerchantOffer {
2022-06-08 08:25:32 +02:00
public int demand;
2021-06-11 14:02:28 +02:00
public float priceMultiplier;
public int xp;
+ public boolean ignoreDiscounts; // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private CraftMerchantRecipe bukkitHandle;
2024-04-26 06:27:19 +02:00
@@ -53,13 +58,14 @@ public class MerchantOffer {
return (this.bukkitHandle == null) ? this.bukkitHandle = new CraftMerchantRecipe(this) : this.bukkitHandle;
}
- public MerchantOffer(ItemCost baseCostA, Optional<ItemCost> costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) {
+ public MerchantOffer(ItemCost baseCostA, Optional<ItemCost> costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, final boolean ignoreDiscounts, CraftMerchantRecipe bukkit) { // Paper
this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand);
+ this.ignoreDiscounts = ignoreDiscounts; // Paper
this.bukkitHandle = bukkit;
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
2024-04-24 15:46:45 +02:00
- private MerchantOffer(ItemCost firstBuyItem, Optional<ItemCost> secondBuyItem, ItemStack sellItem, int uses, int maxUses, boolean rewardingPlayerExperience, int specialPrice, int demandBonus, float priceMultiplier, int merchantExperience) {
2024-04-26 06:27:19 +02:00
+ private MerchantOffer(ItemCost firstBuyItem, Optional<ItemCost> secondBuyItem, ItemStack sellItem, int uses, int maxUses, boolean rewardingPlayerExperience, int specialPrice, int demandBonus, float priceMultiplier, int merchantExperience, final boolean ignoreDiscounts) { // Paper
2024-04-24 15:46:45 +02:00
this.baseCostA = firstBuyItem;
this.costB = secondBuyItem;
this.result = sellItem;
2024-04-26 06:27:19 +02:00
@@ -70,6 +76,7 @@ public class MerchantOffer {
2024-04-24 15:46:45 +02:00
this.demand = demandBonus;
this.priceMultiplier = priceMultiplier;
this.xp = merchantExperience;
2024-04-26 06:27:19 +02:00
+ this.ignoreDiscounts = ignoreDiscounts; // Paper
2021-06-11 14:02:28 +02:00
}
2024-04-24 15:46:45 +02:00
public MerchantOffer(ItemCost buyItem, ItemStack sellItem, int maxUses, int merchantExperience, float priceMultiplier) {
2024-04-26 06:27:19 +02:00
@@ -85,11 +92,11 @@ public class MerchantOffer {
2021-06-11 14:02:28 +02:00
}
2024-04-24 15:46:45 +02:00
public MerchantOffer(ItemCost firstBuyItem, Optional<ItemCost> secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier, int demandBonus) {
- this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, true, 0, demandBonus, priceMultiplier, merchantExperience);
+ this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, true, 0, demandBonus, priceMultiplier, merchantExperience, false); // Paper
2021-06-11 14:02:28 +02:00
}
2024-04-24 15:46:45 +02:00
private MerchantOffer(MerchantOffer offer) {
- this(offer.baseCostA, offer.costB, offer.result.copy(), offer.uses, offer.maxUses, offer.rewardExp, offer.specialPriceDiff, offer.demand, offer.priceMultiplier, offer.xp);
+ this(offer.baseCostA, offer.costB, offer.result.copy(), offer.uses, offer.maxUses, offer.rewardExp, offer.specialPriceDiff, offer.demand, offer.priceMultiplier, offer.xp, offer.ignoreDiscounts); // Paper
2021-06-11 14:02:28 +02:00
}
2024-04-24 15:46:45 +02:00
public ItemStack getBaseCostA() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11405) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
2024-09-15 21:39:53 +02:00
index 86c5bc01d5b87b4301fb83d55cf3046985c45d0f..c9e23a71a35214c363318c48d38c49b695d1ffd4 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
2024-04-24 15:46:45 +02:00
@@ -22,11 +22,19 @@ public class CraftMerchantRecipe extends MerchantRecipe {
2021-06-11 14:02:28 +02:00
@Deprecated
2021-06-11 14:02:28 +02:00
public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier) {
- this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0);
2021-06-11 14:02:28 +02:00
+ // Paper start - add ignoreDiscounts param
+ this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0, false);
2021-06-11 14:02:28 +02:00
+ }
+ public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier, boolean ignoreDiscounts) {
+ this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0, ignoreDiscounts);
}
public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier, int demand, int specialPrice) {
- super(result, uses, maxUses, experienceReward, experience, priceMultiplier, demand, specialPrice);
+ this(result, uses, maxUses, experienceReward, experience, priceMultiplier, demand, specialPrice, false);
+ }
+ public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier, int demand, int specialPrice, boolean ignoreDiscounts) {
+ super(result, uses, maxUses, experienceReward, experience, priceMultiplier, demand, specialPrice, ignoreDiscounts);
2021-06-11 14:02:28 +02:00
+ // Paper end
this.handle = new net.minecraft.world.item.trading.MerchantOffer(
2024-04-24 15:46:45 +02:00
new ItemCost(Items.AIR),
Optional.empty(),
@@ -36,6 +44,7 @@ public class CraftMerchantRecipe extends MerchantRecipe {
2021-06-11 14:02:28 +02:00
experience,
priceMultiplier,
demand,
2021-06-11 14:02:28 +02:00
+ ignoreDiscounts, // Paper - add ignoreDiscounts param
this
);
this.setSpecialPrice(specialPrice);
2024-04-24 15:46:45 +02:00
@@ -112,6 +121,18 @@ public class CraftMerchantRecipe extends MerchantRecipe {
2023-10-27 01:34:58 +02:00
this.handle.priceMultiplier = priceMultiplier;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public boolean shouldIgnoreDiscounts() {
+ return this.handle.ignoreDiscounts;
+ }
+
+ @Override
+ public void setIgnoreDiscounts(boolean ignoreDiscounts) {
+ this.handle.ignoreDiscounts = ignoreDiscounts;
+ }
+ // Paper end
+
public net.minecraft.world.item.trading.MerchantOffer toMinecraft() {
2023-10-27 01:34:58 +02:00
List<ItemStack> ingredients = this.getIngredients();
2021-06-11 14:02:28 +02:00
Preconditions.checkState(!ingredients.isEmpty(), "No offered ingredients");
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11405) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
2024-09-15 21:39:53 +02:00
@@ -130,7 +151,7 @@ public class CraftMerchantRecipe extends MerchantRecipe {
2021-06-11 14:02:28 +02:00
if (recipe instanceof CraftMerchantRecipe) {
return (CraftMerchantRecipe) recipe;
} else {
- CraftMerchantRecipe craft = new CraftMerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward(), recipe.getVillagerExperience(), recipe.getPriceMultiplier(), recipe.getDemand(), recipe.getSpecialPrice());
+ CraftMerchantRecipe craft = new CraftMerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward(), recipe.getVillagerExperience(), recipe.getPriceMultiplier(), recipe.getDemand(), recipe.getSpecialPrice(), recipe.shouldIgnoreDiscounts()); // Paper - shouldIgnoreDiscounts
2021-06-11 14:02:28 +02:00
craft.setIngredients(recipe.getIngredients());
return craft;