#(solved) Creating a new DyeItem without overwriting an existing dye

5 messages · Page 1 of 1 (latest)

hearty dirge
#

Howdy! I'm trying to create a new item that functions identically to a particular color of DyeItem. I'm not creating a new DyeColor or anything, but if I instantiate or subclass a new DyeItem, it overwrites the vanilla DyeItem for that color in DyeItem's static DYES map, which I don't want, since it breaks some recipes, generation, and behavior.

I tried writing a mixin to cancel the DyeItem constructor before inserting into the map, but I'm only gettings inject errors when I do that. Have other folks done something like this before?

#

Even something as simple as changing DYES.put(color, this) to DYES.putIfAbsent(color, this) would work, but I can't get the inject to actually attach in a way such that the default behavior doesn't happen anyway

#

(solved) Creating a new DyeItem without overwriting an existing dye

#

Man, the number of times I've posted a question, only to soon after find the answer myself. Leaving this up for searchability. Here's what I did to solve this:

public class CustomDyeItem extends DyeItem {
    public static final DyeColor COLOR = DyeColor.BROWN;

    public CustomDyeItem(Item.Settings settings) {
        super(COLOR, settings);
        ((DyeItemAccessor) this).getDYES().put(COLOR, ((DyeItem) Items.BROWN_DYE));
    }
}

Accessor mixin:

@Mixin(DyeItem.class)
public interface DyeItemAccessor {
    @Accessor
    Map<DyeColor, DyeItem> getDYES();
}
rare gate
#

Doesn't that overwrite the map value anyway?