mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 10:00:54 +01:00
RocketEntity added. Uses RocketRenderer and RocketStructure to render blocks. RocketStructure supports volumes up to 128^3.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package net.xevianlight.aphelion.planet;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.xevianlight.aphelion.Aphelion;
|
||||
import net.xevianlight.aphelion.client.dimension.DimensionRenderer;
|
||||
import net.xevianlight.aphelion.util.Constants;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AphelionPlanetJSONLoader extends SimpleJsonResourceReloadListener {
|
||||
|
||||
public AphelionPlanetJSONLoader() {
|
||||
super(Constants.GSON, "planet");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply(Map<ResourceLocation, JsonElement> object,
|
||||
ResourceManager resourceManager,
|
||||
ProfilerFiller profiler) {
|
||||
|
||||
Map<ResourceLocation, Planet> planets = new HashMap<>();
|
||||
object.forEach((key, value) -> {
|
||||
JsonObject json = GsonHelper.convertToJsonObject(value, "planet");
|
||||
Planet planet = Planet.CODEC.parse(JsonOps.INSTANCE, json).getOrThrow();
|
||||
|
||||
// IMPORTANT: use the *resource id* of the json as the lookup key
|
||||
// so "effects": "aphelion:space" maps to space.json automatically.
|
||||
planets.put(key, planet);
|
||||
});
|
||||
|
||||
Aphelion.LOGGER.info("Loaded planets " + planets);
|
||||
|
||||
PlanetCache.registerPlanets(planets);
|
||||
}
|
||||
}
|
||||
21
src/main/java/net/xevianlight/aphelion/planet/Planet.java
Normal file
21
src/main/java/net/xevianlight/aphelion/planet/Planet.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.xevianlight.aphelion.planet;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.xevianlight.aphelion.util.registries.ModRegistries;
|
||||
|
||||
public record Planet(
|
||||
ResourceKey<Level> dimension,
|
||||
double orbitDistance,
|
||||
ResourceKey<StarSystem> system
|
||||
) {
|
||||
public static final Codec<Planet> CODEC = RecordCodecBuilder.create(inst -> inst.group(
|
||||
ResourceKey.codec(Registries.DIMENSION).fieldOf("dimension").forGetter(Planet::dimension),
|
||||
Codec.DOUBLE.fieldOf("orbit_distance").forGetter(Planet::orbitDistance),
|
||||
ResourceKey.codec(ModRegistries.STAR_SYSTEM).fieldOf("star_system").forGetter(Planet::system)
|
||||
|
||||
).apply(inst, Planet::new));
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.xevianlight.aphelion.planet;
|
||||
|
||||
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 net.xevianlight.aphelion.util.registries.ModRegistries;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class PlanetCache {
|
||||
|
||||
public static final Map<ResourceLocation, Planet> PLANETS = new HashMap<>();
|
||||
public static final Map<ResourceKey<Level>, ResourceLocation> PLANET_BY_DIMENSION = new HashMap<>();
|
||||
|
||||
public static final Planet DEFAULT = new Planet(
|
||||
ResourceKey.create(Registries.DIMENSION, ResourceLocation.withDefaultNamespace("overworld")),
|
||||
1,
|
||||
ResourceKey.create(ModRegistries.STAR_SYSTEM, Aphelion.id("sol"))
|
||||
);
|
||||
|
||||
public static void registerPlanets(Map<ResourceLocation, Planet> planets) {
|
||||
PLANETS.clear();
|
||||
PLANET_BY_DIMENSION.clear();
|
||||
|
||||
PLANETS.putAll(planets);
|
||||
|
||||
planets.forEach((planetId, planet) -> {
|
||||
var dim = planet.dimension();
|
||||
var prev = PLANET_BY_DIMENSION.put(dim, planetId);
|
||||
if (prev != null) {
|
||||
Aphelion.LOGGER.warn(
|
||||
"Dimension {} is claimed by multiple planets: {} and {}. Keeping latest: {}",
|
||||
dim.location(), prev, planetId, planetId
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Aphelion.LOGGER.info("Loaded {} planets; {} dimension mappings",
|
||||
PLANETS.size(), PLANET_BY_DIMENSION.size());
|
||||
}
|
||||
|
||||
public static Planet getOrDefault(ResourceLocation id) {
|
||||
return PLANETS.getOrDefault(id, DEFAULT);
|
||||
}
|
||||
|
||||
public static Planet getByDimensionOrNull(ResourceKey<Level> dimension) {
|
||||
ResourceLocation planetId = PLANET_BY_DIMENSION.get(dimension);
|
||||
return planetId == null ? null : PLANETS.get(planetId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.xevianlight.aphelion.planet;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
public record StarSystem(
|
||||
int temp
|
||||
) {
|
||||
public static final Codec<StarSystem> CODEC = RecordCodecBuilder.create(inst -> inst.group(
|
||||
Codec.INT.fieldOf("dimension").forGetter(StarSystem::temp)
|
||||
).apply(inst, StarSystem::new));
|
||||
}
|
||||
Reference in New Issue
Block a user