Skip to content

Commit

Permalink
Fix item_handler capability returning empty client-side, closes #363
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIllusiveC4 committed Jan 24, 2024
1 parent 4742a32 commit 3efbce4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package top.theillusivec4.curios.common.capability;

import java.util.Map;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.ItemStackHandler;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.wrapper.CombinedInvWrapper;
import org.jetbrains.annotations.NotNull;
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
import top.theillusivec4.curios.common.CuriosRegistry;

public class CurioItemHandler implements IItemHandler {
Expand All @@ -15,12 +18,18 @@ public class CurioItemHandler implements IItemHandler {
public CurioItemHandler(final LivingEntity livingEntity) {
this.livingEntity = livingEntity;
CurioInventory inv = livingEntity.getData(CuriosRegistry.INVENTORY.get());
Map<String, ICurioStacksHandler> curios = inv.curios;
IItemHandlerModifiable[] itemHandlers = new IItemHandlerModifiable[curios.size()];
int index = 0;

if (inv.curiosItemHandler != null) {
this.curios = inv.curiosItemHandler.getEquippedCurios();
} else {
this.curios = new ItemStackHandler();
for (ICurioStacksHandler stacksHandler : curios.values()) {

if (index < itemHandlers.length) {
itemHandlers[index] = stacksHandler.getStacks();
index++;
}
}
this.curios = new CombinedInvWrapper(itemHandlers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
import net.neoforged.neoforge.event.entity.player.PlayerXpEvent;
import net.neoforged.neoforge.event.level.BlockEvent;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import net.neoforged.neoforge.network.PacketDistributor;
import top.theillusivec4.curios.CuriosConstants;
import top.theillusivec4.curios.api.CuriosApi;
import top.theillusivec4.curios.api.SlotAttribute;
import top.theillusivec4.curios.api.SlotContext;
Expand Down

0 comments on commit 3efbce4

Please sign in to comment.