Curios API (Forge/NeoForge)

Curios API (Forge/NeoForge)

140M Downloads

isItemValid method on the result of CuriosApi.getCuriosHelper().getEquippedCurios returns true when the itemstack is not valid

Lothrazar opened this issue · 2 comments

commented

Versions (Be specific, do not write "latest"):

mc_version=1.16.5
forge_version=36.0.12
curios_version=1.16.5-4.0.4.0

Goal:

I have an item stack that IS a curio, but only one type.

I want to Equip an itemstack onto a player, in a Curios slot that is valid and matches that type

Strategy:

First get the curios capability with the API:
CuriosApi.getCuriosHelper().getEquippedCurios(player);

Then loop on those slots, check if the item stack is valid, and if so, do the insert.

Expected result:

If my item is a "ring" only, and the slot is a "feet" slot, I expect isItemValid to return false.

Actual result:

It returns true, which implies that rings are valid to be placed into feet slots

Source code link:

https://github.com/Lothrazar/Tombstone-Fork/blob/6bed6d9c5474be2450766fa46fcb65bae88b4084/src/main/java/com/lothrazar/simpletomb/helper/CuriosHelper.java#L17

Am i using the curios API wrong?

If there is a better way to equip a curio onto a players slot, OR if there is a better way to check if my itemstack is compatible with the current slot, please let me know

commented

ICuriosHelper#getEquippedCurios only returns a wrapper of currently equipped curios, not the actual curios inventory itself. For that, you're looking for ICuriosHelper#getCuriosHandler.

For your implementation, it'd look something like this:

Set<String> tags = CuriosApi.getCuriosHelper().getCurioTags(stack.getItem());

CuriosApi.getCuriosHelper().getCuriosHandler(livingEntity).ifPresent(handler -> {
  Map<String, ICurioStacksHandler> curios = handler.getCurios();
  
  for (String tag : tags) {
    ICurioStacksHandler curioStacks = curios.get(tag);
  
    if (curioStacks != null) {
      IDynamicStackHandler stacks = curioStacks.getStacks();
  
      for (int i = 0; i < stacks.getSlots(); i++) {
        // Do the thing
      }
    }
  }
});

Basically, use the curio tags to retrieve the right ICurioStacksHandler instances so that your types always match and loop through the result of ICurioStacksHandler#getStacks, which returns an IDynamicStackHandler (which extends IItemHandlerModifiable).

commented

Worked perfectly, thanks!