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-04-24 15:46:45 +02:00
index 4d7f95d2bd415bacccee145bfc47f2b480530c11..4d3a04e1d7910c4e71ac9a1cebb58e482958671a 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -491,6 +491,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
while (iterator.hasNext()) {
MerchantOffer merchantrecipe = (MerchantOffer) iterator.next();
2024-01-20 12:50:16 +01:00
+ if (merchantrecipe.ignoreDiscounts) continue; // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
2022-01-01 04:05:42 +01:00
merchantrecipe.addToSpecialPriceDiff(-Mth.floor((float) i * merchantrecipe.getPriceMultiplier()));
}
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -503,6 +504,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
2021-06-11 14:02:28 +02:00
while (iterator1.hasNext()) {
MerchantOffer merchantrecipe1 = (MerchantOffer) iterator1.next();
2024-01-20 12:50:16 +01:00
+ 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-24 15:46:45 +02:00
index 89982d25f60c8b60ba91e559ef88278f338fe215..bffa088b13312d525efaab3d7988a08953c4d9c3 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;
2024-01-20 12:50:16 +01:00
+ public boolean ignoreDiscounts; // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
// CraftBukkit start
private CraftMerchantRecipe bukkitHandle;
2024-04-24 15:46:45 +02:00
@@ -59,7 +64,7 @@ public class MerchantOffer {
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) {
+ private MerchantOffer(ItemCost firstBuyItem, Optional<ItemCost> secondBuyItem, ItemStack sellItem, int uses, int maxUses, boolean rewardingPlayerExperience, int specialPrice, int demandBonus, float priceMultiplier, int merchantExperience, boolean ignoreDiscounts) { // Paper
this.baseCostA = firstBuyItem;
this.costB = secondBuyItem;
this.result = sellItem;
@@ -70,6 +75,7 @@ public class MerchantOffer {
this.demand = demandBonus;
this.priceMultiplier = priceMultiplier;
this.xp = merchantExperience;
+ this.ignoreDiscounts = ignoreDiscounts;
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) {
@@ -85,11 +91,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
2024-04-24 15:46:45 +02:00
index 3bf9b5c016fa638fd0377d2a031a7359430b79ce..a18088125254178d362fdd283bff704a9ccdd0a7 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
2022-10-02 09:56:36 +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) {
2021-12-20 23:46:51 +01:00
- this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0);
2021-06-11 14:02:28 +02:00
+ // Paper start - add ignoreDiscounts param
2021-12-20 23:46:51 +01:00
+ 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) {
2021-12-20 23:46:51 +01:00
+ 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,
2021-12-20 23:46:51 +01:00
demand,
2021-06-11 14:02:28 +02:00
+ ignoreDiscounts, // Paper - add ignoreDiscounts param
this
);
2021-12-20 23:46:51 +01:00
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");
2024-04-24 15:46:45 +02:00
@@ -128,7 +149,7 @@ public class CraftMerchantRecipe extends MerchantRecipe {
2021-06-11 14:02:28 +02:00
if (recipe instanceof CraftMerchantRecipe) {
return (CraftMerchantRecipe) recipe;
} else {
2022-10-02 09:56:36 +02:00
- 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;