Search in sources :

Example 46 with NNList

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

the class PlantableFarmer method harvestBlock.

@Override
public IHarvestResult harvestBlock(@Nonnull IFarmer farm, @Nonnull final BlockPos pos, @Nonnull Block block, @Nonnull IBlockState meta) {
    if (!canHarvest(farm, pos, block, meta)) {
        return null;
    }
    if (!farm.hasTool(FarmingTool.HOE)) {
        farm.setNotification(FarmNotification.NO_HOE);
        return null;
    }
    final World world = farm.getWorld();
    final NNList<EntityItem> result = new NNList<EntityItem>();
    final EntityPlayerMP fakePlayer = farm.startUsingItem(FarmingTool.HOE);
    final int fortune = farm.getLootingValue(FarmingTool.HOE);
    ItemStack removedPlantable = Prep.getEmpty();
    NNList<ItemStack> drops = new NNList<>();
    block.getDrops(drops, world, pos, meta, fortune);
    float chance = ForgeEventFactory.fireBlockHarvesting(drops, world, pos, meta, fortune, 1.0F, false, fakePlayer);
    farm.registerAction(FarmingAction.HARVEST, FarmingTool.HOE, meta, pos);
    for (ItemStack stack : drops) {
        if (stack != null && Prep.isValid(stack) && world.rand.nextFloat() <= chance) {
            if (Prep.isInvalid(removedPlantable) && isPlantableForBlock(stack, block)) {
                removedPlantable = stack.copy();
                removedPlantable.setCount(1);
                stack.shrink(1);
            }
            if (Prep.isValid(stack)) {
                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 (Prep.isValid(removedPlantable)) {
        if (!plant(farm, world, pos, (IPlantable) removedPlantable.getItem())) {
            result.add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, removedPlantable.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) IPlantable(net.minecraftforge.common.IPlantable) 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 47 with NNList

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

the class StemFarmer method harvestBlock.

@Override
public IHarvestResult harvestBlock(@Nonnull final IFarmer farm, @Nonnull final BlockPos bc, @Nonnull Block block, @Nonnull IBlockState meta) {
    boolean hasHoe = farm.hasTool(FarmingTool.HOE);
    if (!hasHoe) {
        return new HarvestResult();
    }
    final World world = farm.getWorld();
    final EntityPlayerMP joe = farm.startUsingItem(FarmingTool.HOE);
    final int fortune = farm.getLootingValue(FarmingTool.HOE);
    final HarvestResult result = new HarvestResult();
    BlockPos harvestCoord = bc;
    boolean done = false;
    do {
        harvestCoord = harvestCoord.offset(EnumFacing.UP);
        final IBlockState harvestState = farm.getBlockState(harvestCoord);
        if (hasHoe && plantedBlock == harvestState.getBlock()) {
            result.getHarvestedBlocks().add(harvestCoord);
            NNList<ItemStack> drops = new NNList<>();
            plantedBlock.getDrops(drops, world, harvestCoord, meta, fortune);
            float chance = ForgeEventFactory.fireBlockHarvesting(drops, joe.world, harvestCoord, meta, fortune, 1.0F, false, joe);
            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.registerAction(FarmingAction.HARVEST, FarmingTool.HOE, harvestState, harvestCoord);
            hasHoe = farm.hasTool(FarmingTool.HOE);
        } else {
            if (!hasHoe) {
                farm.setNotification(FarmNotification.NO_HOE);
            }
            done = true;
        }
    } while (!done);
    NNList.wrap(farm.endUsingItem(FarmingTool.HOE)).apply(new Callback<ItemStack>() {

        @Override
        public void apply(@Nonnull ItemStack drop) {
            result.getDrops().add(new EntityItem(world, bc.getX() + 0.5, bc.getY() + 0.5, bc.getZ() + 0.5, drop.copy()));
        }
    });
    NNList<BlockPos> toClear = new NNList<BlockPos>(result.getHarvestedBlocks());
    Collections.sort(toClear, COMP);
    toClear.apply(new Callback<BlockPos>() {

        @Override
        public void apply(@Nonnull BlockPos coord) {
            farm.getWorld().setBlockToAir(coord);
        }
    });
    return result;
}
Also used : IHarvestResult(crazypants.enderio.api.farm.IHarvestResult) IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) NNList(com.enderio.core.common.util.NNList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 48 with NNList

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

the class Slicing method register.

@Override
public void register(@Nonnull String recipeName) {
    if (isValid() && isActive()) {
        NNList<IRecipeInput> inputStacks = new NNList<>();
        for (NNIterator<Item> itr = inputs.fastIterator(); itr.hasNext(); ) {
            final Item item = itr.next();
            inputStacks.add(new ThingsRecipeInput(item.getThing(), inputStacks.size()));
        }
        RecipeOutput recipeOutput = new RecipeOutput(getOutput().getItemStack());
        SliceAndSpliceRecipeManager.getInstance().addRecipe(new Recipe(recipeOutput, energy, RecipeBonusType.NONE, inputStacks.toArray(new IRecipeInput[inputStacks.size()])));
    }
}
Also used : IRecipeInput(crazypants.enderio.base.recipe.IRecipeInput) Recipe(crazypants.enderio.base.recipe.Recipe) NNList(com.enderio.core.common.util.NNList) RecipeOutput(crazypants.enderio.base.recipe.RecipeOutput) ThingsRecipeInput(crazypants.enderio.base.recipe.ThingsRecipeInput)

Example 49 with NNList

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

the class EnchanterRecipe method getQuantitiesConsumed.

@Override
@Nonnull
public NNList<MachineRecipeInput> getQuantitiesConsumed(@Nonnull NNList<MachineRecipeInput> inputs) {
    ItemStack slot0 = MachineRecipeInput.getInputForSlot(0, inputs).copy();
    ItemStack slot1 = MachineRecipeInput.getInputForSlot(1, inputs).copy();
    ItemStack slot2 = MachineRecipeInput.getInputForSlot(2, inputs).copy();
    int level = getLevelForStackSize(slot1.getCount());
    slot0.setCount(1);
    slot1.setCount(stackSizePerLevel * level);
    slot2.setCount(getLapizForLevel(level));
    NNList<MachineRecipeInput> result = new NNList<MachineRecipeInput>();
    result.add(new MachineRecipeInput(0, slot0));
    result.add(new MachineRecipeInput(1, slot1));
    result.add(new MachineRecipeInput(2, slot2));
    return result;
}
Also used : NNList(com.enderio.core.common.util.NNList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 50 with NNList

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

the class PoweredTask method getCompletedResult.

@Override
@Nonnull
public ResultStack[] getCompletedResult() {
    Random rand = new Random(nextSeed);
    NNList<ResultStack> result = new NNList<>();
    result.addAll(recipe.getCompletedResult(rand.nextLong(), getBonusType().doChances() ? chanceMultiplier : 1f, inputs));
    if (getBonusType().doMultiply()) {
        float mul = outputMultiplier - 1f;
        while (mul > 0) {
            if (rand.nextFloat() < mul) {
                result.addAll(recipe.getCompletedResult(rand.nextLong(), getBonusType().doChances() ? chanceMultiplier : 1f, inputs));
            }
            mul--;
        }
    }
    return result.toArray(new ResultStack[0]);
}
Also used : Random(java.util.Random) ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) NNList(com.enderio.core.common.util.NNList) Nonnull(javax.annotation.Nonnull)

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