net.minecraft.block.LeavesBlock Java Examples

The following examples show how to use net.minecraft.block.LeavesBlock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OxygenCollectorBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private int collectOxygen(BlockPos center) {
    Optional<CelestialBodyType> celestialBodyType = CelestialBodyType.getByDimType(world.getRegistryKey());

    if (celestialBodyType.isPresent()) {
        if (celestialBodyType.get().getAtmosphere().getComposition().containsKey(AtmosphericGas.OXYGEN)) {
            int minX = center.getX() - 5;
            int minY = center.getY() - 5;
            int minZ = center.getZ() - 5;
            int maxX = center.getX() + 5;
            int maxY = center.getY() + 5;
            int maxZ = center.getZ() + 5;

            float leafBlocks = 0;

            for (BlockPos pos : BlockPos.iterate(minX, minY, minZ, maxX, maxY, maxZ)) {
                BlockState blockState = world.getBlockState(pos);
                if (blockState.isAir()) {
                    continue;
                }
                if (blockState.getBlock() instanceof LeavesBlock && !blockState.get(LeavesBlock.PERSISTENT)) {
                    leafBlocks++;
                } else if (blockState.getBlock() instanceof CropBlock) {
                    leafBlocks += 0.75F;
                }
            }

            if (leafBlocks < 2) return 0;

            double oxyCount = 20 * (leafBlocks / 14.0F);
            return (int) Math.ceil(oxyCount) / 20; //every tick
        } else {
            return 183 / 20;
        }
    } else {
        return 183 / 20;
    }
}