33import com .mojang .logging .LogUtils ;
44import dev .tonimatas .mekanismcurios .bridge .PlayerBridge ;
55import dev .tonimatas .mekanismcurios .networking .OpenPortableQIOPacket ;
6+ import dev .tonimatas .mekanismcurios .util .CuriosSlots ;
67import mekanism .common .registries .MekanismItems ;
78import net .minecraft .server .level .ServerPlayer ;
89import net .minecraft .world .InteractionHand ;
910import net .minecraft .world .entity .player .Player ;
11+ import net .minecraft .world .item .Item ;
1012import net .minecraft .world .item .ItemStack ;
1113import net .neoforged .bus .api .IEventBus ;
1214import net .neoforged .bus .api .SubscribeEvent ;
1820import org .slf4j .Logger ;
1921import top .theillusivec4 .curios .api .CuriosApi ;
2022import top .theillusivec4 .curios .api .CuriosCapability ;
23+ import top .theillusivec4 .curios .api .SlotContext ;
24+ import top .theillusivec4 .curios .api .SlotResult ;
25+ import top .theillusivec4 .curios .api .type .capability .ICuriosItemHandler ;
26+
27+ import java .util .Optional ;
2128
2229@ Mod (MekanismCurios .MODID )
2330public class MekanismCurios {
@@ -41,18 +48,18 @@ public void registerNetworking(final RegisterPayloadHandlersEvent event) {
4148 }
4249
4350 public static ItemStack getSlot (Player player ) {
44- String slot = ((PlayerBridge ) player ).mci$getSlot ().id ();
45-
46- return CuriosApi .getCuriosInventory (player ).map (iCuriosItemHandler ->
47- iCuriosItemHandler .getCurios ().get (slot ).getStacks ().getStackInSlot (0 )).orElse (ItemStack .EMPTY );
51+ return ((PlayerBridge ) player ).mci$getSlot ().getItemStack (player );
4852 }
4953
5054 public static void setSlot (Player player , ItemStack stack ) {
5155 if (player instanceof ServerPlayer ) {
52- String slot = ((PlayerBridge ) player ).mci$getSlot ().id ();
56+ CuriosSlots slot = ((PlayerBridge ) player ).mci$getSlot ();
57+ SlotContext slotContext = getFirstCurios (player , slot .getItem ());
58+
59+ if (slotContext == null ) return ;
5360
5461 CuriosApi .getCuriosInventory (player ).ifPresent (curiosInventory ->
55- curiosInventory .setEquippedCurio (slot , 0 , stack ));
62+ curiosInventory .setEquippedCurio (slotContext . identifier (), slotContext . index () , stack ));
5663 }
5764 }
5865
@@ -63,4 +70,15 @@ public static ItemStack getHandOrCuriosItem(Player player, InteractionHand hand)
6370 return player .getItemInHand (hand );
6471 }
6572 }
73+
74+ public static SlotResult getCuriosSlot (Player player , SlotContext slotContext ) {
75+ Optional <ICuriosItemHandler > curiosInventory = CuriosApi .getCuriosInventory (player );
76+ return curiosInventory .flatMap (iCuriosItemHandler -> iCuriosItemHandler .findCurio (slotContext .identifier (), slotContext .index ())).orElse (null );
77+ }
78+
79+ public static SlotContext getFirstCurios (Player player , Item item ) {
80+ Optional <ICuriosItemHandler > curiosInventory = CuriosApi .getCuriosInventory (player );
81+ Optional <SlotResult > firstCurios = curiosInventory .flatMap (iCuriosItemHandler -> iCuriosItemHandler .findFirstCurio (item ));
82+ return firstCurios .map (SlotResult ::slotContext ).orElse (null );
83+ }
6684}
0 commit comments