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);
}
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;
}
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()])));
}
}
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;
}
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]);
}
Aggregations