Server side partition syncing and packets

This commit is contained in:
XevianLight
2026-01-17 13:48:58 -07:00
parent 79f3e2562e
commit 28639dae81
16 changed files with 666 additions and 11 deletions

View File

@@ -18,7 +18,6 @@ public record DimensionRenderer(
int sunriseColor,
int sunriseAngle,
boolean renderInRain,
boolean renderVoidFog,
double horizonHeight,
float clearColorScale
) {
@@ -32,7 +31,6 @@ public record DimensionRenderer(
Codec.INT.fieldOf("sunrise_color").forGetter(DimensionRenderer::sunriseColor),
Codec.INT.fieldOf("sunrise_angle").forGetter(DimensionRenderer::sunriseAngle),
Codec.BOOL.fieldOf("render_in_rain").forGetter(DimensionRenderer::renderInRain),
Codec.BOOL.fieldOf("render_void_fog").forGetter(DimensionRenderer::renderVoidFog),
Codec.DOUBLE.fieldOf("horizon_height").forGetter(DimensionRenderer::horizonHeight),
Codec.FLOAT.fieldOf("clear_color_scale").forGetter(DimensionRenderer::clearColorScale)
).apply(inst, DimensionRenderer::new));

View File

@@ -1,8 +1,10 @@
package net.xevianlight.aphelion.client.dimension;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.xevianlight.aphelion.Aphelion;
import java.util.HashMap;
import java.util.Map;
@@ -11,6 +13,20 @@ public final class DimensionRendererCache {
public static final Map<ResourceLocation, DimensionRenderer> RENDERERS = new HashMap<>();
public static final DimensionRenderer DEFAULT = new DimensionRenderer(
ResourceKey.create(Registries.DIMENSION, ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "space")),
false,
false,
false,
false,
true,
14180147,
0,
false,
63,
1
);
public static void registerPlanetRenderers(Map<ResourceLocation, DimensionRenderer> renderers) {
RENDERERS.clear();
RENDERERS.putAll(renderers);
@@ -18,6 +34,6 @@ public final class DimensionRendererCache {
}
public static DimensionRenderer getOrDefault(ResourceLocation id) {
return RENDERERS.getOrDefault(id, null);
return RENDERERS.getOrDefault(id, DEFAULT);
}
}

View File

@@ -1,11 +1,17 @@
package net.xevianlight.aphelion.client.dimension;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.DimensionSpecialEffects;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.phys.Vec3;
import net.xevianlight.aphelion.Aphelion;
import net.xevianlight.aphelion.client.PartitionClientState;
import net.xevianlight.aphelion.core.space.SpacePartitionSavedData;
import net.xevianlight.aphelion.util.SpacePartitionHelper;
import org.joml.Matrix4f;
public class SpaceSkyEffects extends DimensionSpecialEffects {
@@ -42,6 +48,7 @@ public class SpaceSkyEffects extends DimensionSpecialEffects {
@Override
public boolean isFoggyAt(int i, int i1) {
ResourceLocation id = orbitForPos(net.minecraft.client.Minecraft.getInstance()
.gameRenderer.getMainCamera().getPosition());
@@ -49,11 +56,19 @@ public class SpaceSkyEffects extends DimensionSpecialEffects {
}
public static ResourceLocation orbitForPos(Vec3 pos) {
double r = Math.sqrt(pos.x * pos.x + pos.z * pos.z);
if (r < 100) return ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "orbit/earth");
if (r < 200) return ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "orbit/mars");
if (r < 300) return ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "orbit/venus");
int x = SpacePartitionHelper.get(pos.x);
int z = SpacePartitionHelper.get(pos.z);
Minecraft mc = Minecraft.getInstance();
if (mc.level == null) return ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "orbit/default");
// int px = PartitionClientState.pxOr(0);
// int py = PartitionClientState.pyOr(0);
var data = ResourceLocation.parse(PartitionClientState.idOrUnknown());
// var data = SpacePartitionSavedData.get(serverLevel).getOrbitForPartition((int) x, (int) z);
if (data != null) return data;
return ResourceLocation.fromNamespaceAndPath(Aphelion.MOD_ID, "orbit/default");
}