Search in sources :

Example 1 with InventoryComposite

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

the class PrototypeRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
    if (!matches(grid, null))
        return InvTools.emptyStack();
    InventoryComposite inv = InventoryComposite.of(grid);
    ItemStack container = inv.findOne(PROTOTYPE_CONTAINER);
    if (InvTools.isEmpty(container))
        return InvTools.emptyStack();
    ItemStack prototype = inv.findOne(validPrototype(container));
    if (!InvTools.isEmpty(prototype))
        return ((IPrototypedItem) container.getItem()).setPrototype(container, prototype);
    return InvTools.emptyStack();
}
Also used : InventoryComposite(mods.railcraft.common.util.inventory.InventoryComposite) ItemStack(net.minecraft.item.ItemStack)

Example 2 with InventoryComposite

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

the class PrototypeRecipe method matches.

@Override
public boolean matches(InventoryCrafting grid, @Nullable World world) {
    InventoryComposite inv = InventoryComposite.of(grid);
    int containerStacks = inv.countStacks(PROTOTYPE_CONTAINER);
    if (containerStacks != 1)
        return false;
    ItemStack container = inv.findOne(PROTOTYPE_CONTAINER);
    return !InvTools.isEmpty(container) && inv.countStacks(validPrototype(container)) == 1;
}
Also used : InventoryComposite(mods.railcraft.common.util.inventory.InventoryComposite) ItemStack(net.minecraft.item.ItemStack)

Example 3 with InventoryComposite

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

the class IcemanBackpack method manageSnow.

private void manageSnow(IInventory backpackInventory) {
    InventoryComposite inv = InventoryComposite.of(backpackInventory);
    if (inv.hasItems()) {
        int numSnowballs = inv.countItems(SNOWBALL_MATCHER);
        while (numSnowballs > 16 && inv.canFit(SNOW_BLOCK) && inv.removeItems(4, SNOWBALL_MATCHER)) {
            inv.addStack(new ItemStack(Blocks.SNOW));
            numSnowballs -= 4;
        }
        while (numSnowballs < 8 && inv.canFit(new ItemStack(Items.SNOWBALL, 4)) && inv.removeItems(1, SNOW_BLOCK_MATCHER)) {
            inv.addStack(new ItemStack(Items.SNOWBALL, 4));
            numSnowballs += 4;
        }
    }
}
Also used : InventoryComposite(mods.railcraft.common.util.inventory.InventoryComposite) ItemStack(net.minecraft.item.ItemStack)

Example 4 with InventoryComposite

use of mods.railcraft.common.util.inventory.InventoryComposite 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 5 with InventoryComposite

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

the class TileFeedStation method update.

@Override
public void update() {
    super.update();
    if (Game.isClient(getWorld())) {
        return;
    }
    ItemStack feed = getStackInSlot(0);
    if (clock % (MIN_FEED_INTERVAL / 4) == 0 && (feed.isEmpty() || sizeOf(feed) < feed.getMaxStackSize())) {
        InventoryComposite chests = invCache.getAdjacentInventories();
        chests.moveOneItemTo(this, StackFilters.FEED);
    }
    feed = getStackInSlot(0);
    feedTime--;
    if (!powered && !InvTools.isEmpty(feed) && feedTime <= 0) {
        feedTime = MIN_FEED_INTERVAL + rand.nextInt(FEED_VARIANCE);
        // TODO: test (maybe we can draw this somehow?)
        AxisAlignedBB box = AABBFactory.start().createBoxForTileAt(getPos()).raiseFloor(-1).raiseCeiling(2).expandHorizontally(AREA).build();
        List<EntityAnimal> animals = world.getEntitiesWithinAABB(EntityAnimal.class, box);
        for (EntityAnimal target : animals) {
            if (target.isBreedingItem(getStackInSlot(0)) && feedAnimal(target)) {
                if (feedCounter <= 0) {
                    setInventorySlotContents(0, InvTools.depleteItem(feed));
                    feedCounter = ANIMALS_PER_FOOD;
                }
                feedCounter--;
                sendFeedPacket(target);
                break;
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ItemStack(net.minecraft.item.ItemStack) InventoryComposite(mods.railcraft.common.util.inventory.InventoryComposite) EntityAnimal(net.minecraft.entity.passive.EntityAnimal)

Aggregations

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