mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 19:52:55 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
143 lines
8 KiB
Diff
143 lines
8 KiB
Diff
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
|
|
index e9912551e6a19d6ad3b20fad1b716577b9d28f99..415fa3591add1f1ab22dd5866e110dbfccd0ec93 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
|
|
@@ -459,6 +459,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
|
|
while (iterator.hasNext()) {
|
|
MerchantOffer merchantrecipe = (MerchantOffer) iterator.next();
|
|
+ if (merchantrecipe.ignoreDiscounts) continue; // Paper
|
|
|
|
// CraftBukkit start
|
|
int bonus = -Mth.floor((float) i * merchantrecipe.getPriceMultiplier());
|
|
@@ -478,6 +479,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
|
|
while (iterator1.hasNext()) {
|
|
MerchantOffer merchantrecipe1 = (MerchantOffer) iterator1.next();
|
|
+ if (merchantrecipe1.ignoreDiscounts) continue; // Paper
|
|
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
|
|
index fa74813e0fe76612023830b2fc41d41aa0b4f10e..25a0f180967911d5916eb71334a94baec84eafbf 100644
|
|
--- 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 {
|
|
private int demand;
|
|
public float priceMultiplier;
|
|
public int xp;
|
|
+ public boolean ignoreDiscounts; // Paper
|
|
// CraftBukkit start
|
|
private CraftMerchantRecipe bukkitHandle;
|
|
|
|
@@ -27,7 +28,12 @@ public class MerchantOffer {
|
|
}
|
|
|
|
public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, CraftMerchantRecipe bukkit) {
|
|
- this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier);
|
|
+ // Paper start - add ignoreDiscounts param
|
|
+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, false, bukkit);
|
|
+ }
|
|
+ public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, boolean ignoreDiscounts, CraftMerchantRecipe bukkit) {
|
|
+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, ignoreDiscounts);
|
|
+ // Paper end
|
|
this.bukkitHandle = bukkit;
|
|
}
|
|
// CraftBukkit end
|
|
@@ -59,6 +65,7 @@ public class MerchantOffer {
|
|
|
|
this.specialPriceDiff = nbttagcompound.getInt("specialPrice");
|
|
this.demand = nbttagcompound.getInt("demand");
|
|
+ this.ignoreDiscounts = nbttagcompound.getBoolean("Paper.IgnoreDiscounts"); // Paper
|
|
}
|
|
|
|
public MerchantOffer(ItemStack buyItem, ItemStack sellItem, int maxUses, int rewardedExp, float priceMultiplier) {
|
|
@@ -70,10 +77,19 @@ public class MerchantOffer {
|
|
}
|
|
|
|
public MerchantOffer(ItemStack firstBuyItem, ItemStack secondBuyItem, ItemStack sellItem, int uses, int maxUses, int rewardedExp, float priceMultiplier) {
|
|
- this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, rewardedExp, priceMultiplier, 0);
|
|
+ // Paper start - add ignoreDiscounts param
|
|
+ this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, rewardedExp, priceMultiplier, false);
|
|
+ }
|
|
+ public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int i, int j, int k, float f, boolean ignoreDiscounts) {
|
|
+ this(itemstack, itemstack1, itemstack2, i, j, k, f, 0, ignoreDiscounts);
|
|
}
|
|
|
|
public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int i, int j, int k, float f, int l) {
|
|
+ this(itemstack, itemstack1, itemstack2, i, j, k, f, l, false);
|
|
+ }
|
|
+ public MerchantOffer(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int i, int j, int k, float f, int l, boolean ignoreDiscounts) {
|
|
+ this.ignoreDiscounts = ignoreDiscounts;
|
|
+ // Paper end
|
|
this.rewardExp = true;
|
|
this.xp = 1;
|
|
this.baseCostA = itemstack;
|
|
@@ -189,6 +205,7 @@ public class MerchantOffer {
|
|
nbttagcompound.putFloat("priceMultiplier", this.priceMultiplier);
|
|
nbttagcompound.putInt("specialPrice", this.specialPriceDiff);
|
|
nbttagcompound.putInt("demand", this.demand);
|
|
+ nbttagcompound.putBoolean("Paper.IgnoreDiscounts", this.ignoreDiscounts); // Paper
|
|
return nbttagcompound;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
|
|
index 212f9c7f3e73ffedf27b94abeac957b7d866a086..a6c8588f10c4c109833aea6a8b02c9048b6d9ea4 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java
|
|
@@ -17,7 +17,12 @@ public class CraftMerchantRecipe extends MerchantRecipe {
|
|
}
|
|
|
|
public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier) {
|
|
- super(result, uses, maxUses, experienceReward, experience, priceMultiplier);
|
|
+ // Paper start - add ignoreDiscounts param
|
|
+ this(result, uses, maxUses, experienceReward, experience, priceMultiplier, false);
|
|
+ }
|
|
+ public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier, boolean ignoreDiscounts) {
|
|
+ super(result, uses, maxUses, experienceReward, experience, priceMultiplier, ignoreDiscounts);
|
|
+ // Paper end
|
|
this.handle = new net.minecraft.world.item.trading.MerchantOffer(
|
|
net.minecraft.world.item.ItemStack.EMPTY,
|
|
net.minecraft.world.item.ItemStack.EMPTY,
|
|
@@ -26,6 +31,7 @@ public class CraftMerchantRecipe extends MerchantRecipe {
|
|
maxUses,
|
|
experience,
|
|
priceMultiplier,
|
|
+ ignoreDiscounts, // Paper - add ignoreDiscounts param
|
|
this
|
|
);
|
|
this.setExperienceReward(experienceReward);
|
|
@@ -81,6 +87,18 @@ public class CraftMerchantRecipe extends MerchantRecipe {
|
|
handle.priceMultiplier = priceMultiplier;
|
|
}
|
|
|
|
+ // 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() {
|
|
List<ItemStack> ingredients = getIngredients();
|
|
Preconditions.checkState(!ingredients.isEmpty(), "No offered ingredients");
|
|
@@ -95,7 +113,7 @@ public class CraftMerchantRecipe extends MerchantRecipe {
|
|
if (recipe instanceof CraftMerchantRecipe) {
|
|
return (CraftMerchantRecipe) recipe;
|
|
} else {
|
|
- CraftMerchantRecipe craft = new CraftMerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward(), recipe.getVillagerExperience(), recipe.getPriceMultiplier());
|
|
+ CraftMerchantRecipe craft = new CraftMerchantRecipe(recipe.getResult(), recipe.getUses(), recipe.getMaxUses(), recipe.hasExperienceReward(), recipe.getVillagerExperience(), recipe.getPriceMultiplier(), recipe.shouldIgnoreDiscounts()); // Paper - shouldIgnoreDiscounts
|
|
craft.setIngredients(recipe.getIngredients());
|
|
|
|
return craft;
|