Search in sources :

Example 1 with IInventoryManager

use of powercrystals.core.inventory.IInventoryManager in project MineFactoryReloaded by powercrystals.

the class BlockRailCargoPickup method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !(entity instanceof EntityMinecartContainer)) {
        return;
    }
    IInventoryManager minecart = InventoryManager.create((EntityMinecartContainer) entity, ForgeDirection.UNKNOWN);
    for (Entry<ForgeDirection, IInventory> inventory : UtilInventory.findChests(world, x, y, z).entrySet()) {
        IInventoryManager chest = InventoryManager.create(inventory.getValue(), inventory.getKey().getOpposite());
        for (Entry<Integer, ItemStack> contents : chest.getContents().entrySet()) {
            if (contents.getValue() == null) {
                continue;
            }
            ItemStack stackToAdd = contents.getValue().copy();
            ItemStack remaining = minecart.addItem(stackToAdd);
            if (remaining != null) {
                stackToAdd.stackSize -= remaining.stackSize;
                if (stackToAdd.stackSize > 0) {
                    chest.removeItem(stackToAdd.stackSize, stackToAdd);
                }
            } else {
                chest.removeItem(stackToAdd.stackSize, stackToAdd);
                break;
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) EntityMinecartContainer(net.minecraft.entity.item.EntityMinecartContainer) ForgeDirection(net.minecraftforge.common.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Example 2 with IInventoryManager

use of powercrystals.core.inventory.IInventoryManager in project MineFactoryReloaded by powercrystals.

the class TileEntityBreeder method activateMachine.

@Override
protected boolean activateMachine() {
    List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
    IInventoryManager manager = InventoryManager.create(this, ForgeDirection.UNKNOWN);
    if (entities.size() > MFRConfig.breederShutdownThreshold.getInt()) {
        setIdleTicks(getIdleTicksMax());
        return false;
    }
    for (Object o : entities) {
        if (o instanceof EntityAnimal) {
            EntityAnimal a = ((EntityAnimal) o);
            List<ItemStack> foodList;
            if (MFRRegistry.getBreederFoods().containsKey(a.getClass())) {
                foodList = MFRRegistry.getBreederFoods().get(a.getClass());
            } else {
                foodList = new ArrayList<ItemStack>();
                foodList.add(new ItemStack(Item.wheat));
            }
            for (ItemStack food : foodList) {
                int stackIndex = manager.findItem(food);
                if (stackIndex < 0) {
                    continue;
                }
                if (!a.isInLove() && a.getGrowingAge() == 0) {
                    a.inLove = 600;
                    decrStackSize(stackIndex, 1);
                    for (int var3 = 0; var3 < 7; ++var3) {
                        double var4 = a.getRNG().nextGaussian() * 0.02D;
                        double var6 = a.getRNG().nextGaussian() * 0.02D;
                        double var8 = a.getRNG().nextGaussian() * 0.02D;
                        this.worldObj.spawnParticle("heart", a.posX + a.getRNG().nextFloat() * a.width * 2.0F - a.width, a.posY + 0.5D + a.getRNG().nextFloat() * a.height, a.posZ + a.getRNG().nextFloat() * a.width * 2.0F - a.width, var4, var6, var8);
                    }
                    return true;
                }
            }
        }
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : EntityAnimal(net.minecraft.entity.passive.EntityAnimal) ItemStack(net.minecraft.item.ItemStack) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Example 3 with IInventoryManager

use of powercrystals.core.inventory.IInventoryManager in project MineFactoryReloaded by powercrystals.

the class BlockRailCargoDropoff method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (world.isRemote || !(entity instanceof EntityMinecartContainer)) {
        return;
    }
    IInventoryManager minecart = InventoryManager.create((EntityMinecartContainer) entity, ForgeDirection.UNKNOWN);
    for (Entry<Integer, ItemStack> contents : minecart.getContents().entrySet()) {
        if (contents.getValue() == null) {
            continue;
        }
        ItemStack stackToAdd = contents.getValue().copy();
        ItemStack remaining = UtilInventory.dropStack(world, new BlockPosition(x, y, z), contents.getValue(), ForgeDirection.VALID_DIRECTIONS, ForgeDirection.UNKNOWN);
        if (remaining != null) {
            stackToAdd.stackSize -= remaining.stackSize;
        }
        minecart.removeItem(stackToAdd.stackSize, stackToAdd);
    }
}
Also used : EntityMinecartContainer(net.minecraft.entity.item.EntityMinecartContainer) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Example 4 with IInventoryManager

use of powercrystals.core.inventory.IInventoryManager in project MineFactoryReloaded by powercrystals.

the class RanchableCow method ranch.

@Override
public List<ItemStack> ranch(World world, EntityLiving entity, IInventory rancher) {
    List<ItemStack> drops = new LinkedList<ItemStack>();
    IInventoryManager manager = InventoryManager.create(rancher, ForgeDirection.UP);
    int bucketIndex = manager.findItem(new ItemStack(Item.bucketEmpty));
    if (bucketIndex >= 0) {
        drops.add(new ItemStack(Item.bucketMilk));
        rancher.decrStackSize(bucketIndex, 1);
    } else {
        LiquidStack milk = LiquidDictionary.getLiquid("milk", 1000);
        drops.add(new ItemStack(milk.itemID, 1, milk.itemMeta));
    }
    return drops;
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Example 5 with IInventoryManager

use of powercrystals.core.inventory.IInventoryManager in project MineFactoryReloaded by powercrystals.

the class RanchableMooshroom method ranch.

@Override
public List<ItemStack> ranch(World world, EntityLiving entity, IInventory rancher) {
    List<ItemStack> drops = new LinkedList<ItemStack>();
    IInventoryManager manager = InventoryManager.create(rancher, ForgeDirection.UP);
    int bowlIndex = manager.findItem(new ItemStack(Item.bowlEmpty));
    if (bowlIndex >= 0) {
        drops.add(new ItemStack(Item.bowlSoup));
        rancher.decrStackSize(bowlIndex, 1);
    }
    int bucketIndex = manager.findItem(new ItemStack(Item.bucketEmpty));
    if (bucketIndex >= 0) {
        drops.add(new ItemStack(Item.bucketMilk));
        rancher.setInventorySlotContents(bucketIndex, null);
    } else {
        LiquidStack soup = LiquidDictionary.getLiquid("mushroomsoup", 1000);
        drops.add(new ItemStack(soup.itemID, 1, soup.itemMeta));
    }
    return drops;
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList) IInventoryManager(powercrystals.core.inventory.IInventoryManager)

Aggregations

ItemStack (net.minecraft.item.ItemStack)5 IInventoryManager (powercrystals.core.inventory.IInventoryManager)5 LinkedList (java.util.LinkedList)2 EntityMinecartContainer (net.minecraft.entity.item.EntityMinecartContainer)2 LiquidStack (net.minecraftforge.liquids.LiquidStack)2 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)1 IInventory (net.minecraft.inventory.IInventory)1 ForgeDirection (net.minecraftforge.common.ForgeDirection)1 BlockPosition (powercrystals.core.position.BlockPosition)1