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-01-23 15:43:48 +01:00
index bfd156acbae31619234fffb1804726090802fbae..3653193effdecd969b5ac159b6d5ce633451d706 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-01-23 15:43:48 +01:00
@@ -490,6 +490,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()));
}
2024-01-23 15:43:48 +01:00
@@ -502,6 +503,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-01-21 19:37:09 +01:00
index 7da5c4a45f8fd46fedd4386e0faac57445475e3a..02feea12c998f37098b72becf6bfaf6b27d155de 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
@@ -19,6 +19,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;
2021-12-20 23:46:51 +01:00
@@ -31,7 +32,15 @@ public class MerchantOffer {
2021-06-11 14:02:28 +02:00
}
2021-12-20 23:46:51 +01:00
public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) {
- this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand);
2024-01-20 12:50:16 +01:00
+ // Paper start - Add ignore discounts API
2021-12-20 23:46:51 +01:00
+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand, false, bukkit);
2021-06-11 14:02:28 +02:00
+ }
+ public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, boolean ignoreDiscounts, CraftMerchantRecipe bukkit) {
2021-12-20 23:46:51 +01:00
+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, 0, ignoreDiscounts, bukkit);
+ }
+ public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, int demand, boolean ignoreDiscounts, CraftMerchantRecipe bukkit) {
+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand, ignoreDiscounts);
2024-01-20 12:50:16 +01:00
+ // Paper end - Add ignore discounts API
2021-06-11 14:02:28 +02:00
this.bukkitHandle = bukkit;
}
// CraftBukkit end
2021-12-20 23:46:51 +01:00
@@ -63,6 +72,7 @@ public class MerchantOffer {
2021-06-11 14:02:28 +02:00
2021-06-14 18:58:00 +02:00
this.specialPriceDiff = nbt.getInt("specialPrice");
this.demand = nbt.getInt("demand");
2024-01-20 12:50:16 +01:00
+ this.ignoreDiscounts = nbt.getBoolean("Paper.IgnoreDiscounts"); // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
}
2021-06-14 18:58:00 +02:00
public MerchantOffer(ItemStack buyItem, ItemStack sellItem, int maxUses, int merchantExperience, float priceMultiplier) {
2021-12-20 23:46:51 +01:00
@@ -74,10 +84,19 @@ public class MerchantOffer {
2021-06-11 14:02:28 +02:00
}
2021-06-14 18:58:00 +02:00
public MerchantOffer(ItemStack firstBuyItem, ItemStack secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier) {
- this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, merchantExperience, priceMultiplier, 0);
2024-01-20 12:50:16 +01:00
+ // Paper start - Add ignore discounts API
2021-06-14 18:58:00 +02:00
+ this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, merchantExperience, priceMultiplier, false);
2021-06-11 14:02:28 +02:00
+ }
2021-06-14 18:58:00 +02:00
+ public MerchantOffer(ItemStack firstBuyItem, ItemStack secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier, boolean ignoreDiscounts) {
+ this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, merchantExperience, priceMultiplier, 0, ignoreDiscounts);
2021-06-11 14:02:28 +02:00
}
2021-06-14 18:58:00 +02:00
public MerchantOffer(ItemStack firstBuyItem, ItemStack secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier, int demandBonus) {
+ this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, merchantExperience, priceMultiplier, demandBonus, false);
2021-06-11 14:02:28 +02:00
+ }
2021-06-14 18:58:00 +02:00
+ public MerchantOffer(ItemStack firstBuyItem, ItemStack secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier, int demandBonus, boolean ignoreDiscounts) {
2021-06-11 14:02:28 +02:00
+ this.ignoreDiscounts = ignoreDiscounts;
2024-01-20 12:50:16 +01:00
+ // Paper end - Add ignore discounts API
2021-06-11 14:02:28 +02:00
this.rewardExp = true;
this.xp = 1;
2021-06-14 18:58:00 +02:00
this.baseCostA = firstBuyItem;
2023-09-22 06:40:51 +02:00
@@ -210,6 +229,7 @@ public class MerchantOffer {
2021-06-11 14:02:28 +02:00
nbttagcompound.putFloat("priceMultiplier", this.priceMultiplier);
nbttagcompound.putInt("specialPrice", this.specialPriceDiff);
nbttagcompound.putInt("demand", this.demand);
2024-01-20 12:50:16 +01:00
+ nbttagcompound.putBoolean("Paper.IgnoreDiscounts", this.ignoreDiscounts); // Paper - Add ignore discounts API
2021-06-11 14:02:28 +02:00
return nbttagcompound;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
2023-10-27 01:34:58 +02:00
index c015b34d2b13a759783da7c0c06dd0563d35fc88..5741a233fb1dd8ad0f83a09b44476a4b88e6aa16 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
2021-12-20 23:46:51 +01:00
@@ -18,11 +18,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(
net.minecraft.world.item.ItemStack.EMPTY,
net.minecraft.world.item.ItemStack.EMPTY,
2021-12-20 23:46:51 +01:00
@@ -32,6 +40,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);
@@ -108,6 +117,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");
2021-12-20 23:46:51 +01:00
@@ -122,7 +143,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;