Feature/linear recipe cost (#72)

This commit is contained in:
alexcrea 2025-07-06 22:37:04 +02:00 committed by GitHub
commit a40fd14b05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 560 additions and 132 deletions

View file

@ -14,7 +14,10 @@ public class AnvilRecipeBuilder {
private @NotNull String name;
private boolean exactCount;
private int xpCostPerCraft;
private int levelCostPerCraft;
private int linearXpCostPerCraft;
private boolean removeExactLinearXp;
private @Nullable ItemStack leftItem;
private @Nullable ItemStack rightItem;
@ -23,7 +26,7 @@ public class AnvilRecipeBuilder {
/**
* Instantiates a new Anvil recipe builder.
* exact count default to true.
* xp cost per craft default to 1.
* xp level and linear cost per craft default to 0.
*
* @param name The recipe name
*/
@ -31,7 +34,9 @@ public class AnvilRecipeBuilder {
this.name = name;
this.exactCount = true;
this.xpCostPerCraft = 1;
this.levelCostPerCraft = 0;
this.linearXpCostPerCraft = 0;
this.removeExactLinearXp = false;
this.leftItem = null;
this.rightItem = null;
@ -60,7 +65,7 @@ public class AnvilRecipeBuilder {
}
/**
* Get if the recipe is exact count.
* Get if the recipe is exact count. (default 0)
* <p>
* Exact count mean the recipe can only be crafted 1 by 1.
* If set to false, then it will craft as much as possible in 1 go and will keep unused material onto the anvil inventory.
@ -86,12 +91,14 @@ public class AnvilRecipeBuilder {
}
/**
* Get the xp level cost per craft.
* Get the xp level cost per craft. (default 0)
*
* @return The xp level cost per craft
* @deprecated use {@link #getLevelCostPerCraft() getLevelCostPerCraft} instead
*/
@Deprecated(since = "1.13.0")
public int getXpCostPerCraft() {
return xpCostPerCraft;
return getLevelCostPerCraft();
}
/**
@ -99,9 +106,78 @@ public class AnvilRecipeBuilder {
*
* @param xpCostPerCraft The xp level cost per craft
* @return This recipe builder instance.
* @deprecated use {@link #setLevelCostPerCraft(int) setLevelCostPerCraft} instead
*/
@Deprecated(since = "1.13.0")
public AnvilRecipeBuilder setXpCostPerCraft(int xpCostPerCraft) {
this.xpCostPerCraft = xpCostPerCraft;
return setLevelCostPerCraft(xpCostPerCraft);
}
/**
* Get the xp level cost per craft. (default 0)
*
* @return The xp level cost per craft
*/
public int getLevelCostPerCraft() {
return levelCostPerCraft;
}
/**
* Sets the xp level cost per craft.
*
* @param levelCostPerCraft The xp level cost per craft
* @return This recipe builder instance.
*/
public AnvilRecipeBuilder setLevelCostPerCraft(int levelCostPerCraft) {
this.levelCostPerCraft = levelCostPerCraft;
return this;
}
/**
* Get the linear xp cost (not xp level cost) per craft.
*
* @return The xp level cost per craft
*/
public int getLinearXpCostPerCraft() {
return linearXpCostPerCraft;
}
/**
* Sets the linear xp cost (not xp level cost) per craft.
*
* @param linearXpCostPerCraft The linear xp cost per craft
* @return This recipe builder instance.
*/
public AnvilRecipeBuilder setLinearXpCostPerCraft(int linearXpCostPerCraft) {
this.linearXpCostPerCraft = linearXpCostPerCraft;
return this;
}
/**
* Get if the linear xp should get removed by an exact amount.
* <p>
* If false (default) level cost will be the level that would be reached by a player with this amount of xp.
* If true will require the level that has at least the specified level of xp then on click remove only the necessary xp
* <p>
* linear xp cost are applied after level cost
* @return if we should remove the exact amount of linear xp
*/
public boolean isRemoveExactLinearXp() {
return removeExactLinearXp;
}
/**
* Set if the linear xp should get removed by an exact amount.
* <p>
* If false (default) level cost will be the level that would be reached by a player with this amount of xp.
* If true will require the level that has at least the specified level of xp then on click remove only the necessary xp
* <p>
* linear xp cost are applied after level cost
* @param removeExactLinearXp if we should remove the exact amount of linear xp
* @return This recipe builder instance.
*/
public AnvilRecipeBuilder setRemoveExactLinearXp(boolean removeExactLinearXp) {
this.removeExactLinearXp = removeExactLinearXp;
return this;
}
@ -182,12 +258,14 @@ public class AnvilRecipeBuilder {
*/
@Nullable // null if missing argument
public AnvilCustomRecipe build() {
if(leftItem == null || resultItem == null) return null;
if (leftItem == null || resultItem == null) return null;
return new AnvilCustomRecipe(
this.name,
this.exactCount,
this.xpCostPerCraft,
this.levelCostPerCraft,
this.linearXpCostPerCraft,
this.removeExactLinearXp,
this.leftItem, this.rightItem, this.resultItem
);
}
@ -198,7 +276,7 @@ public class AnvilRecipeBuilder {
*
* @return True if successful.
*/
public boolean registerIfAbsent(){
public boolean registerIfAbsent() {
return CustomAnvilRecipeApi.addRecipe(this);
}

View file

@ -14,7 +14,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRecipe,
@ -58,19 +58,26 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
meta.setDisplayName("§e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.toString()) + " §fCustom recipe");
meta.addItemFlags(ItemFlag.values());
boolean shouldWork = recipe.validate();
meta.setLore(Arrays.asList(
"§7Should work: §" + (shouldWork ? "aYes" : "cNo"),
"§7Exact count: §" + (recipe.getExactCount() ? "aYes" : "cNo"),
"§7Recipe Xp Cost: §e" + recipe.getXpCostPerCraft()
));
meta.setLore(getRecipeLore(recipe));
displayedItem.setItemMeta(meta);
return displayedItem;
}
private static @NotNull ArrayList<String> getRecipeLore(AnvilCustomRecipe recipe) {
boolean shouldWork = recipe.validate();
ArrayList<String> lore = new ArrayList<>();
lore.add("§7Is valid: §" + (shouldWork ? "aYes" : "cNo"));
lore.add("§7Exact count: §" + (recipe.getExactCount() ? "aYes" : "cNo"));
lore.add("§7Recipe Level Cost: §e" + recipe.getLevelCostPerCraft());
lore.add("§7Recipe Linear Xp Cost: §e" + recipe.getXpCostPerCraft());
if (recipe.getXpCostPerCraft() != 0) {
lore.add("§7Exact Linear xp remove: §" + (recipe.getRemoveExactLinearXp() ? "aYes" : "cNo"));
}
return lore;
}
@Override
protected LazyElement<CustomRecipeSubSettingGui> newInstanceOfGui(AnvilCustomRecipe generic, GuiItem item) {
return new LazyElement<>(item, () -> new CustomRecipeSubSettingGui(this, generic));
@ -87,7 +94,11 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRec
AnvilCustomRecipe recipe = new AnvilCustomRecipe(
name,
AnvilCustomRecipe.DEFAULT_EXACT_COUNT_CONFIG,
AnvilCustomRecipe.DEFAULT_XP_COST_CONFIG,
AnvilCustomRecipe.DEFAULT_XP_LEVEL_COST_CONFIG,
AnvilCustomRecipe.DEFAULT_LINEAR_XP_COST_CONFIG,
AnvilCustomRecipe.DEFAULT_REMOVE_EXACT_XP_CONFIG,
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG(),
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG(),
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());

View file

@ -36,26 +36,32 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
public CustomRecipeSubSettingGui(
@NotNull CustomRecipeConfigGui parent,
@NotNull AnvilCustomRecipe anvilRecipe) {
super(3, "§e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString()) + " §8Config");
super(4, "§e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString()) + " §8Config");
this.parent = parent;
this.anvilRecipe = anvilRecipe;
Pattern pattern = new Pattern(
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"01203450D",
"0ab000000",
"B00000000"
);
this.pane = new PatternPane(0, 0, 9, 3, pattern);
this.pane = new PatternPane(0, 0, 9, 4, pattern);
addPane(this.pane);
prepareStaticValues();
}
BoolSettingsGui.BoolSettingFactory exactCountFactory;
IntSettingsGui.IntSettingFactory xpCostFactory;
ItemSettingGui.ItemSettingFactory leftItemFactory;
ItemSettingGui.ItemSettingFactory rightItemFactory;
ItemSettingGui.ItemSettingFactory resultItemFactory;
private BoolSettingsGui.BoolSettingFactory exactCountFactory;
private BoolSettingsGui.BoolSettingFactory removeExactLinearXpFactory;
private GuiItem noRemoveExactLinearXp;
private IntSettingsGui.IntSettingFactory levelCostFactory;
private IntSettingsGui.IntSettingFactory linearXpCostFactory;
private ItemSettingGui.ItemSettingFactory leftItemFactory;
private ItemSettingGui.ItemSettingFactory rightItemFactory;
private ItemSettingGui.ItemSettingFactory resultItemFactory;
private void prepareStaticValues() {
@ -74,19 +80,38 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance));
// Displayed item will be updated later
IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE();
this.exactCountFactory = new BoolSettingsGui.BoolSettingFactory("§8Exact count ?", this,
ConfigHolder.CUSTOM_RECIPE_HOLDER,
this.anvilRecipe + "." + AnvilCustomRecipe.EXACT_COUNT_CONFIG, AnvilCustomRecipe.DEFAULT_EXACT_COUNT_CONFIG);
this.xpCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Xp Cost", this,
this.anvilRecipe +"."+AnvilCustomRecipe.XP_COST_CONFIG,
this.removeExactLinearXpFactory = new BoolSettingsGui.BoolSettingFactory("§8Remove exact linear xp ?", this,
ConfigHolder.CUSTOM_RECIPE_HOLDER,
this.anvilRecipe + "." + AnvilCustomRecipe.REMOVE_EXACT_XP_CONFIG, AnvilCustomRecipe.DEFAULT_REMOVE_EXACT_XP_CONFIG);
ItemStack item = new ItemStack(Material.BARRIER);
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("§cRemove exact linear xp ?");
meta.setLore(Collections.singletonList("§7Not usable if linear cost is 0"));
item.setItemMeta(meta);
this.noRemoveExactLinearXp = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
this.levelCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Level Cost", this,
this.anvilRecipe + "." + AnvilCustomRecipe.XP_LEVEL_COST_CONFIG,
ConfigHolder.CUSTOM_RECIPE_HOLDER,
null,
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.DEFAULT_XP_COST_CONFIG, 1, 5, 10);
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.DEFAULT_XP_LEVEL_COST_CONFIG, 1, 5, 10);
this.linearXpCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Linear Xp Cost", this,
this.anvilRecipe + "." + AnvilCustomRecipe.LINEAR_XP_COST_CONFIG,
ConfigHolder.CUSTOM_RECIPE_HOLDER,
null,
0, Integer.MAX_VALUE, AnvilCustomRecipe.DEFAULT_LINEAR_XP_COST_CONFIG, 1, 10, 100, 1000, 10000);
// Right part of the gui
this.leftItemFactory = new ItemSettingGui.ItemSettingFactory("§eRecipe Left §8Item", this,
this.anvilRecipe + "." + AnvilCustomRecipe.LEFT_ITEM_CONFIG,
ConfigHolder.CUSTOM_RECIPE_HOLDER,
@ -158,8 +183,18 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
GuiItem exactCountItem = this.exactCountFactory.getItem();
this.pane.bindItem('1', exactCountItem);
GuiItem xpCostItem = this.xpCostFactory.getItem(Material.EXPERIENCE_BOTTLE);
this.pane.bindItem('2', xpCostItem);
if (anvilRecipe.getXpCostPerCraft() == 0) {
this.pane.bindItem('a', noRemoveExactLinearXp);
} else {
this.pane.bindItem('a', removeExactLinearXpFactory.getItem());
}
GuiItem levelCostItem = this.levelCostFactory.getItem(Material.EXPERIENCE_BOTTLE);
this.pane.bindItem('2', levelCostItem);
GuiItem xpCostItem = this.linearXpCostFactory.getItem(Material.EXPERIENCE_BOTTLE);
this.pane.bindItem('b', xpCostItem);
GuiItem leftGuiItem = this.leftItemFactory.getItem();
this.pane.bindItem('3', leftGuiItem);

View file

@ -130,10 +130,20 @@ class AnvilResultListener : Listener {
if (recipe.leftItem == null) return // in case it changed
val amount = CustomRecipeUtil.getCustomRecipeAmount(recipe, leftItem, rightItem)
val xpCost = amount * recipe.xpCostPerCraft
val xpCost = recipe.determineCost(amount, leftItem, output)
val finalCost =
if (recipe.removeExactLinearXp) xpCost
else AnvilXpUtil.calculateLevelForXp(xpCost)
CustomAnvil.log("gamemode: ${player.gameMode != GameMode.CREATIVE}, cost: $xpCost, level: ${player.level}, result: ${player.level < xpCost}")
if ((player.gameMode != GameMode.CREATIVE) && (player.level < xpCost)) return
CustomAnvil.log("gamemode: ${player.gameMode != GameMode.CREATIVE}, cost: $finalCost, level: ${player.level}, result: ${player.totalExperience < finalCost} ${player.level < finalCost}")
if (player.gameMode != GameMode.CREATIVE) {
if (recipe.removeExactLinearXp) {
val levelXp = AnvilXpUtil.calculateXpForLevel(player.level)
val delta = AnvilXpUtil.calculateXpForLevel(player.level + 1) - levelXp
val totalXp = levelXp + player.exp * delta
if (totalXp < finalCost) return
} else if (player.level < finalCost) return
}
// We give the item manually
// But first we check if we should give the item
@ -142,7 +152,17 @@ class AnvilResultListener : Listener {
// Handle not creative middle click...
if (event.click != ClickType.MIDDLE &&
!handleCustomCraftClick(event, recipe, inventory, player, leftItem, rightItem, amount, xpCost)
!handleCustomCraftClick(
event,
recipe,
inventory,
player,
leftItem,
rightItem,
amount,
finalCost,
recipe.removeExactLinearXp
)
) return
// Finally, we add the item to the player
@ -157,7 +177,7 @@ class AnvilResultListener : Listener {
event: InventoryClickEvent, recipe: AnvilCustomRecipe,
inventory: AnvilInventory, player: Player,
leftItem: ItemStack, rightItem: ItemStack?,
amount: Int, xpCost: Int
amount: Int, xpCost: Int, linearCost: Boolean = false
): Boolean {
// We remove what should be removed
if (rightItem != null) {
@ -171,7 +191,23 @@ class AnvilResultListener : Listener {
inventory.setItem(ANVIL_INPUT_LEFT, leftItem)
if (player.gameMode != GameMode.CREATIVE) {
player.level -= xpCost
if (linearCost) {
val levelXp = AnvilXpUtil.calculateXpForLevel(player.level)
val delta = AnvilXpUtil.calculateXpForLevel(player.level + 1) - levelXp
var totalXp = levelXp + player.exp * delta
totalXp -= xpCost
val newLevel = AnvilXpUtil.calculateLevelForXp(totalXp.toInt())
val newLevelXp = AnvilXpUtil.calculateXpForLevel(newLevel)
val newDelta = AnvilXpUtil.calculateXpForLevel(newLevel + 1) - newLevelXp
val xp = (totalXp - newLevelXp) / newDelta
player.level = newLevel
player.exp = xp / newDelta
} else {
player.level -= xpCost
}
}
// Then we try to find the new values for the anvil

View file

@ -136,12 +136,13 @@ class PrepareAnvilListener : Listener {
event.result = resultItem
if (DependencyManager.tryTreatAnvilResult(event, resultItem)) return true
// Maybe add an option on custom craft to ignore/not ignore penalty ??
var xpCost = recipe.xpCostPerCraft * amount
xpCost += AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.CUSTOM_CRAFT)
val xpCost = recipe.determineCost(amount, first, resultItem)
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, xpCost, true)
val levelCost =
if (recipe.removeExactLinearXp) AnvilXpUtil.calculateMinimumLevelForXp(xpCost)
else AnvilXpUtil.calculateLevelForXp(xpCost)
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, levelCost, true)
return true
}

View file

@ -5,6 +5,8 @@ import org.bukkit.configuration.ConfigurationSection
import org.bukkit.inventory.ItemStack
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
import xyz.alexcrea.cuanvil.util.AnvilUseType
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
class AnvilCustomRecipe(
val name: String,
@ -12,7 +14,10 @@ class AnvilCustomRecipe(
//var exactLeft: Boolean,
//var exactRight: Boolean,
var xpCostPerCraft: Int,
var levelCostPerCraft: Int,
var XpCostPerCraft: Int,
var removeExactLinearXp: Boolean,
var leftItem: ItemStack?,
var rightItem: ItemStack?,
@ -25,7 +30,9 @@ class AnvilCustomRecipe(
//const val EXACT_LEFT_CONFIG = "exact_left"
//const val EXACT_RIGHT_CONFIG = "exact_right"
const val XP_COST_CONFIG = "xp_cost"
const val XP_LEVEL_COST_CONFIG = "xp_cost"
const val LINEAR_XP_COST_CONFIG = "linear_xp_cost"
const val REMOVE_EXACT_XP_CONFIG = "remove_exact_linear_xp"
const val LEFT_ITEM_CONFIG = "left_item"
const val RIGHT_ITEM_CONFIG = "right_item"
@ -36,7 +43,9 @@ class AnvilCustomRecipe(
//val DEFAULT_EXACT_LEFT_CONFIG = true
//val DEFAULT_EXACT_RIGHT_CONFIG = true
const val DEFAULT_XP_COST_CONFIG = 1
const val DEFAULT_XP_LEVEL_COST_CONFIG = 1
const val DEFAULT_LINEAR_XP_COST_CONFIG = 0
const val DEFAULT_REMOVE_EXACT_XP_CONFIG = false
val DEFAULT_LEFT_ITEM_CONFIG: ItemStack? = null
val DEFAULT_RIGHT_ITEM_CONFIG: ItemStack? = null
@ -45,20 +54,24 @@ class AnvilCustomRecipe(
val XP_COST_CONFIG_RANGE = 0..255
fun getFromConfig(name: String, configSection: ConfigurationSection?): AnvilCustomRecipe? {
if(configSection == null) return null
if (configSection == null) return null
return AnvilCustomRecipe(
name,
configSection.getBoolean(EXACT_COUNT_CONFIG, DEFAULT_EXACT_COUNT_CONFIG),
//configSection.getBoolean(EXACT_LEFT_CONFIG, true),
//configSection.getBoolean(EXACT_RIGHT_CONFIG, true),
configSection.getInt(XP_COST_CONFIG, DEFAULT_XP_COST_CONFIG),
configSection.getInt(XP_LEVEL_COST_CONFIG, DEFAULT_XP_LEVEL_COST_CONFIG),
configSection.getInt(LINEAR_XP_COST_CONFIG, DEFAULT_LINEAR_XP_COST_CONFIG),
configSection.getBoolean(REMOVE_EXACT_XP_CONFIG, DEFAULT_REMOVE_EXACT_XP_CONFIG),
configSection.getItemStack(LEFT_ITEM_CONFIG, DEFAULT_LEFT_ITEM_CONFIG),
configSection.getItemStack(RIGHT_ITEM_CONFIG, DEFAULT_RIGHT_ITEM_CONFIG),
configSection.getItemStack(RESULT_ITEM_CONFIG, DEFAULT_RESULT_ITEM_CONFIG),
)
)
}
fun getFromConfig(name: String): AnvilCustomRecipe? {
@ -74,14 +87,16 @@ class AnvilCustomRecipe(
}
fun saveToFile(writeFile: Boolean, doBackup: Boolean){
fun saveToFile(writeFile: Boolean, doBackup: Boolean) {
val fileConfig = ConfigHolder.CUSTOM_RECIPE_HOLDER.config
fileConfig["$name.$EXACT_COUNT_CONFIG"] = exactCount
//fileConfig.set("$name.$EXACT_LEFT_CONFIG", exactLeft)
//fileConfig.set("$name.$EXACT_RIGHT_CONFIG", exactRight)
fileConfig["$name.$XP_COST_CONFIG"] = xpCostPerCraft
fileConfig["$name.$XP_LEVEL_COST_CONFIG"] = levelCostPerCraft
fileConfig["$name.$LINEAR_XP_COST_CONFIG"] = XpCostPerCraft
fileConfig["$name.$REMOVE_EXACT_XP_CONFIG"] = removeExactLinearXp
fileConfig["$name.$LEFT_ITEM_CONFIG"] = leftItem
fileConfig["$name.$RIGHT_ITEM_CONFIG"] = rightItem
@ -94,19 +109,32 @@ class AnvilCustomRecipe(
}
@Deprecated("Should use saveToFile(Boolean, Boolean) instead") //TODO determine when an where to save/do backup and remove use of variable like TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE
fun saveToFile(){
saveToFile(GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE, GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE)
fun saveToFile() {
saveToFile(
GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE,
GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE
)
}
fun updateFromFile(){
fun updateFromFile() {
this.exactCount = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getBoolean(
"$name.$EXACT_COUNT_CONFIG",
DEFAULT_EXACT_COUNT_CONFIG
)
this.xpCostPerCraft = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getInt(
"$name.$XP_COST_CONFIG",
DEFAULT_XP_COST_CONFIG
this.levelCostPerCraft = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getInt(
"$name.$XP_LEVEL_COST_CONFIG",
DEFAULT_XP_LEVEL_COST_CONFIG
)
this.XpCostPerCraft = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getInt(
"$name.$LINEAR_XP_COST_CONFIG",
DEFAULT_LINEAR_XP_COST_CONFIG
)
this.removeExactLinearXp = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getBoolean(
"$name.$REMOVE_EXACT_XP_CONFIG",
DEFAULT_REMOVE_EXACT_XP_CONFIG
)
// Update items
@ -135,30 +163,30 @@ class AnvilCustomRecipe(
// We assume this function can be call only if leftItem != null
// Test is valid
if(!validate()) return false
if (!validate()) return false
val leftSimilar = leftItem!!.isSimilar(item1)
CustomAnvil.verboseLog("Validated test !")
// test of left item
if(!leftSimilar) return false // Test similar
if(exactCount){
if((leftItem!!.amount != item1.amount)) return false // test exact amount
}else if(item1.amount < leftItem!!.amount) return false // test if it has at least the amount we ask
if (!leftSimilar) return false // Test similar
if (exactCount) {
if ((leftItem!!.amount != item1.amount)) return false // test exact amount
} else if (item1.amount < leftItem!!.amount) return false // test if it has at least the amount we ask
CustomAnvil.verboseLog("Left item passed !")
// we don't know if right item can be
if(rightItem == null){ // null test
if(item2 != null) return false
}else {
if (rightItem == null) { // null test
if (item2 != null) return false
} else {
val rightSimilar = rightItem!!.isSimilar(item2)
CustomAnvil.verboseLog("Right similar: $rightSimilar")
if(!rightSimilar) return false // test if similar when not null
if (!rightSimilar) return false // test if similar when not null
if(exactCount) {
if (exactCount) {
if (rightItem!!.amount != item2!!.amount) return false // test exact amount
}else if(item2!!.amount < rightItem!!.amount) return false // test if it has at least the amount we ask
} else if (item2!!.amount < rightItem!!.amount) return false // test if it has at least the amount we ask
}
CustomAnvil.verboseLog("Right item passed !")
@ -170,5 +198,18 @@ class AnvilCustomRecipe(
return name
}
fun determineCost(amount: Int, first: ItemStack, resultItem: ItemStack): Int {
// First we determine the non linear level cost
var levelCost = levelCostPerCraft * amount
// TODO Maybe add an option per custom craft to ignore/not ignore penalty ??
levelCost += AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.CUSTOM_CRAFT)
var xpCost = AnvilXpUtil.calculateXpForLevel(levelCost)
// Then we add the linear cost
xpCost += XpCostPerCraft * amount
return xpCost
}
}

View file

@ -203,4 +203,43 @@ object AnvilXpUtil {
return rightValue + illegalPenalty
}
/**
* Calculate the maximum level reachable with this amount of `xp`
* This is equivalent of the displayed level on client
* @author provided by kFor
*/
fun calculateLevelForXp(xp: Int): Int {
return when {
xp <= 352 -> (Math.sqrt((xp + 9).toDouble()) - 3).toInt()
xp <= 1507 -> {
val inner = (2.0 / 5.0) * (xp - 7839.0 / 40.0)
(81.0 / 10.0 + Math.sqrt(inner)).toInt()
}
else -> {
val inner = (2.0 / 9.0) * (xp - 54215.0 / 72.0)
(325.0 / 18.0 + Math.sqrt(inner)).toInt()
}
}
}
/**
* Calculate the minimum level necessary to have at least `xp`
*/
fun calculateMinimumLevelForXp(xp: Int): Int {
return calculateLevelForXp(xp - 1) + 1
}
/**
* Calculate the minimum amount of xp necessary to reach `level`
* @author provided by kFor
*/
fun calculateXpForLevel(level: Int): Int {
return when {
level <= 16 -> (level * level + 6 * level)
level <= 31 -> (2.5 * level * level - 40.5 * level + 360).toInt()
else -> (4.5 * level * level - 162.5 * level + 2220).toInt()
}
}
}

View file

@ -88,16 +88,16 @@ public class EnchantmentUtilTests extends ConfigResetCustomAnvilTest {
);
// Test with no permission
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData2);
nullResultData.executeTest(anvil, player);
nullResultData2.executeTest(anvil, player);
// Add permission
PermissionAttachment attachment = player.addAttachment(plugin);
attachment.setPermission(permission, true);
// Test with new permission
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData2);
legalResultData.executeTest(anvil, player);
legalResultData2.executeTest(anvil, player);
}
@Test
@ -161,24 +161,24 @@ public class EnchantmentUtilTests extends ConfigResetCustomAnvilTest {
);
// Test failing result first
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData2);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData3);
nullResultData2.executeTest(anvil, player);
nullResultData3.executeTest(anvil, player);
// Test working sharpness 2
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
// Set merge limit to 2 & test
ConfigHolder.DEFAULT_CONFIG.getConfig().set("disable-merge-over.minecraft:sharpness", 1);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
// Add permission
PermissionAttachment attachment = player.addAttachment(plugin);
attachment.setPermission(permission, true);
// Test working sharpness 2
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData2);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData3);
legalResultData.executeTest(anvil, player);
legalResultData2.executeTest(anvil, player);
legalResultData3.executeTest(anvil, player);
}
}

View file

@ -67,7 +67,7 @@ public class AnvilFuseTests extends SharedCustomAnvilTest {
5
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, data);
data.executeTest(anvil, player);
}
@Test
@ -87,7 +87,7 @@ public class AnvilFuseTests extends SharedCustomAnvilTest {
5
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, data);
data.executeTest(anvil, player);
}
@Test
@ -101,7 +101,7 @@ public class AnvilFuseTests extends SharedCustomAnvilTest {
null
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, data);
data.executeTest(anvil, player);
}
// Note: currently anvil can only have null name. maybe handle differently later
@ -117,10 +117,10 @@ public class AnvilFuseTests extends SharedCustomAnvilTest {
AnvilFuseTestData data = new AnvilFuseTestData(
base, null,
expected, expected, null,
1, 1, null
1, null, 1
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, data);
data.executeTest(anvil, player);
}
}

View file

@ -12,10 +12,15 @@ import static org.junit.jupiter.api.Assertions.*;
public class AnvilRecipeBuilderTest extends SharedOnlyMockBukkit {
private AnvilRecipeBuilder builder;
private AnvilRecipeBuilder builder2;
@BeforeEach
public void setup() {
builder = new AnvilRecipeBuilder("test");
builder2 = new AnvilRecipeBuilder("test");
builder2.setLeftItem(new ItemStack(Material.STICK));
builder2.setResultItem(new ItemStack(Material.STICK));
}
@Test
@ -38,6 +43,7 @@ public class AnvilRecipeBuilderTest extends SharedOnlyMockBukkit {
.setResultItem(new ItemStack(Material.STICK));
assertNotNull(builder.build());
assertNotNull(builder2.build());
}
@Test
@ -63,23 +69,39 @@ public class AnvilRecipeBuilderTest extends SharedOnlyMockBukkit {
@Test
void setXpCostPerCraft(){
assertEquals(1, builder.getXpCostPerCraft());
builder.setXpCostPerCraft(2);
assertEquals(2, builder.getXpCostPerCraft());
assertEquals(0, builder2.getLevelCostPerCraft());
assertEquals(0, builder2.build().getLevelCostPerCraft());
builder2.setLevelCostPerCraft(2);
assertEquals(2, builder2.getLevelCostPerCraft());
assertEquals(2, builder2.build().getLevelCostPerCraft());
}
@Test
void setLinearXpCostPerCraft(){
assertEquals(0, builder2.getLinearXpCostPerCraft());
assertEquals(0, builder2.build().getXpCostPerCraft());
builder2.setLinearXpCostPerCraft(2);
assertEquals(2, builder2.getLinearXpCostPerCraft());
assertEquals(2, builder2.build().getXpCostPerCraft());
}
@Test
void setExactCount(){
assertTrue(builder.isExactCount());
builder.setExactCount(false);
assertFalse(builder.isExactCount());
assertTrue(builder2.isExactCount());
assertTrue(builder2.build().getExactCount());
builder2.setExactCount(false);
assertFalse(builder2.isExactCount());
assertFalse(builder2.build().getExactCount());
}
@Test
void setName(){
assertEquals("test", builder.getName());
builder.setName("other");
assertEquals("other", builder.getName());
assertEquals("test", builder2.getName());
assertEquals("test", builder2.build().getName());
builder2.setName("other");
assertEquals("other", builder2.getName());
assertEquals("other", builder2.build().getName());
}
}

View file

@ -71,7 +71,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
Assertions.assertNotNull(sharpness);
// Testing default conflict (illegal item should not be produced)
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
// Try to find & remove conflict
EnchantConflictGroup conflict = findGroup("sword_enchant_conflict");
@ -79,7 +79,7 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
// Test what happen when we remove the conflict (illegal item should be allowed)
ConflictAPI.removeConflict(conflict);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
// We create and add a new conflict
ConflictBuilder builder = new ConflictBuilder("sword_enchant_conflict");
@ -88,11 +88,11 @@ public class ConflictApiTests extends ConfigResetCustomAnvilTest {
// Nothing should change as it is not new: it was previously deleted
Assertions.assertFalse(builder.registerIfNew());
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
// Now the conflict should be registered and conflict should exist
Assertions.assertTrue(builder.registerIfAbsent());
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
}
@Test

View file

@ -1,6 +1,7 @@
package xyz.alexcrea.cuanvil.api;
import org.bukkit.Material;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.Inventory;
@ -11,10 +12,11 @@ import org.junit.jupiter.api.Test;
import org.mockbukkit.mockbukkit.entity.PlayerMock;
import org.mockbukkit.mockbukkit.inventory.ItemStackMock;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.data.AnvilClickTestData;
import xyz.alexcrea.cuanvil.data.TestDataContainer;
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
import xyz.alexcrea.cuanvil.tests.ConfigResetCustomAnvilTest;
import xyz.alexcrea.cuanvil.data.AnvilFuseTestData;
import xyz.alexcrea.cuanvil.util.AnvilFuseTestUtil;
import static org.junit.jupiter.api.Assertions.*;
@ -57,14 +59,14 @@ public class CustomAnvilRecipeApiTests extends ConfigResetCustomAnvilTest {
);
// Testing default conflict (no recipe exist)
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
// Add and test recipe
AnvilRecipeBuilder builder = new AnvilRecipeBuilder(recipeName);
builder.setExactCount(true).setLeftItem(stick).setResultItem(stick).setXpCostPerCraft(2);
builder.setExactCount(true).setLeftItem(stick).setResultItem(stick).setLevelCostPerCraft(2);
assertTrue(builder.registerIfAbsent());
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
AnvilCustomRecipe recipe = getByName(recipeName);
assertNotNull(recipe);
@ -72,21 +74,21 @@ public class CustomAnvilRecipeApiTests extends ConfigResetCustomAnvilTest {
// Remove recipe
assertTrue(CustomAnvilRecipeApi.removeRecipe(recipe));
assertFalse(CustomAnvilRecipeApi.removeRecipe(recipe));
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
recipe = getByName(recipeName);
assertNull(recipe);
// Try to add deleted recipe with no override (should not add)
assertFalse(CustomAnvilRecipeApi.addRecipe(builder, false));
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
recipe = getByName(recipeName);
assertNull(recipe);
// Try to add deleted recipe with override (should add)
assertTrue(CustomAnvilRecipeApi.addRecipe(builder, true));
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
recipe = getByName(recipeName);
assertNotNull(recipe);
@ -119,25 +121,134 @@ public class CustomAnvilRecipeApiTests extends ConfigResetCustomAnvilTest {
null, null
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
AnvilRecipeBuilder builder = new AnvilRecipeBuilder(recipeName);
builder.setExactCount(false)
.setLeftItem(stick)
.setResultItem(stick2)
.setXpCostPerCraft(2);
.setLevelCostPerCraft(2);
assertTrue(builder.registerIfAbsent());
// Now working test
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData1);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData2);
legalResultData1.executeTest(anvil, player);
legalResultData2.executeTest(anvil, player);
}
@Test
public void testLinearXpCost() {
String recipeName = "stick_recipe";
ItemStack stick = new ItemStackMock(Material.STICK);
ItemStack stick2 = new ItemStackMock(Material.STICK, 2);
ItemStack stick5 = new ItemStackMock(Material.STICK, 5);
ItemStack stick10 = new ItemStackMock(Material.STICK, 10);
AnvilFuseTestData nullResultData = new AnvilFuseTestData(
stick, stick,
null
);
TestDataContainer legalResultData1 = new TestDataContainer(new AnvilFuseTestData(
stick, stick,
null, stick2, null,
1,
null, null
), new AnvilClickTestData(
null, null, null, stick2,
1,
Event.Result.DENY, true, Event.Result.DENY
));
TestDataContainer legalResultData2 = new TestDataContainer(new AnvilFuseTestData(
stick5, stick,
null, stick10, null,
4,
null, null
), new AnvilClickTestData(
null, null, null, stick10,
4,
Event.Result.DENY, true, Event.Result.DENY
));
nullResultData.executeTest(anvil, player);
AnvilRecipeBuilder builder = new AnvilRecipeBuilder(recipeName);
builder.setExactCount(false)
.setLeftItem(stick)
.setResultItem(stick2)
.setLevelCostPerCraft(0)
.setLinearXpCostPerCraft(10);
assertTrue(builder.registerIfAbsent());
// Now working test
legalResultData1.executeTest(anvil, player);
legalResultData2.executeTest(anvil, player);
}
@Test
public void testLinearXpCostRemoveExact() {
String recipeName = "stick_recipe";
ItemStack stick = new ItemStackMock(Material.STICK);
ItemStack stick2 = new ItemStackMock(Material.STICK, 2);
ItemStack stick5 = new ItemStackMock(Material.STICK, 5);
ItemStack stick10 = new ItemStackMock(Material.STICK, 10);
AnvilFuseTestData nullResultData = new AnvilFuseTestData(
stick, stick,
null
);
TestDataContainer legalResultData1 = new TestDataContainer(new AnvilFuseTestData(
stick, stick,
null, stick2, null,
2,
null, null
), new AnvilClickTestData(
null, null, null, stick2,
2,
Event.Result.DENY, true, Event.Result.DENY
));
TestDataContainer legalResultData2 = new TestDataContainer(new AnvilFuseTestData(
stick5, stick,
null, stick10, null,
5,
null, null
), new AnvilClickTestData(
null, null, null, stick10,
5,
Event.Result.DENY, true, Event.Result.DENY
));
nullResultData.executeTest(anvil, player);
AnvilRecipeBuilder builder = new AnvilRecipeBuilder(recipeName);
builder.setExactCount(false)
.setLeftItem(stick)
.setResultItem(stick2)
.setLinearXpCostPerCraft(10)
.setRemoveExactLinearXp(true);
assertTrue(builder.registerIfAbsent());
// Now working test
legalResultData1.executeTest(anvil, player);
//TODO check exp ?
System.out.printf(String.valueOf(player.getExp()));
legalResultData2.executeTest(anvil, player);
//TODO check exp ?
}
@Nullable
public static AnvilCustomRecipe getByName(String name){
public static AnvilCustomRecipe getByName(String name) {
for (AnvilCustomRecipe registeredRecipe : CustomAnvilRecipeApi.getRegisteredRecipes()) {
if(registeredRecipe.getName().contentEquals(name)){
if (registeredRecipe.getName().contentEquals(name)) {
return registeredRecipe;
}
}

View file

@ -58,7 +58,7 @@ public class UnitRepairApiTests extends ConfigResetCustomAnvilTest {
2
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
}
@Test
@ -76,7 +76,7 @@ public class UnitRepairApiTests extends ConfigResetCustomAnvilTest {
// Remove unit repair
assertTrue(UnitRepairApi.removeUnitRepair(Material.DIAMOND, Material.DIAMOND_PICKAXE));
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
// see override
assertFalse(UnitRepairApi.addUnitRepair(Material.DIAMOND, Material.DIAMOND_PICKAXE, 0.25));
@ -107,12 +107,12 @@ public class UnitRepairApiTests extends ConfigResetCustomAnvilTest {
2
);
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, nullResultData);
nullResultData.executeTest(anvil, player);
// Add unit repair
assertTrue(UnitRepairApi.addUnitRepair(Material.STICK, Material.DIAMOND_PICKAXE));
assertFalse(UnitRepairApi.addUnitRepair(Material.STICK, Material.DIAMOND_PICKAXE));
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, legalResultData);
legalResultData.executeTest(anvil, player);
}
}

View file

@ -1,8 +1,11 @@
package xyz.alexcrea.cuanvil.data;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.util.AnvilFuseTestUtil;
public record AnvilClickTestData(
@Nullable ItemStack leftItem,
@ -47,4 +50,8 @@ public record AnvilClickTestData(
int levelCost) {
this(expectedCursor, levelCost, null);
}
public void executeTest(AnvilInventory anvil, Player player){
AnvilFuseTestUtil.executeAnvilClickTest(anvil, player, this);
}
}

View file

@ -1,7 +1,10 @@
package xyz.alexcrea.cuanvil.data;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.util.AnvilFuseTestUtil;
public record AnvilFuseTestData(
@Nullable ItemStack leftItem,
@ -51,4 +54,8 @@ public record AnvilFuseTestData(
);
}
public void executeTest(AnvilInventory anvil, HumanEntity player){
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, this);
}
}

View file

@ -16,17 +16,17 @@ public record TestDataContainer(
) {
public void executeTest(AnvilInventory anvil, Player player) {
executeFuseTest(anvil, player);
if (clickData != null) executeClickTest(anvil, player);
fuseData.executeTest(anvil, player);
if (clickData != null) clickData.executeTest(anvil, player);
}
public void executeFuseTest(AnvilInventory anvil, HumanEntity player) {
AnvilFuseTestUtil.executeAnvilFuseTest(anvil, player, fuseData);
fuseData.executeTest(anvil, player);
}
public void executeClickTest(AnvilInventory anvil, Player player) {
Assertions.assertNotNull(clickData);
AnvilFuseTestUtil.executeAnvilClickTest(anvil, player, clickData);
clickData.executeTest(anvil, player);
}
public @NotNull TestDataContainer nullifyResult() {

View file

@ -110,22 +110,60 @@ public class AnvilFuseTestUtil {
Assertions.assertEquals(player.getOpenInventory().getTopInventory(), anvil,
"Openned inventory is not anvil");
ItemStack afterLeft = data.expectedAfterLeftPlaced();
ItemStack afterRight = data.expectedAfterRightPlaced();
ItemStack afterBoth = data.expectedResult();
// Fist, test null result(s)
// Test with only the left item
anvil.setItem(1, null); // We clear the right slot in case something was there
testPlacingItem(anvil, player,
0, data.expectedPriceAfterLeftPlaced(),
data.leftItem(), data.expectedAfterLeftPlaced());
if(afterLeft == null){
anvil.setItem(1, null); // We clear the right slot in case something was there
testPlacingItem(anvil, player,
0, data.expectedPriceAfterLeftPlaced(),
data.leftItem(), null);
}
// Test with only the right item
anvil.setItem(0, null); // We only want the right item. so we remove the left one
testPlacingItem(anvil, player,
1, data.expectedPriceAfterRightPlaced(),
data.rightItem(), data.expectedAfterRightPlaced());
if(afterRight == null){
anvil.setItem(0, null); // We only want the right item. so we remove the left one
testPlacingItem(anvil, player,
1, data.expectedPriceAfterRightPlaced(),
data.rightItem(), null);
}
// Test with both placed
testPlacingItem(anvil, player,
0, data.expectedPriceAfterBothPlaced(),
data.leftItem(), data.expectedResult());
if(afterBoth == null){
anvil.setItem(0, data.leftItem());
testPlacingItem(anvil, player,
1, data.expectedPriceAfterBothPlaced(),
data.rightItem(), data.expectedResult());
}
// Then, test non null result(s)
// Test with only the left item
if(afterLeft != null){
anvil.setItem(1, null); // We clear the right slot in case something was there
testPlacingItem(anvil, player,
0, data.expectedPriceAfterLeftPlaced(),
data.leftItem(), afterLeft);
}
// Test with only the right item
if(afterRight != null){
anvil.setItem(0, null); // We only want the right item. so we remove the left one
testPlacingItem(anvil, player,
1, data.expectedPriceAfterRightPlaced(),
data.rightItem(), afterRight);
}
// Test with both placed
if(afterBoth != null){
anvil.setItem(0, data.leftItem());
testPlacingItem(anvil, player,
1, data.expectedPriceAfterBothPlaced(),
data.rightItem(), afterBoth);
}
}
public static void executeAnvilClickTest(
@ -139,6 +177,7 @@ public class AnvilFuseTestUtil {
ItemStack result = anvil.getResult();
player.setLevel(0);
player.setExp(0);
player.setItemOnCursor(null);
// Do a test with not enough level
@ -151,6 +190,7 @@ public class AnvilFuseTestUtil {
assertEqual(null, player.getItemOnCursor());
}
player.setLevel(data.levelCost());
player.setExp(0);
player.setItemOnCursor(null);
simulateClick(anvil, player, data.expectedResult());
@ -208,7 +248,7 @@ public class AnvilFuseTestUtil {
public static void assertEqual(@Nullable ItemStack expected, @Nullable ItemStack other) {
boolean secondIsAir = isAir(other);
if (isAir(expected))
Assertions.assertTrue(secondIsAir, "Item " + other + " was not air but was expected to be");
Assertions.assertTrue(secondIsAir, "Item " + other + " was not air but was expected to be.");
else {
Assertions.assertFalse(secondIsAir, "Item " + other + " is air but was expected to be " + expected);
@ -225,7 +265,7 @@ public class AnvilFuseTestUtil {
public static void assertPriceEqual(Integer expectedPrice, int price) {
if (expectedPrice == null) return;
Assertions.assertEquals(expectedPrice, price);
Assertions.assertEquals(expectedPrice, price, "Price of anvil fuse was wrong");
}
}