com.yungnickyoung.minecraft.yungsapi.world.util.SurfaceHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of YungsApi-1.21-Fabric Show documentation
Show all versions of YungsApi-1.21-Fabric Show documentation
A common API for YUNG's Minecraft mods
The newest version!
package com.yungnickyoung.minecraft.yungsapi.world.util;
import net.minecraft.class_2246;
import net.minecraft.class_2265;
import net.minecraft.class_2338;
import net.minecraft.class_2350;
import net.minecraft.class_2680;
import net.minecraft.class_2791;
public class SurfaceHelper {
private SurfaceHelper() {} // Private constructor prevents instantiation
/**
* Returns the y-coordinate of the topmost non-air block at the given column position in the world.
* Returns 1 if somehow no non-air block is found.
*/
public static int getSurfaceHeight(class_2791 chunk, class_2265 pos) {
int maxY = chunk.method_31600() - 1;
class_2338.class_2339 blockPos = new class_2338.class_2339(pos.comp_638(), maxY, pos.comp_639());
// Edge case: blocks go all the way up to build height
if (chunk.method_8320(blockPos) != class_2246.field_10124.method_9564())
return maxY;
for (int y = maxY; y >= 0; y--) {
class_2680 blockState = chunk.method_8320(blockPos);
if (blockState != class_2246.field_10124.method_9564())
return y;
blockPos.method_10098(class_2350.field_11033);
}
return 1; // Surface somehow not found
}
}