test Skyblock
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// Zielpfad: src/main/java/ovh/glitchlabs/ornamentum/client/ClientSkyboxTracker.java
|
||||
package ovh.glitchlabs.ornamentum.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import ovh.glitchlabs.ornamentum.blocks.entity.SkyboxBlockEntity;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ClientSkyboxTracker {
|
||||
|
||||
private static final Set<BlockPos> POSITIONS = ConcurrentHashMap.newKeySet();
|
||||
private static final int FADE_DISTANCE = 12;
|
||||
|
||||
public static void register(BlockPos pos) {
|
||||
POSITIONS.add(pos);
|
||||
}
|
||||
|
||||
public static void unregister(BlockPos pos) {
|
||||
POSITIONS.remove(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bündelt alle für das Rendering relevanten Werte des aktuell "gewinnenden"
|
||||
* (nächstgelegenen, aktivsten) Skybox-Blocks.
|
||||
*/
|
||||
public record ActiveSkybox(float blend, int colorIndex, boolean starsEnabled, int texturePreset) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null, wenn kein Skybox-Block in Reichweite ist, sonst die Werte
|
||||
* des Blocks mit dem stärksten Überblend-Faktor.
|
||||
*/
|
||||
public static ActiveSkybox getActive() {
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
ClientLevel level = Minecraft.getInstance().level;
|
||||
if (player == null || level == null || POSITIONS.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ActiveSkybox best = null;
|
||||
float bestBlend = 0f;
|
||||
|
||||
for (BlockPos pos : POSITIONS) {
|
||||
if (!(level.getBlockEntity(pos) instanceof SkyboxBlockEntity be)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double dist = Math.sqrt(player.blockPosition().distSqr(pos));
|
||||
int range = be.getRange();
|
||||
if (dist >= range) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float blend = dist <= range - FADE_DISTANCE
|
||||
? 1f
|
||||
: (float) ((range - dist) / FADE_DISTANCE);
|
||||
|
||||
if (blend > bestBlend) {
|
||||
bestBlend = blend;
|
||||
best = new ActiveSkybox(blend, be.getColorIndex(), be.isStarsEnabled(), be.getTexturePreset());
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user