Version 1.5.5:

* Hopefully fixed MaxDemand bug when you buy something around 1500+ times back-to-back
This commit is contained in:
PretzelJohn 2022-04-30 01:57:06 -04:00
parent 030974f065
commit 2d97903db6
4 changed files with 12 additions and 5 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.pretzel.dev</groupId> <groupId>com.pretzel.dev</groupId>
<artifactId>VillagerTradeLimiter</artifactId> <artifactId>VillagerTradeLimiter</artifactId>
<version>1.5.4</version> <version>1.5.5</version>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>

View File

@ -121,7 +121,7 @@ public class PlayerListener implements Listener {
setIngredient(override.getConfigurationSection("Result"), recipe.getResult()); setIngredient(override.getConfigurationSection("Result"), recipe.getResult());
} }
//Set the maximum number of uses (trades/day) //Set the maximum number of uses (trades/restock)
recipe.setMaxUses(getMaxUses(recipe, other)); recipe.setMaxUses(getMaxUses(recipe, other));
} }
@ -146,7 +146,10 @@ public class PlayerListener implements Listener {
private int getDemand(final RecipeWrapper recipe) { private int getDemand(final RecipeWrapper recipe) {
int demand = recipe.getDemand(); int demand = recipe.getDemand();
int maxDemand = settings.fetchInt(recipe, "MaxDemand", -1); int maxDemand = settings.fetchInt(recipe, "MaxDemand", -1);
if(maxDemand >= 0 && demand > maxDemand) return maxDemand; if(maxDemand >= 0 && demand > maxDemand) {
recipe.setDemand(maxDemand);
return maxDemand;
}
return demand; return demand;
} }
@ -162,8 +165,9 @@ public class PlayerListener implements Listener {
int demand = getDemand(recipe); int demand = getDemand(recipe);
float priceMultiplier = recipe.getPriceMultiplier(); float priceMultiplier = recipe.getPriceMultiplier();
int discount = -(int)(totalReputation * priceMultiplier) - (int)(hotvDiscount * basePrice) + Math.max(0, (int)(demand * priceMultiplier * basePrice)); int discount = -(int)(totalReputation * priceMultiplier) - (int)(hotvDiscount * basePrice) + Math.max(0, (int)(demand * priceMultiplier * basePrice));
//discount = -(265 * 0.05) - (0.3 * 1) + max(0, 94965314 * 0.05 * 1) = -13
double maxDiscount = settings.fetchDouble(recipe, "MaxDiscount", 0.3); double maxDiscount = settings.fetchDouble(recipe, "MaxDiscount", 0.3); //0.1
if(maxDiscount >= 0.0 && maxDiscount <= 1.0) { if(maxDiscount >= 0.0 && maxDiscount <= 1.0) {
//Change the discount to the smaller MaxDiscount //Change the discount to the smaller MaxDiscount
if(basePrice + discount < basePrice * (1.0 - maxDiscount)) { if(basePrice + discount < basePrice * (1.0 - maxDiscount)) {

View File

@ -26,6 +26,9 @@ public class RecipeWrapper {
this.specialPrice = getSpecialPrice(); this.specialPrice = getSpecialPrice();
} }
/** @param demand The demand, which increases prices if you buy too often. Negative values are ignored. */
public void setDemand(int demand) { recipe.setInteger("demand", demand); }
/** @param specialPrice The discount, which is added to the base price. A negative value will decrease the price, and a positive value will increase the price. */ /** @param specialPrice The discount, which is added to the base price. A negative value will decrease the price, and a positive value will increase the price. */
public void setSpecialPrice(int specialPrice) { recipe.setInteger("specialPrice", specialPrice); } public void setSpecialPrice(int specialPrice) { recipe.setInteger("specialPrice", specialPrice); }

View File

@ -1,7 +1,7 @@
name: VillagerTradeLimiter name: VillagerTradeLimiter
author: PretzelJohn author: PretzelJohn
main: com.pretzel.dev.villagertradelimiter.VillagerTradeLimiter main: com.pretzel.dev.villagertradelimiter.VillagerTradeLimiter
version: 1.5.4 version: 1.5.5
api-version: 1.14 api-version: 1.14
commands: commands: