Skip to content

Commit

Permalink
feat: allow curios to find satchel in any curios slot type
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Jun 7, 2024
1 parent f2024ca commit fbbe4ea
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 31 deletions.
26 changes: 19 additions & 7 deletions src/main/java/com/klikli_dev/occultism/util/CuriosUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import top.theillusivec4.curios.api.CuriosApi;
import top.theillusivec4.curios.api.CuriosCapability;
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
Expand Down Expand Up @@ -63,22 +64,33 @@ public static ItemStack getBackpack(Player player) {
if (curiosHandler == null)
return ItemStack.EMPTY;

var belt = curiosHandler.getStacksHandler("belt");
if (!belt.isPresent())
for (var curio : curiosHandler.getCurios().keySet()) {
var stack = getSatchelItemFromSlot(curiosHandler, curio);
if (!stack.isEmpty()) {
return stack;
}
}
return ItemStack.EMPTY;
}

protected static ItemStack getSatchelItemFromSlot(ICuriosItemHandler curiosHandler, String identifier) {
ICurioStacksHandler slotHandler = curiosHandler.getStacksHandler(identifier).orElse(null);
if (slotHandler == null) {
return ItemStack.EMPTY;
}

IDynamicStackHandler stackHandler = belt.get().getStacks();
ItemStack hasBackpack = ItemStack.EMPTY;
IDynamicStackHandler stackHandler = slotHandler.getStacks();
for (int i = 0; i < stackHandler.getSlots(); i++) {
ItemStack stack = stackHandler.getStackInSlot(i);
if (stack.getItem() instanceof SatchelItem) {
hasBackpack = stack;
break;
return stack;
}
}
return hasBackpack;

return ItemStack.EMPTY;
}


public static SelectedCurio getStorageRemote(Player player) {
int selectedSlot = player.getInventory().selected;
ItemStack storageRemoteStack = player.getInventory().getSelected();
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/data/curios/slots/belt.json

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/resources/data/curios/slots/hands.json

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/resources/data/curios/slots/head.json

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/resources/data/curios/slots/ring.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"entities": [
"player"
],
"slots": [
"belt",
"hands",
"head",
"ring",
"belt"
]
}
4 changes: 4 additions & 0 deletions src/main/resources/data/occultism/curios/slots/belt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"render_toggle":true,
"size": 1
}
4 changes: 4 additions & 0 deletions src/main/resources/data/occultism/curios/slots/hands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"render_toggle":true,
"size": 2
}
4 changes: 4 additions & 0 deletions src/main/resources/data/occultism/curios/slots/head.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"render_toggle":true,
"size": 1
}
4 changes: 4 additions & 0 deletions src/main/resources/data/occultism/curios/slots/ring.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"render_toggle":true,
"size": 1
}q

0 comments on commit fbbe4ea

Please sign in to comment.