CraftTweaker

CraftTweaker

151M Downloads

Reimplement maxDamage setter

jtgibson01 opened this issue ยท 0 comments

commented

I would like the maxDamage setter from 1.12 versions of CraftTweaker to be reimplemented for the new CraftTweaker versions (1.16 at the very least, as it's my current use case =)).

Feature request reason
I currently have a very simple script (rewritten here using 1.14+ API):

import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;

<item:minecraft:wooden_axe>.maxDamage = 3;
<item:minecraft:wooden_hoe>.maxDamage = 12;
<item:minecraft:wooden_pickaxe>.maxDamage = 3;
<item:minecraft:wooden_shovel>.maxDamage = 32;

<item:minecraft:stone_axe>.maxDamage = 48;
<item:minecraft:stone_hoe>.maxDamage = 24;
<item:minecraft:stone_pickaxe>.maxDamage = 16;
<item:minecraft:stone_shovel>.maxDamage = 64;

<item:minecraft:iron_hoe>.maxDamage = 511;
<item:minecraft:diamond_hoe>.maxDamage = 4087;

which works flawlessly in 1.12, but does not work in 1.16 as there are no equivalent setters for maxDamage after the rewrite.

Feature request dependencies
Delving into the 1.12 source, it does seem as though the setter is non-trivial -- it involves calling an ActionSetStackMaxDamage action and stuff'n'such. Is this doable in the newer Minecraft versions at all?

/**
* Gets the maximum item damage. Returns 0 if the item cannot be damaged.
*
* @return maximum item damage
*/
@ZenGetter("maxDamage")
int getMaxDamage();
/**
* Sets the max Itemstack damage
*
* @param damage the new max damage
*/
@ZenSetter("maxDamage")
void setMaxDamage(int damage);

@Override
public int getMaxDamage() {
return stack.getMaxDamage();
}
@Override
public void setMaxDamage(int damage) {
CraftTweakerAPI.apply(new ActionSetStackMaxDamage(stack, damage));
}

package crafttweaker.mc1120.actions;
import crafttweaker.IAction;
import net.minecraft.item.ItemStack;
/**
* @author Jared
*/
public class ActionSetStackMaxDamage implements IAction {
private final ItemStack stack;
private final int damage;
public ActionSetStackMaxDamage(ItemStack stack, int damage) {
this.stack = stack;
this.damage = damage;
}
private static void set(ItemStack stack, int damage) {
if(!stack.isEmpty())
stack.getItem().setMaxDamage(damage);
}
@Override
public void apply() {
set(stack, damage);
}
@Override
public String describe() {
return "Setting max damage of " + stack.getDisplayName() + " to " + damage;
}
}

Game Version
1.14+