Curios API (Forge/NeoForge)

Curios API (Forge/NeoForge)

140M Downloads

Unsupported Operation in Forge 1.20.1

lcy0x1 opened this issue ยท 0 comments

commented

Relevant Code:
In the following lines, CuriosEventHandler::tick retrieves the prevStack attribute multimap, and then modify it.

Multimap<Attribute, AttributeModifier> map =
CuriosApi.getAttributeModifiers(slotContext, uuid, prevStack);

for (Attribute attribute : toRemove) {
map.removeAll(attribute);
}

In the following lines, we can see that the multimap is from CurioAttributeModifierEvent::getModifiers. Note that it's named as unmodifiable.
CurioAttributeModifierEvent evt =
new CurioAttributeModifierEvent(stack, slotContext, uuid, multimap);
MinecraftForge.EVENT_BUS.post(evt);
return evt.getModifiers();

public Multimap<Attribute, AttributeModifier> getModifiers() {
return this.unmodifiableModifiers;
}

However, it's actually modifiable at the beginning
public CurioAttributeModifierEvent(ItemStack stack, SlotContext slotContext, UUID uuid,
Multimap<Attribute, AttributeModifier> modifiers) {
this.stack = stack;
this.slotContext = slotContext;
this.unmodifiableModifiers = this.originalModifiers = modifiers;
this.uuid = uuid;

Then it becomes unmodifiable when someone attempts to modify through the event.
private Multimap<Attribute, AttributeModifier> getModifiableMap() {
if (this.modifiableModifiers == null) {
this.modifiableModifiers = HashMultimap.create(this.originalModifiers);
this.unmodifiableModifiers = Multimaps.unmodifiableMultimap(this.modifiableModifiers);
}
return this.modifiableModifiers;
}

Here map is assigned with a modifiable multimap when nobody attempts to modify the map through event. However, if someone attempts to modify it, then the map will get an unmodifiable multimap. And thus, if the map contains slot modifiers, it will crash.

Steps to reproduce the event:

  1. Have a curios item that adds slot and one that doesn't
  2. Write an event that modifies that map
  3. Put the slot-adder in, and then use the non-adder to replace the item
  4. Crash