Search in sources :

Example 6 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class ItemHelper method getValidItems.

@Nonnull
public static NNList<ItemStack> getValidItems() {
    final NNList<ItemStack> list = new NNList<ItemStack>();
    final NNList<ItemStack> sublist = new NNList<ItemStack>();
    for (final Item item : Item.REGISTRY) {
        item.getSubItems(CreativeTabs.SEARCH, sublist);
        sublist.apply(new Callback<ItemStack>() {

            @Override
            public void apply(@Nonnull ItemStack stack) {
                if (Prep.isInvalid(stack)) {
                    Log.error("The item " + item + " (" + item.getUnlocalizedName() + ") produces empty itemstacks in getSubItems()");
                } else if (stack.getItem() == Items.AIR) {
                    Log.error("The item " + item + " (" + item.getUnlocalizedName() + ") produces itemstacks without item in getSubItems()");
                } else {
                    list.add(stack);
                }
            }
        });
        sublist.clear();
    }
    return list;
}
Also used : Item(net.minecraft.item.Item) NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 7 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class ContainerWiredCharger method getValidPair.

public static NNList<Triple<ItemStack, ItemStack, Integer>> getValidPair(List<ItemStack> validItems) {
    NNList<Triple<ItemStack, ItemStack, Integer>> result = new NNList<>();
    for (ItemStack stack : validItems) {
        if (PowerHandlerUtil.getCapability(stack, null) != null) {
            ItemStack copy = stack.copy();
            IEnergyStorage emptyCap = PowerHandlerUtil.getCapability(copy, null);
            if (emptyCap != null) {
                int extracted = 1, maxloop = 200;
                while (extracted > 0 && emptyCap.canExtract() && maxloop-- > 0) {
                    extracted = emptyCap.extractEnergy(Integer.MAX_VALUE, false);
                }
                if (emptyCap.canReceive() && emptyCap.getEnergyStored() < emptyCap.getMaxEnergyStored()) {
                    ItemStack empty = copy.copy();
                    int added = emptyCap.receiveEnergy(Integer.MAX_VALUE, false);
                    int power = added;
                    maxloop = 200;
                    while (added > 0 && maxloop-- > 0) {
                        power += added = emptyCap.receiveEnergy(Integer.MAX_VALUE, false);
                    }
                    result.add(Triple.of(empty, copy, power));
                }
            }
        }
    }
    return result;
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) NNList(com.enderio.core.common.util.NNList) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) ItemStack(net.minecraft.item.ItemStack) Point(java.awt.Point)

Example 8 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class ChorusFarmer method doHarvest.

private void doHarvest(@Nonnull final IFarmer farm, @Nonnull final World world, @Nonnull IBlockState blockState, @Nonnull final BlockPos pos, int fortune, @Nonnull final HarvestResult result) {
    FakePlayer joe = farm.startUsingItem(FarmingTool.AXE);
    NNList<ItemStack> drops = new NNList<>();
    blockState.getBlock().getDrops(drops, world, pos, blockState, fortune);
    final float chance = ForgeEventFactory.fireBlockHarvesting(drops, world, pos, blockState, fortune, 1f, false, joe);
    // flowers drop here by spawning their drops into the world (joe's world captures those)
    blockState.getBlock().harvestBlock(joe.world, joe, pos, blockState, null, joe.getHeldItemMainhand());
    NNList.wrap(drops).apply(new Callback<ItemStack>() {

        @Override
        public void apply(@Nonnull ItemStack drop) {
            if (farm.getWorld().rand.nextFloat() <= chance) {
                result.getDrops().add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy()));
            }
        }
    });
    NNList.wrap(farm.endUsingItem(FarmingTool.AXE)).apply(new Callback<ItemStack>() {

        @Override
        public void apply(@Nonnull ItemStack drop) {
            result.getDrops().add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy()));
        }
    });
    farm.registerAction(FarmingAction.HARVEST, FarmingTool.AXE, blockState, pos);
    world.setBlockToAir(pos);
    result.getHarvestedBlocks().add(pos);
}
Also used : NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 9 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class CustomSeedFarmer method harvestBlock.

@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull final BlockPos pos, @Nonnull Block block, @Nonnull IBlockState state) {
    if (!canHarvest(farm, pos, block, state)) {
        return null;
    }
    if (!farm.hasTool(FarmingTool.HOE)) {
        farm.setNotification(FarmNotification.NO_HOE);
        return null;
    }
    final World world = farm.getWorld();
    final EntityPlayerMP joe = farm.startUsingItem(FarmingTool.HOE);
    final int fortune = farm.getLootingValue(FarmingTool.HOE);
    final NNList<EntityItem> result = new NNList<EntityItem>();
    NNList<ItemStack> drops = new NNList<>();
    block.getDrops(drops, world, pos, state, fortune);
    float chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, pos, state, fortune, 1.0F, false, joe);
    farm.registerAction(FarmingAction.HARVEST, FarmingTool.HOE, state, pos);
    boolean removed = false;
    for (ItemStack stack : drops) {
        if (world.rand.nextFloat() <= chance) {
            if (!removed && stack.isItemEqual(getSeeds())) {
                stack.shrink(1);
                removed = true;
                if (Prep.isValid(stack)) {
                    result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack.copy()));
                }
            } else {
                result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack.copy()));
            }
        }
    }
    NNList.wrap(farm.endUsingItem(FarmingTool.HOE)).apply(new Callback<ItemStack>() {

        @Override
        public void apply(@Nonnull ItemStack drop) {
            result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy()));
        }
    });
    if (removed) {
        if (!plant(farm, world, pos)) {
            result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, getSeeds().copy()));
            world.setBlockState(pos, Blocks.AIR.getDefaultState(), 1 | 2);
        }
    } else {
        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 1 | 2);
    }
    return new HarvestResult(result, pos);
}
Also used : IHarvestResult(crazypants.enderio.api.farm.IHarvestResult) World(net.minecraft.world.World) NNList(com.enderio.core.common.util.NNList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 10 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class TreeFarmer method harvestSingleBlock.

void harvestSingleBlock(@Nonnull IFarmer farm, @Nonnull final World world, @Nonnull final HarvestResult result, @Nonnull final BlockPos harvestPos) {
    float chance = 1.0F;
    NNList<ItemStack> drops = new NNList<>();
    final IBlockState state = farm.getBlockState(harvestPos);
    final Block blk = state.getBlock();
    if (blk instanceof IShearable && hasShears && ((shearCount / result.getHarvestedBlocks().size() + noShearingPercentage) < 100)) {
        drops.addAll(((IShearable) blk).onSheared(farm.getTool(FarmingTool.SHEARS), world, harvestPos, 0));
        shearCount += 100;
        farm.registerAction(FarmingAction.HARVEST, FarmingTool.SHEARS, state, harvestPos);
        hasShears = farm.hasTool(FarmingTool.SHEARS);
        if (!hasShears) {
            farm.setNotification(FarmNotification.NO_SHEARS);
        }
    } else {
        FarmingTool tool = isWood(blk) || !hasHoe ? FarmingTool.AXE : FarmingTool.HOE;
        blk.getDrops(drops, world, harvestPos, state, fortune);
        EntityPlayerMP joe = farm.startUsingItem(tool);
        chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, harvestPos, state, fortune, chance, false, joe);
        farm.registerAction(FarmingAction.HARVEST, tool, state, harvestPos);
        NNList.wrap(farm.endUsingItem(tool)).apply(new Callback<ItemStack>() {

            @Override
            public void apply(@Nonnull ItemStack drop) {
                result.getDrops().add(new EntityItem(world, harvestPos.getX() + 0.5, harvestPos.getY() + 0.5, harvestPos.getZ() + 0.5, drop.copy()));
            }
        });
        if (tool == FarmingTool.AXE) {
            hasAxe = farm.hasTool(FarmingTool.AXE);
            if (!hasAxe) {
                farm.setNotification(FarmNotification.NO_AXE);
            }
        } else {
            hasHoe = farm.hasTool(FarmingTool.HOE);
            if (!hasHoe) {
                farm.setNotification(FarmNotification.NO_HOE);
            }
        }
    }
    BlockPos farmPos = farm.getLocation();
    for (ItemStack drop : drops) {
        if (world.rand.nextFloat() <= chance) {
            result.getDrops().add(new EntityItem(world, farmPos.getX() + 0.5, farmPos.getY() + 0.5, farmPos.getZ() + 0.5, drop.copy()));
        }
    }
    farm.getWorld().setBlockToAir(harvestPos);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FarmingTool(crazypants.enderio.base.farming.FarmingTool) NNList(com.enderio.core.common.util.NNList) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

NNList (com.enderio.core.common.util.NNList)53 ItemStack (net.minecraft.item.ItemStack)37 Nonnull (javax.annotation.Nonnull)12 BlockPos (net.minecraft.util.math.BlockPos)8 EntityItem (net.minecraft.entity.item.EntityItem)7 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)5 Block (net.minecraft.block.Block)5 IBlockState (net.minecraft.block.state.IBlockState)5 IHarvestResult (crazypants.enderio.api.farm.IHarvestResult)4 ArrayList (java.util.ArrayList)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 GhostBackgroundItemSlot (com.enderio.core.client.gui.widget.GhostBackgroundItemSlot)3 Recipe (crazypants.enderio.base.recipe.Recipe)3 RecipeOutput (crazypants.enderio.base.recipe.RecipeOutput)3 ThingsRecipeInput (crazypants.enderio.base.recipe.ThingsRecipeInput)3 World (net.minecraft.world.World)3 Triple (org.apache.commons.lang3.tuple.Triple)3 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)2 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)2 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2