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