package net.minecraft.world.level; import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; public interface LevelHeightAccessor { int getHeight(); int getMinBuildHeight(); default int getMaxBuildHeight() { return this.getMinBuildHeight() + this.getHeight(); } default int getSectionsCount() { return this.getMaxSection() - this.getMinSection(); } default int getMinSection() { return SectionPos.blockToSectionCoord(this.getMinBuildHeight()); } default int getMaxSection() { return SectionPos.blockToSectionCoord(this.getMaxBuildHeight() - 1) + 1; } default boolean isOutsideBuildHeight(BlockPos pos) { return this.isOutsideBuildHeight(pos.getY()); } default boolean isOutsideBuildHeight(int y) { return y < this.getMinBuildHeight() || y >= this.getMaxBuildHeight(); } default int getSectionIndex(int y) { return this.getSectionIndexFromSectionY(SectionPos.blockToSectionCoord(y)); } default int getSectionIndexFromSectionY(int sectionIndex) { return sectionIndex - this.getMinSection(); } default int getSectionYFromSectionIndex(int sectionIndex) { return sectionIndex + this.getMinSection(); } static LevelHeightAccessor create(int minBuildHeight, int height) { return new LevelHeightAccessor() { @Override public int getHeight() { return height; } @Override public int getMinBuildHeight() { return minBuildHeight; } }; } }