From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/npc/Villager.java +++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java @@ -0,0 +0,0 @@ public class Villager extends AbstractVillager implements ReputationEventHandler while (iterator.hasNext()) { MerchantOffer merchantrecipe = (MerchantOffer) iterator.next(); + if (merchantrecipe.ignoreDiscounts) continue; // Paper merchantrecipe.addToSpecialPriceDiff(-Mth.floor((float) i * merchantrecipe.getPriceMultiplier())); } @@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java +++ b/src/main/java/net/minecraft/world/item/trading/MerchantOffer.java @@ -0,0 +0,0 @@ public class MerchantOffer { public int demand; public float priceMultiplier; public int xp; + public boolean ignoreDiscounts; // Paper // CraftBukkit start private CraftMerchantRecipe bukkitHandle; @@ -0,0 +0,0 @@ public class MerchantOffer { } 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); + // Paper start - add ignoreDiscounts param + this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand, 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, 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); + // Paper end this.bukkitHandle = bukkit; } // CraftBukkit end @@ -0,0 +0,0 @@ public class MerchantOffer { this.specialPriceDiff = nbt.getInt("specialPrice"); this.demand = nbt.getInt("demand"); + this.ignoreDiscounts = nbt.getBoolean("Paper.IgnoreDiscounts"); // Paper } public MerchantOffer(ItemStack buyItem, ItemStack sellItem, int maxUses, int merchantExperience, float priceMultiplier) { @@ -0,0 +0,0 @@ public class MerchantOffer { } 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); + // Paper start - add ignoreDiscounts param + this(firstBuyItem, secondBuyItem, sellItem, uses, maxUses, merchantExperience, priceMultiplier, false); + } + 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); } 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); + } + public MerchantOffer(ItemStack firstBuyItem, ItemStack secondBuyItem, ItemStack sellItem, int uses, int maxUses, int merchantExperience, float priceMultiplier, int demandBonus, boolean ignoreDiscounts) { + this.ignoreDiscounts = ignoreDiscounts; + // Paper end this.rewardExp = true; this.xp = 1; this.baseCostA = firstBuyItem; @@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java @@ -0,0 +0,0 @@ public class CraftMerchantRecipe extends MerchantRecipe { @Deprecated public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier) { - this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0); + // Paper start - add ignoreDiscounts param + this(result, uses, maxUses, experienceReward, experience, priceMultiplier, 0, 0, false); + } + 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); + // Paper end this.handle = new net.minecraft.world.item.trading.MerchantOffer( net.minecraft.world.item.ItemStack.EMPTY, net.minecraft.world.item.ItemStack.EMPTY, @@ -0,0 +0,0 @@ public class CraftMerchantRecipe extends MerchantRecipe { experience, priceMultiplier, demand, + ignoreDiscounts, // Paper - add ignoreDiscounts param this ); this.setSpecialPrice(specialPrice); @@ -0,0 +0,0 @@ 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 ingredients = getIngredients(); Preconditions.checkState(!ingredients.isEmpty(), "No offered ingredients"); @@ -0,0 +0,0 @@ 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(), 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 craft.setIngredients(recipe.getIngredients()); return craft;