Skip to content

Commit

Permalink
Fix crash when using Integrated Tunnels with chests
Browse files Browse the repository at this point in the history
Closes #169
  • Loading branch information
rubensworks committed Oct 16, 2024
1 parent 6ae7fba commit efdf7be
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import org.cyclops.colossalchests.blockentity.BlockEntityInterface;
import org.cyclops.commoncapabilities.api.capability.inventorystate.IInventoryState;
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
import org.cyclops.cyclopscore.inventory.IndexedInventoryCommon;
import org.cyclops.cyclopscore.inventory.IndexedSlotlessItemHandlerWrapper;
import org.cyclops.cyclopscore.inventory.SimpleInventory;
import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon;
import org.cyclops.cyclopscore.modcompat.ICompatInitializer;
import org.cyclops.cyclopscore.modcompat.IModCompat;
import org.cyclops.cyclopscore.modcompat.capabilities.CapabilityConstructorRegistry;
Expand Down Expand Up @@ -56,8 +57,11 @@ public BaseCapability<ISlotlessItemHandler, Direction> getCapability() {

@Override
public ICapabilityProvider<BlockEntityColossalChest, Direction, ISlotlessItemHandler> createProvider(BlockEntityType<BlockEntityColossalChest> capabilityKey) {
return (blockEntity, side) -> new IndexedSlotlessItemHandlerWrapper(new InvWrapper(blockEntity.getInventory()),
(IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference) blockEntity.getInventory());
return (blockEntity, side) -> {
IndexedInventoryCommon inv = (IndexedInventoryCommon) blockEntity.getInventory();
return new IndexedSlotlessItemHandlerWrapper(new InvWrapper(inv),
new InventoryIndexReferenceIndexedInventoryCommon(inv));
};
}
});
registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_INTERFACE::value,
Expand All @@ -73,7 +77,7 @@ public ICapabilityProvider<BlockEntityInterface, Direction, ISlotlessItemHandler
BlockEntityColossalChest core = blockEntity.getCore();
if (core != null) {
return new IndexedSlotlessItemHandlerWrapper(new InvWrapper(core.getInventory()),
(IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference) core.getInventory());
new InventoryIndexReferenceIndexedInventoryCommon((IndexedInventoryCommon) core.getInventory()));
}
return null;
};
Expand All @@ -90,7 +94,7 @@ public BaseCapability<IInventoryState, Direction> getCapability() {

@Override
public ICapabilityProvider<BlockEntityColossalChest, Direction, IInventoryState> createProvider(BlockEntityType<BlockEntityColossalChest> capabilityKey) {
return (blockEntity, side) -> () -> ((SimpleInventory) blockEntity.getInventory()).getState();
return (blockEntity, side) -> () -> ((SimpleInventoryCommon) blockEntity.getInventory()).getState();
}
});
registry.registerBlockEntity(RegistryEntries.BLOCK_ENTITY_INTERFACE::value,
Expand All @@ -105,7 +109,7 @@ public ICapabilityProvider<BlockEntityInterface, Direction, IInventoryState> cre
return (blockEntity, side) -> {
BlockEntityColossalChest core = blockEntity.getCore();
if (core != null) {
return () -> ((SimpleInventory) core.getInventory()).getState();
return () -> ((SimpleInventoryCommon) core.getInventory()).getState();
}
return null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.cyclops.colossalchests.modcompat;

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.cyclops.cyclopscore.inventory.IndexedInventoryCommon;
import org.cyclops.cyclopscore.inventory.IndexedSlotlessItemHandlerWrapper;

import java.util.Map;
import java.util.PrimitiveIterator;

/**
* @author rubensworks
*/
public class InventoryIndexReferenceIndexedInventoryCommon implements IndexedSlotlessItemHandlerWrapper.IInventoryIndexReference {

private final IndexedInventoryCommon inventory;

public InventoryIndexReferenceIndexedInventoryCommon(IndexedInventoryCommon inventory) {
this.inventory = inventory;
}

@Override
public int getInventoryReferenceStackLimit() {
return this.inventory.getInventoryReferenceStackLimit();
}

@Override
public Map<Item, Int2ObjectMap<ItemStack>> getIndex() {
return this.inventory.getIndex();
}

@Override
public PrimitiveIterator.OfInt getEmptySlots() {
return this.inventory.getEmptySlots();
}

@Override
public PrimitiveIterator.OfInt getNonEmptySlots() {
return this.inventory.getNonEmptySlots();
}
}

0 comments on commit efdf7be

Please sign in to comment.