Search in sources :

Example 1 with InventoryAdvanced

use of mods.railcraft.common.util.inventory.InventoryAdvanced in project Railcraft by Railcraft.

the class InventoryTest method buildAdapters.

@Test
void buildAdapters() {
    InventoryComposite invBasic = InventoryComposite.of(new InventoryBasic("Test", true, 4));
    testComposite("InventoryBasic", invBasic);
    InventoryComposite invAdvanced = InventoryComposite.of(new InventoryAdvanced(4));
    testComposite("InventoryAdvanced", invAdvanced);
    InventoryComposite invCap = InventoryComposite.of(new ICapabilityProvider() {

        @Override
        public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
            return true;
        }

        @Override
        public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
            // noinspection unchecked
            return (T) new InvWrapper(new InventoryAdvanced(4));
        }
    });
    testComposite("IItemHandler", invCap);
}
Also used : ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) EnumFacing(net.minecraft.util.EnumFacing) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryAdvanced(mods.railcraft.common.util.inventory.InventoryAdvanced) InventoryComposite(mods.railcraft.common.util.inventory.InventoryComposite) IInventoryComposite(mods.railcraft.common.util.inventory.IInventoryComposite) InventoryBasic(net.minecraft.inventory.InventoryBasic) Test(org.junit.jupiter.api.Test)

Example 2 with InventoryAdvanced

use of mods.railcraft.common.util.inventory.InventoryAdvanced in project Railcraft by Railcraft.

the class InventoryTest method canFit.

@Test
void canFit() {
    ItemStack stackFull = new ItemStack(Items.APPLE, 64);
    InventoryAdvanced invFull = new InventoryAdvanced(1);
    invFull.addStack(stackFull);
    InventoryAdvanced invRoom = new InventoryAdvanced(2);
    invRoom.addStack(stackFull);
    invRoom.addStack(new ItemStack(Items.CARROT, 63));
    ItemStack stackApple = new ItemStack(Items.APPLE);
    ItemStack stackCarrot = new ItemStack(Items.CARROT);
    Assertions.assertFalse(invFull.canFit(stackApple));
    Assertions.assertFalse(invFull.canFit(stackCarrot));
    Assertions.assertFalse(invRoom.canFit(stackApple));
    Assertions.assertTrue(invRoom.canFit(stackCarrot));
}
Also used : InventoryAdvanced(mods.railcraft.common.util.inventory.InventoryAdvanced) ItemStack(net.minecraft.item.ItemStack) Test(org.junit.jupiter.api.Test)

Example 3 with InventoryAdvanced

use of mods.railcraft.common.util.inventory.InventoryAdvanced in project Railcraft by Railcraft.

the class InventoryTest method removeOneItem.

@Test
void removeOneItem() {
    ItemStack stack = new ItemStack(Items.APPLE, 32);
    InventoryAdvanced inv = new InventoryAdvanced(6);
    inv.setInventorySlotContents(3, stack);
    ItemStack result = inv.removeOneItem(StackFilters.of(Items.APPLE));
    Assertions.assertEquals(1, result.getCount());
    Assertions.assertEquals(31, inv.countItems());
}
Also used : InventoryAdvanced(mods.railcraft.common.util.inventory.InventoryAdvanced) ItemStack(net.minecraft.item.ItemStack) Test(org.junit.jupiter.api.Test)

Example 4 with InventoryAdvanced

use of mods.railcraft.common.util.inventory.InventoryAdvanced in project Railcraft by Railcraft.

the class InventoryTest method addStack.

@Test
void addStack() {
    ItemStack stack = new ItemStack(Items.APPLE, 32);
    InventoryAdvanced inv = new InventoryAdvanced(6);
    ItemStack resultStack = inv.addStack(stack);
    Assertions.assertTrue(resultStack.isEmpty());
    Assertions.assertTrue(inv.contains(stack));
}
Also used : InventoryAdvanced(mods.railcraft.common.util.inventory.InventoryAdvanced) ItemStack(net.minecraft.item.ItemStack) Test(org.junit.jupiter.api.Test)

Example 5 with InventoryAdvanced

use of mods.railcraft.common.util.inventory.InventoryAdvanced in project Railcraft by Railcraft.

the class InventoryTest method removeItems.

@Test
void removeItems() {
    ItemStack stack = new ItemStack(Items.APPLE, 32);
    InventoryAdvanced inv = new InventoryAdvanced(6);
    inv.setInventorySlotContents(3, stack);
    Assertions.assertTrue(inv.removeItems(8, StackFilters.of(Items.APPLE)));
    Assertions.assertFalse(inv.removeItems(8, StackFilters.of(Items.CARROT)));
    Assertions.assertEquals(24, inv.countItems());
}
Also used : InventoryAdvanced(mods.railcraft.common.util.inventory.InventoryAdvanced) ItemStack(net.minecraft.item.ItemStack) Test(org.junit.jupiter.api.Test)

Aggregations

InventoryAdvanced (mods.railcraft.common.util.inventory.InventoryAdvanced)6 Test (org.junit.jupiter.api.Test)6 ItemStack (net.minecraft.item.ItemStack)5 IInventoryComposite (mods.railcraft.common.util.inventory.IInventoryComposite)1 InventoryComposite (mods.railcraft.common.util.inventory.InventoryComposite)1 InventoryBasic (net.minecraft.inventory.InventoryBasic)1 EnumFacing (net.minecraft.util.EnumFacing)1 ICapabilityProvider (net.minecraftforge.common.capabilities.ICapabilityProvider)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1