mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
net.minecraft.world.item.trading
This commit is contained in:
parent
2546348b9d
commit
630c815714
3 changed files with 89 additions and 92 deletions
|
@ -1,6 +1,6 @@
|
|||
--- a/net/minecraft/world/item/trading/Merchant.java
|
||||
+++ b/net/minecraft/world/item/trading/Merchant.java
|
||||
@@ -20,6 +20,7 @@
|
||||
@@ -19,6 +_,7 @@
|
||||
|
||||
void overrideOffers(MerchantOffers offers);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
|||
void notifyTrade(MerchantOffer offer);
|
||||
|
||||
void notifyTradeUpdated(ItemStack stack);
|
||||
@@ -54,4 +55,6 @@
|
||||
@@ -50,4 +_,6 @@
|
||||
boolean isClientSide();
|
||||
|
||||
boolean stillValid(Player player);
|
|
@ -0,0 +1,87 @@
|
|||
--- a/net/minecraft/world/item/trading/MerchantOffer.java
|
||||
+++ b/net/minecraft/world/item/trading/MerchantOffer.java
|
||||
@@ -21,6 +_,7 @@
|
||||
Codec.INT.lenientOptionalFieldOf("demand", Integer.valueOf(0)).forGetter(merchantOffer -> merchantOffer.demand),
|
||||
Codec.FLOAT.lenientOptionalFieldOf("priceMultiplier", Float.valueOf(0.0F)).forGetter(merchantOffer -> merchantOffer.priceMultiplier),
|
||||
Codec.INT.lenientOptionalFieldOf("xp", Integer.valueOf(1)).forGetter(merchantOffer -> merchantOffer.xp)
|
||||
+ , Codec.BOOL.lenientOptionalFieldOf("Paper.IgnoreDiscounts", false).forGetter(merchantOffer -> merchantOffer.ignoreDiscounts) // Paper
|
||||
)
|
||||
.apply(instance, MerchantOffer::new)
|
||||
);
|
||||
@@ -37,6 +_,21 @@
|
||||
public int demand;
|
||||
public float priceMultiplier;
|
||||
public int xp;
|
||||
+ public boolean ignoreDiscounts; // Paper - Add ignore discounts API
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ private org.bukkit.craftbukkit.inventory.@org.jspecify.annotations.Nullable CraftMerchantRecipe bukkitHandle;
|
||||
+
|
||||
+ public org.bukkit.craftbukkit.inventory.CraftMerchantRecipe asBukkit() {
|
||||
+ return (this.bukkitHandle == null) ? this.bukkitHandle = new org.bukkit.craftbukkit.inventory.CraftMerchantRecipe(this) : this.bukkitHandle;
|
||||
+ }
|
||||
+
|
||||
+ public MerchantOffer(ItemCost baseCostA, Optional<ItemCost> costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, final boolean ignoreDiscounts, org.bukkit.craftbukkit.inventory.CraftMerchantRecipe bukkit) { // Paper
|
||||
+ this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand);
|
||||
+ this.ignoreDiscounts = ignoreDiscounts; // Paper
|
||||
+ this.bukkitHandle = bukkit;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
private MerchantOffer(
|
||||
ItemCost baseCostA,
|
||||
@@ -49,6 +_,7 @@
|
||||
int demand,
|
||||
float priceMultiplier,
|
||||
int xp
|
||||
+ , final boolean ignoreDiscounts // Paper
|
||||
) {
|
||||
this.baseCostA = baseCostA;
|
||||
this.costB = costB;
|
||||
@@ -60,6 +_,7 @@
|
||||
this.demand = demand;
|
||||
this.priceMultiplier = priceMultiplier;
|
||||
this.xp = xp;
|
||||
+ this.ignoreDiscounts = ignoreDiscounts; // Paper
|
||||
}
|
||||
|
||||
public MerchantOffer(ItemCost baseCostA, ItemStack result, int maxUses, int xp, float priceMultiplier) {
|
||||
@@ -75,7 +_,7 @@
|
||||
}
|
||||
|
||||
public MerchantOffer(ItemCost baseCostA, Optional<ItemCost> costB, ItemStack result, int _uses, int maxUses, int xp, float priceMultiplier, int demand) {
|
||||
- this(baseCostA, costB, result, _uses, maxUses, true, 0, demand, priceMultiplier, xp);
|
||||
+ this(baseCostA, costB, result, _uses, maxUses, true, 0, demand, priceMultiplier, xp, false); // Paper
|
||||
}
|
||||
|
||||
private MerchantOffer(MerchantOffer other) {
|
||||
@@ -90,6 +_,7 @@
|
||||
other.demand,
|
||||
other.priceMultiplier,
|
||||
other.xp
|
||||
+ , other.ignoreDiscounts // Paper
|
||||
);
|
||||
}
|
||||
|
||||
@@ -124,7 +_,7 @@
|
||||
}
|
||||
|
||||
public void updateDemand() {
|
||||
- this.demand = this.demand + this.uses - (this.maxUses - this.uses);
|
||||
+ this.demand = Math.max(0, this.demand + this.uses - (this.maxUses - this.uses)); // Paper - Fix MC-163962
|
||||
}
|
||||
|
||||
public ItemStack assemble() {
|
||||
@@ -205,7 +_,11 @@
|
||||
if (!this.satisfiedBy(playerOfferA, playerOfferB)) {
|
||||
return false;
|
||||
} else {
|
||||
- playerOfferA.shrink(this.getCostA().getCount());
|
||||
+ // CraftBukkit start
|
||||
+ if (!this.getCostA().isEmpty()) {
|
||||
+ playerOfferA.shrink(this.getCostA().getCount());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (!this.getCostB().isEmpty()) {
|
||||
playerOfferB.shrink(this.getCostB().getCount());
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
--- a/net/minecraft/world/item/trading/MerchantOffer.java
|
||||
+++ b/net/minecraft/world/item/trading/MerchantOffer.java
|
||||
@@ -8,6 +8,8 @@
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; // CraftBukkit
|
||||
+
|
||||
public class MerchantOffer {
|
||||
|
||||
public static final Codec<MerchantOffer> CODEC = RecordCodecBuilder.create((instance) -> {
|
||||
@@ -31,6 +33,10 @@
|
||||
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);
|
||||
@@ -44,8 +50,22 @@
|
||||
public int demand;
|
||||
public float priceMultiplier;
|
||||
public int xp;
|
||||
+ public boolean ignoreDiscounts; // Paper - Add ignore discounts API
|
||||
+ // CraftBukkit start
|
||||
+ private CraftMerchantRecipe bukkitHandle;
|
||||
|
||||
- private MerchantOffer(ItemCost firstBuyItem, Optional<ItemCost> secondBuyItem, ItemStack sellItem, int uses, int maxUses, boolean rewardingPlayerExperience, int specialPrice, int demandBonus, float priceMultiplier, int merchantExperience) {
|
||||
+ public CraftMerchantRecipe asBukkit() {
|
||||
+ 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, final boolean ignoreDiscounts, CraftMerchantRecipe bukkit) { // Paper
|
||||
+ this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand);
|
||||
+ this.ignoreDiscounts = ignoreDiscounts; // Paper
|
||||
+ this.bukkitHandle = bukkit;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ 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
|
||||
this.baseCostA = firstBuyItem;
|
||||
this.costB = secondBuyItem;
|
||||
this.result = sellItem;
|
||||
@@ -56,6 +76,7 @@
|
||||
this.demand = demandBonus;
|
||||
this.priceMultiplier = priceMultiplier;
|
||||
this.xp = merchantExperience;
|
||||
+ this.ignoreDiscounts = ignoreDiscounts; // Paper
|
||||
}
|
||||
|
||||
public MerchantOffer(ItemCost buyItem, ItemStack sellItem, int maxUses, int merchantExperience, float priceMultiplier) {
|
||||
@@ -71,11 +92,11 @@
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
public ItemStack getBaseCostA() {
|
||||
@@ -110,7 +131,7 @@
|
||||
}
|
||||
|
||||
public void updateDemand() {
|
||||
- this.demand = this.demand + this.uses - (this.maxUses - this.uses);
|
||||
+ this.demand = Math.max(0, this.demand + this.uses - (this.maxUses - this.uses)); // Paper - Fix MC-163962
|
||||
}
|
||||
|
||||
public ItemStack assemble() {
|
||||
@@ -185,7 +206,11 @@
|
||||
if (!this.satisfiedBy(firstBuyStack, secondBuyStack)) {
|
||||
return false;
|
||||
} else {
|
||||
- firstBuyStack.shrink(this.getCostA().getCount());
|
||||
+ // CraftBukkit start
|
||||
+ if (!this.getCostA().isEmpty()) {
|
||||
+ firstBuyStack.shrink(this.getCostA().getCount());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (!this.getCostB().isEmpty()) {
|
||||
secondBuyStack.shrink(this.getCostB().getCount());
|
||||
}
|
Loading…
Reference in a new issue