diff --git a/build.gradle.kts b/build.gradle.kts index ef79333b..f956ed79 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -112,6 +112,12 @@ repositories { includeGroup("dev.galacticraft") } } + maven("https://maven.galacticraft.net/repository/maven-snapshots/") { + name = "Galacticraft Repository" + content { + includeVersionByRegex("dev.galacticraft", ".*", ".*-SNAPSHOT") + } + } } dependencies { @@ -122,7 +128,7 @@ dependencies { modImplementation("net.fabricmc.fabric-api:fabric-api:$fabric") modImplementation("dev.galacticraft:MachineLib:$machinelib") -// modImplementation("dev.galacticraft:dyndims:$dyndims") + modImplementation("dev.galacticraft:dyndims:$dyndims") } tasks.processResources { diff --git a/gradle.properties b/gradle.properties index 68d20b46..6f31d976 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,9 +8,9 @@ mod.group=dev.galacticraft # Minecraft and Fabric Loader minecraft.version=1.19.2 -loader.version=0.14.9 +loader.version=0.14.10 # Mod Dependencies -fabric.version=0.60.0+1.19.2 +fabric.version=0.64.0+1.19.2 machinelib.version=0.1.0+98a0a4f3 -dyndims.version=0.3.0 +dyndims.version=0.4.0-SNAPSHOT diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/dev/galacticraft/api/accessor/ChunkSectionOxygenAccessor.java b/src/main/java/dev/galacticraft/api/accessor/ChunkSectionOxygenAccessor.java index 2e1068f4..4adb9d15 100644 --- a/src/main/java/dev/galacticraft/api/accessor/ChunkSectionOxygenAccessor.java +++ b/src/main/java/dev/galacticraft/api/accessor/ChunkSectionOxygenAccessor.java @@ -26,10 +26,26 @@ * @author TeamGalacticraft */ public interface ChunkSectionOxygenAccessor { + /** + * Returns whether the supplied position in this chunk section is breathable for entities + * + * @param x the position to test on the X-axis + * @param y the position to test on the Y-axis + * @param z the position to test on the Z-axis + * @return whether the supplied position in this chunk section is breathable for entities + */ default boolean isBreathable(int x, int y, int z) { throw new RuntimeException("This should be overridden by mixin!"); } + /** + * Sets the breathable state for entities for the supplied position + * + * @param x the position to test on the X-axis + * @param y the position to test on the Y-axis + * @param z the position to test on the Z-axis + * @param value whether the supplied position is breathable + */ default void setBreathable(int x, int y, int z, boolean value) { throw new RuntimeException("This should be overridden by mixin!"); } diff --git a/src/main/java/dev/galacticraft/api/accessor/SatelliteAccessor.java b/src/main/java/dev/galacticraft/api/accessor/SatelliteAccessor.java index 5fb183b8..4e50853c 100644 --- a/src/main/java/dev/galacticraft/api/accessor/SatelliteAccessor.java +++ b/src/main/java/dev/galacticraft/api/accessor/SatelliteAccessor.java @@ -23,15 +23,15 @@ package dev.galacticraft.api.accessor; import dev.galacticraft.api.universe.celestialbody.CelestialBody; -import dev.galacticraft.impl.universe.celestialbody.type.SatelliteType; -import dev.galacticraft.impl.universe.position.config.SatelliteConfig; +import dev.galacticraft.impl.universe.celestialbody.type.SpaceStationType; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; import java.util.Map; import net.minecraft.resources.ResourceLocation; public interface SatelliteAccessor { - Map> getSatellites(); + Map> getSatellites(); - void addSatellite(ResourceLocation id, CelestialBody satellite); + void addSatellite(ResourceLocation id, CelestialBody satellite); void removeSatellite(ResourceLocation id); } diff --git a/src/main/java/dev/galacticraft/api/client/accessor/ClientSatelliteAccessor.java b/src/main/java/dev/galacticraft/api/client/accessor/ClientSatelliteAccessor.java index f7a0326f..2853c031 100644 --- a/src/main/java/dev/galacticraft/api/client/accessor/ClientSatelliteAccessor.java +++ b/src/main/java/dev/galacticraft/api/client/accessor/ClientSatelliteAccessor.java @@ -24,8 +24,8 @@ import dev.galacticraft.api.accessor.SatelliteAccessor; import dev.galacticraft.api.universe.celestialbody.CelestialBody; -import dev.galacticraft.impl.universe.celestialbody.type.SatelliteType; -import dev.galacticraft.impl.universe.position.config.SatelliteConfig; +import dev.galacticraft.impl.universe.celestialbody.type.SpaceStationType; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -37,6 +37,6 @@ public interface ClientSatelliteAccessor extends SatelliteAccessor { @FunctionalInterface interface SatelliteListener { - void onSatelliteUpdated(CelestialBody satellite, boolean added); + void onSatelliteUpdated(CelestialBody satellite, boolean added); } } diff --git a/src/main/java/dev/galacticraft/api/data/CelestialBodyDataProvider.java b/src/main/java/dev/galacticraft/api/data/CelestialBodyDataProvider.java index 28070503..b342fe3e 100644 --- a/src/main/java/dev/galacticraft/api/data/CelestialBodyDataProvider.java +++ b/src/main/java/dev/galacticraft/api/data/CelestialBodyDataProvider.java @@ -29,7 +29,7 @@ import com.mojang.logging.LogUtils; import com.mojang.serialization.JsonOps; import dev.galacticraft.api.gas.GasComposition; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import dev.galacticraft.api.universe.display.CelestialDisplay; import dev.galacticraft.api.universe.galaxy.Galaxy; @@ -218,7 +218,7 @@ public class PlanetBuilder implements CelestialBuilder { private GasComposition atmosphere; private float gravity; private int accessWeight, dayTemperature, nightTemperature; - private Optional satelliteRecipe; + private Optional satelliteRecipe; PlanetBuilder(ResourceLocation key) { this.key = key; @@ -290,7 +290,7 @@ public PlanetBuilder nightTemperature(int nightTemperature) { return this; } - public PlanetBuilder satelliteRecipe(Optional satelliteRecipe) { + public PlanetBuilder satelliteRecipe(Optional satelliteRecipe) { this.satelliteRecipe = satelliteRecipe; return this; } diff --git a/src/main/java/dev/galacticraft/api/satellite/Satellite.java b/src/main/java/dev/galacticraft/api/satellite/Satellite.java index 0027c633..7e22519e 100644 --- a/src/main/java/dev/galacticraft/api/satellite/Satellite.java +++ b/src/main/java/dev/galacticraft/api/satellite/Satellite.java @@ -39,11 +39,11 @@ public interface Satellite { * @return the ownership data of this satellite * @see SatelliteOwnershipData */ - SatelliteOwnershipData ownershipData(C config); + SatelliteOwnershipData ownershipData(@NotNull C config); /** * Returns the custom name of this satellite - * By default it is {@code 's satellite} + * By default it is {@code [Player Name]'s satellite} * * @param config the satellite configuration to be queried * @return the custom name of this satellite @@ -56,5 +56,5 @@ public interface Satellite { * @param text the text to set * @param config the satellite configuration to be set */ - void setCustomName(@NotNull Component text, C config); + void setCustomName(@NotNull Component text, @NotNull C config); } diff --git a/src/main/java/dev/galacticraft/api/satellite/SatelliteRecipe.java b/src/main/java/dev/galacticraft/api/satellite/SpaceStationRecipe.java similarity index 88% rename from src/main/java/dev/galacticraft/api/satellite/SatelliteRecipe.java rename to src/main/java/dev/galacticraft/api/satellite/SpaceStationRecipe.java index f1fe6788..1f9e5298 100644 --- a/src/main/java/dev/galacticraft/api/satellite/SatelliteRecipe.java +++ b/src/main/java/dev/galacticraft/api/satellite/SpaceStationRecipe.java @@ -25,7 +25,7 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.*; import com.mojang.serialization.codecs.RecordCodecBuilder; -import dev.galacticraft.impl.satellite.SatelliteRecipeImpl; +import dev.galacticraft.impl.satellite.SpaceStationRecipeImpl; import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import org.jetbrains.annotations.Contract; @@ -35,7 +35,7 @@ import net.minecraft.world.Container; import net.minecraft.world.item.crafting.Ingredient; -public interface SatelliteRecipe extends Predicate { +public interface SpaceStationRecipe extends Predicate { Codec INGREDIENT_CODEC = new Codec<>() { @Override public DataResult encode(Ingredient input, DynamicOps ops, T prefix) { @@ -48,7 +48,7 @@ public DataResult> decode(DynamicOps ops, T input) { } }; - Codec CODEC = RecordCodecBuilder.create(i -> i.group( + Codec CODEC = RecordCodecBuilder.create(i -> i.group( new Codec>() { @Override public DataResult encode(Object2IntMap input, DynamicOps ops, T prefix) { @@ -64,12 +64,12 @@ public DataResult, T>> decode(DynamicOps o mapLike.entries().forEachOrdered(ttPair -> list.put(INGREDIENT_CODEC.decode(ops, ttPair.getFirst()).get().orThrow().getFirst(), ops.getNumberValue(ttPair.getSecond()).get().orThrow().intValue())); return DataResult.success(new Pair<>(list, input)); } - }.fieldOf("ingredients").forGetter(SatelliteRecipe::ingredients) - ).apply(i, SatelliteRecipe::create)); + }.fieldOf("ingredients").forGetter(SpaceStationRecipe::ingredients) + ).apply(i, SpaceStationRecipe::create)); @Contract(value = "_ -> new", pure = true) - static @NotNull SatelliteRecipe create(Object2IntMap list) { - return new SatelliteRecipeImpl(list); + static @NotNull SpaceStationRecipe create(Object2IntMap list) { + return new SpaceStationRecipeImpl(list); } Object2IntMap ingredients(); diff --git a/src/main/java/dev/galacticraft/api/universe/celestialbody/landable/Landable.java b/src/main/java/dev/galacticraft/api/universe/celestialbody/landable/Landable.java index 0295badd..93bfe2e2 100644 --- a/src/main/java/dev/galacticraft/api/universe/celestialbody/landable/Landable.java +++ b/src/main/java/dev/galacticraft/api/universe/celestialbody/landable/Landable.java @@ -40,7 +40,7 @@ public interface Landable extends SurfaceEnvironm * @param config the celestial body configuration to be queried * @return the registry key of the {@link Level} this celestial body is linked to */ - @NotNull ResourceKey world(C config); + @NotNull ResourceKey world(@NotNull C config); /** * Returns the access weight required to generically reach this celestial body or a negative value if it cannot be accessed this way. diff --git a/src/main/java/dev/galacticraft/api/universe/celestialbody/satellite/Orbitable.java b/src/main/java/dev/galacticraft/api/universe/celestialbody/satellite/Orbitable.java index 27b6c51b..84192cbd 100644 --- a/src/main/java/dev/galacticraft/api/universe/celestialbody/satellite/Orbitable.java +++ b/src/main/java/dev/galacticraft/api/universe/celestialbody/satellite/Orbitable.java @@ -22,21 +22,37 @@ package dev.galacticraft.api.universe.celestialbody.satellite; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import dev.galacticraft.api.universe.celestialbody.CelestialBodyConfig; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; /** * Represents a {@link dev.galacticraft.api.universe.celestialbody.CelestialBodyType celestial body type} that can potentially allow player-made objects to orbit itself. + * Moons and other natural satellites are not effected by this. * * @param the type of configuration */ public interface Orbitable { /** - * Returns the {@link SatelliteRecipe stellite recipe} of this celestial body, or {@code null} if satellites should not be allowed to be created + * Returns the {@link SpaceStationRecipe stellite recipe} of this celestial body, or {@code null} if satellites should not be allowed to be created * * @param config the celestial body configuration to be queried - * @return the {@link SatelliteRecipe satellite recipe} of this celestial body + * @return the {@link SpaceStationRecipe satellite recipe} of this celestial body */ - @Nullable SatelliteRecipe satelliteRecipe(C config); + @Nullable SpaceStationRecipe getSpaceStationRecipe(C config); + + /** + * Callback to register client listeners (for example, {@link net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry.SkyRenderer sky renderers}) for this celestial body. + * Should only be called on the client. + * + * @param world + * @param key the {@link ResourceKey} of the satellite's dimension + * @param config the celestial body configuration + * @param spaceStationConfig + */ + void registerClientWorldHooks(RegistryAccess manager, /*Client*/Level world, ResourceKey key, C config, SpaceStationConfig spaceStationConfig); } diff --git a/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplay.java b/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplay.java index 666b603f..8cabd01a 100644 --- a/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplay.java +++ b/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplay.java @@ -38,7 +38,7 @@ public record CelestialDisplay> CODEC = AddonRegistry.CELESTIAL_DISPLAY_TYPE.byNameCodec().dispatch(CelestialDisplay::type, CelestialDisplayType::codec); @Environment(EnvType.CLIENT) - public Vector4f render(PoseStack matrices, BufferBuilder buffer, int scale, double mouseX, double mouseY, float delta, Consumer> shaderSetter) { + public Vector4f render(PoseStack matrices, BufferBuilder buffer, float scale, double mouseX, double mouseY, float delta, Consumer> shaderSetter) { return this.type().render(matrices, buffer, scale, mouseX, mouseY, delta, shaderSetter, this.config()); } } diff --git a/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplayType.java b/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplayType.java index 31300d1d..e5b50907 100644 --- a/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplayType.java +++ b/src/main/java/dev/galacticraft/api/universe/display/CelestialDisplayType.java @@ -41,7 +41,7 @@ public CelestialDisplayType(Codec codec) { } @Environment(EnvType.CLIENT) - public abstract Vector4f render(PoseStack matrices, BufferBuilder buffer, int size, double mouseX, double mouseY, float delta, Consumer> shaderSetter, C config); + public abstract Vector4f render(PoseStack matrices, BufferBuilder buffer, float size, double mouseX, double mouseY, float delta, Consumer> shaderSetter, C config); public Codec>> codec() { return this.codec; diff --git a/src/main/java/dev/galacticraft/impl/accessor/SoundSystemAccessor.java b/src/main/java/dev/galacticraft/impl/accessor/SoundSystemAccessor.java index 3f4f7632..b8a63714 100644 --- a/src/main/java/dev/galacticraft/impl/accessor/SoundSystemAccessor.java +++ b/src/main/java/dev/galacticraft/impl/accessor/SoundSystemAccessor.java @@ -29,5 +29,7 @@ */ @ApiStatus.Internal public interface SoundSystemAccessor { - void updateAtmosphericVolumeMultiplier(float multiplier); + default void updateAtmosphericVolumeMultiplier(float multiplier) { + throw new RuntimeException("This should not happen, you need to override this!"); + } } diff --git a/src/main/java/dev/galacticraft/impl/client/accessor/ClientResearchAccessor.java b/src/main/java/dev/galacticraft/impl/client/accessor/ClientResearchAccessor.java index e7fb07b5..bb94f754 100644 --- a/src/main/java/dev/galacticraft/impl/client/accessor/ClientResearchAccessor.java +++ b/src/main/java/dev/galacticraft/impl/client/accessor/ClientResearchAccessor.java @@ -31,5 +31,7 @@ @Environment(EnvType.CLIENT) @ApiStatus.Internal public interface ClientResearchAccessor extends ResearchAccessor { - void readChanges(FriendlyByteBuf buf); + default void readChanges(FriendlyByteBuf buf) { + throw new RuntimeException("This should not happen, you need to override this!"); + } } diff --git a/src/main/java/dev/galacticraft/impl/internal/client/GCApiDimensionEffects.java b/src/main/java/dev/galacticraft/impl/internal/client/GCApiDimensionEffects.java new file mode 100644 index 00000000..b17d8d77 --- /dev/null +++ b/src/main/java/dev/galacticraft/impl/internal/client/GCApiDimensionEffects.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2019-2022 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.impl.internal.client; + +import com.mojang.authlib.minecraft.client.MinecraftClient; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.*; +import com.mojang.math.Vector3f; +import dev.galacticraft.api.universe.display.CelestialDisplay; +import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.util.Mth; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +import java.util.Random; + +public final class GCApiDimensionEffects { + public static final DimensionRenderingRegistry.CloudRenderer NO_CLOUDS = context -> {}; + public static final DimensionRenderingRegistry.WeatherRenderer NO_WEATHER = context -> {}; + + public static DimensionRenderingRegistry.SkyRenderer createSpaceStationRenderer(float starSize, float planetSize, CelestialDisplay starDisplay, CelestialDisplay planetDisplay) { + return new SatelliteSkyRenderer(starSize, planetSize, starDisplay, planetDisplay); + } + + private static class SatelliteSkyRenderer implements DimensionRenderingRegistry.SkyRenderer { + private final float starSize; + private final float planetSize; + private final CelestialDisplay starDisplay; + private final CelestialDisplay planetDisplay; + private VertexBuffer starBuffer = null; + + public SatelliteSkyRenderer(float starSize, float planetSize, CelestialDisplay starDisplay, CelestialDisplay planetDisplay) { + this.starSize = starSize; + this.planetSize = planetSize; + this.starDisplay = starDisplay; + this.planetDisplay = planetDisplay; + } + + @Override + public void render(WorldRenderContext context) { + context.profiler().push("satellite_sky_render"); + if (this.starBuffer == null) this.generateStarBuffer(context); + + RenderSystem.disableTexture(); + RenderSystem.disableBlend(); + RenderSystem.depthMask(false); + + final PoseStack matrices = context.matrixStack(); + final BufferBuilder buffer = Tesselator.getInstance().getBuilder(); + float starBrightness = this.getStarBrightness(context.world(), context.tickDelta()); + + context.profiler().push("stars"); + matrices.pushPose(); + matrices.mulPose(Vector3f.YP.rotationDegrees(-90.0F)); + matrices.mulPose(Vector3f.XP.rotationDegrees(context.world().getSunAngle(context.tickDelta()) * 360.0f)); + matrices.mulPose(Vector3f.YP.rotationDegrees(-19.0F)); + RenderSystem.setShaderColor(1.0F, 0.95F, 0.9F, starBrightness); + RenderSystem.disableTexture(); + this.starBuffer.bind(); + this.starBuffer.drawWithShader(matrices.last().pose(), context.projectionMatrix(), GameRenderer.getPositionShader()); + VertexBuffer.unbind(); + + matrices.popPose(); + context.profiler().pop(); + + context.profiler().push("star"); + matrices.pushPose(); + + matrices.mulPose(Vector3f.YP.rotationDegrees(-90.0F)); + matrices.mulPose(Vector3f.XP.rotationDegrees(context.world().getSunAngle(context.tickDelta()) * 360.0f)); + matrices.translate(0.0, -100.0, 0.0); + RenderSystem.enableTexture(); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + + starDisplay.render(matrices, buffer, starSize, Float.MAX_VALUE / 3, Float.MAX_VALUE / 3, context.tickDelta(), RenderSystem::setShader); + + matrices.popPose(); + context.profiler().popPush("planet"); + matrices.pushPose(); + + matrices.mulPose(Vector3f.XP.rotationDegrees((context.world().getSunAngle(context.tickDelta()) * 360.0F) * 0.001F + ((float) (context.world().getSharedSpawnPos().getZ() - Minecraft.getInstance().player.getZ()) * 0.01F) + 200.0F)); + matrices.scale(0.6F, 0.6F, 0.6F); + planetDisplay.render(matrices, buffer, planetSize, Float.MAX_VALUE / 3, Float.MAX_VALUE / 3, context.tickDelta(), RenderSystem::setShader); + + context.profiler().pop(); + matrices.popPose(); + + RenderSystem.disableTexture(); + RenderSystem.depthMask(true); + context.profiler().pop(); + } + + private void generateStarBuffer(@NotNull WorldRenderContext context) { + context.profiler().push("generate_star_buffer"); + final Random random = new Random(context.world().dimension().location().hashCode()); + final BufferBuilder buffer = Tesselator.getInstance().getBuilder(); + RenderSystem.setShader(GameRenderer::getPositionShader); + buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); + for (int i = 0; i < 12000; ++i) { + double j = random.nextFloat() * 2.0F - 1.0F; + double k = random.nextFloat() * 2.0F - 1.0F; + double l = random.nextFloat() * 2.0F - 1.0F; + double m = 0.15F + random.nextFloat() * 0.1F; + double n = j * j + k * k + l * l; + + if (n < 1.0D && n > 0.01D) { + n = 1.0D / Math.sqrt(n); + j *= n; + k *= n; + l *= n; + double o = j * 100.0D; + double p = k * 100.0D; + double q = l * 100.0D; + double r = Math.atan2(j, l); + double s = Math.sin(r); + double t = Math.cos(r); + double u = Math.atan2(Math.sqrt(j * j + l * l), k); + double v = Math.sin(u); + double w = Math.cos(u); + double x = random.nextDouble() * Math.PI * 2.0D; + double y = Math.sin(x); + double z = Math.cos(x); + + for (int a = 0; a < 4; ++a) { + double b = 0.0D; + double c = ((a & 2) - 1) * m; + double d = ((a + 1 & 2) - 1) * m; + double e = c * z - d * y; + double f = d * z + c * y; + double g = e * v + b * w; + double h = b * v - e * w; + double aa = h * s - f * t; + double ab = f * s + h * t; + buffer.vertex((o + aa) * (i > 6000 ? -1 : 1), (p + g) * (i > 6000 ? -1 : 1), (q + ab) * (i > 6000 ? -1 : 1)).endVertex(); + } + } + } + this.starBuffer = new VertexBuffer(); + this.starBuffer.bind(); + this.starBuffer.upload(buffer.end()); + VertexBuffer.unbind(); + context.profiler().pop(); + } + + private float getStarBrightness(Level world, float delta) { + final float skyAngle = world.getSunAngle(delta); + float brightness = 1.0F - (Mth.cos((float) (skyAngle * Math.PI * 2.0D) * 2.0F + 0.25F)); + + if (brightness < 0.0F) { + brightness = 0.0F; + } + + if (brightness > 1.0F) { + brightness = 1.0F; + } + + return brightness * brightness * 0.5F + 0.3F; + } + } +} diff --git a/src/main/java/dev/galacticraft/impl/internal/client/fabric/GalacticraftAPIClient.java b/src/main/java/dev/galacticraft/impl/internal/client/fabric/GalacticraftAPIClient.java index cf182875..dc7ff161 100644 --- a/src/main/java/dev/galacticraft/impl/internal/client/fabric/GalacticraftAPIClient.java +++ b/src/main/java/dev/galacticraft/impl/internal/client/fabric/GalacticraftAPIClient.java @@ -28,14 +28,15 @@ import dev.galacticraft.impl.Constant; import dev.galacticraft.impl.client.accessor.ClientResearchAccessor; import dev.galacticraft.impl.internal.accessor.ChunkOxygenSyncer; -import dev.galacticraft.impl.universe.celestialbody.type.SatelliteType; -import dev.galacticraft.impl.universe.position.config.SatelliteConfig; +import dev.galacticraft.impl.universe.celestialbody.type.SpaceStationType; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.nbt.NbtOps; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; @@ -53,7 +54,7 @@ public void onInitializeClient() { client.execute(() -> ((ClientResearchAccessor) Objects.requireNonNull(client.player)).readChanges(buf)); }); ClientPlayNetworking.registerGlobalReceiver(new ResourceLocation(Constant.MOD_ID, "add_satellite"), (client, networkHandler, buffer, sender) -> { - ((SatelliteAccessor) networkHandler).addSatellite(buffer.readResourceLocation(), new CelestialBody<>(SatelliteType.INSTANCE, SatelliteConfig.CODEC.decode(NbtOps.INSTANCE, buffer.readNbt()).get().orThrow().getFirst())); + ((SatelliteAccessor) networkHandler).addSatellite(buffer.readResourceLocation(), new CelestialBody<>(SpaceStationType.INSTANCE, SpaceStationConfig.CODEC.decode(RegistryOps.create(NbtOps.INSTANCE, networkHandler.registryAccess()), buffer.readNbt()).get().orThrow().getFirst())); }); ClientPlayNetworking.registerGlobalReceiver(new ResourceLocation(Constant.MOD_ID, "remove_satellite"), (client, networkHandler, buffer, sender) -> { FriendlyByteBuf buf = new FriendlyByteBuf(buffer.copy()); diff --git a/src/main/java/dev/galacticraft/impl/internal/command/GCApiCommands.java b/src/main/java/dev/galacticraft/impl/internal/command/GCApiCommands.java index 3c5ac39f..55e39e41 100644 --- a/src/main/java/dev/galacticraft/impl/internal/command/GCApiCommands.java +++ b/src/main/java/dev/galacticraft/impl/internal/command/GCApiCommands.java @@ -25,14 +25,16 @@ import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.galacticraft.api.accessor.WorldOxygenAccessor; +import dev.galacticraft.api.registry.AddonRegistry; import dev.galacticraft.impl.Constant; import dev.galacticraft.impl.command.argument.RegistryArgumentType; +import dev.galacticraft.impl.universe.celestialbody.type.SpaceStationType; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.mixin.command.ArgumentTypesAccessor; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.ResourceLocationArgument; @@ -43,60 +45,76 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; @ApiStatus.Internal public class GCApiCommands { public static void register() { - SingletonArgumentInfo> serializer = SingletonArgumentInfo.contextFree(RegistryArgumentType::create); - ArgumentTypesAccessor.fabric_getClassMap().put(RegistryArgumentType.class, serializer); - Registry.register(Registry.COMMAND_ARGUMENT_TYPE, new ResourceLocation("galacticraft-api", "registry"), serializer); // Blame fabric api generics for this - CommandRegistrationCallback.EVENT.register((commandDispatcher, registryAccess, environment) -> { - LiteralArgumentBuilder builder = Commands.literal(Constant.MOD_ID + ":debug") - .requires(serverCommandSource -> serverCommandSource.hasPermission(2)) - .executes(context -> { - context.getSource().sendFailure(Component.translatable("command.galacticraft-api.debug")); - return -1; - }); - builder.then(Commands.literal("registry").then(Commands.argument("registry", RegistryArgumentType.create()) - .then(Commands.literal("dump_ids").executes(context -> { - CommandSourceStack source = context.getSource(); - Registry registry = RegistryArgumentType.getRegistry(context, "registry"); - source.sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.dump", registry.key().location().toString()), true); - for (ResourceLocation id : registry.keySet()) { - source.sendSuccess(Component.literal(id.toString()), false); - } - return 1; - })).then(Commands.literal("get").then(Commands.argument("id", ResourceLocationArgument.id()).executes(context -> { - Registry registry = RegistryArgumentType.getRegistry(context, "registry"); - context.getSource().sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.id", registry.key().location(), registry.get(ResourceLocationArgument.getId(context, "id"))), true); - return 1; - }))).then(Commands.literal("get_raw").then(Commands.argument("id", IntegerArgumentType.integer()).executes(context -> { - Registry registry = RegistryArgumentType.getRegistry(context, "registry"); - context.getSource().sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.id", registry.key().location(), registry.byId(IntegerArgumentType.getInteger(context, "id"))), true); - return 1; - }))).then(Commands.literal("to_raw").then(Commands.argument("id", ResourceLocationArgument.id()).executes(context -> { - Registry registry = RegistryArgumentType.getRegistry(context, "registry"); - Object o = registry.get(ResourceLocationArgument.getId(context, "id")); - context.getSource().sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.id", registry.key().location(), registry.getId(o)), true); - return 1; - }))).then(Commands.literal("dump_values").then(Commands.argument("id", ResourceLocationArgument.id()).executes(context -> { - CommandSourceStack source = context.getSource(); - Registry registry = RegistryArgumentType.getRegistry(context, "registry"); - source.sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.dump", registry.key().location().toString()), true); - for (ResourceLocation id : registry.keySet()) { - source.sendSuccess(Component.literal(id.toString() + " - " + registry.get(id)), false); - } - return 1; - }))))); - commandDispatcher.register(builder); - builder = Commands.literal(Constant.MOD_ID + ":oxygen").requires(source -> source.hasPermission(3)); - builder.then(Commands.literal("get").then(Commands.argument("start_pos", BlockPosArgument.blockPos()).executes(GCApiCommands::getOxygen).then(Commands.argument("end_pos", BlockPosArgument.blockPos()).executes(GCApiCommands::getOxygenArea)))); - builder.then(Commands.literal("set").requires(source -> source.hasPermission(4)).then(Commands.argument("start_pos", BlockPosArgument.blockPos()).then(Commands.argument("oxygen", BoolArgumentType.bool()).executes(GCApiCommands::setOxygen)).then(Commands.argument("end_pos", BlockPosArgument.blockPos()).then(Commands.argument("oxygen", BoolArgumentType.bool()).executes(GCApiCommands::setOxygenArea))))); - commandDispatcher.register(builder); + ArgumentTypesAccessor.fabric_getClassMap().put(RegistryArgumentType.class, SingletonArgumentInfo.contextFree(RegistryArgumentType::create)); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, commandSelection) -> { + if (FabricLoader.getInstance().isDevelopmentEnvironment()) { + dispatcher.register(Commands.literal(Constant.MOD_ID + ":debug") + .requires(serverCommandSource -> serverCommandSource.hasPermission(2)).then(Commands.literal("registry").then(Commands.argument("registry", RegistryArgumentType.create()) + .then(Commands.literal("dump_ids").executes(GCApiCommands::dumpRegistries)) + .then(Commands.literal("get") + .then(Commands.argument("id", ResourceLocationArgument.id()) + .executes(GCApiCommands::getRegistryValue))) + .then(Commands.literal("get_raw") + .then(Commands.argument("id", IntegerArgumentType.integer()) + .executes(GCApiCommands::getRegistryValueFromRawId))) + .then(Commands.literal("to_raw") + .then(Commands.argument("id", ResourceLocationArgument.id()) + .executes(GCApiCommands::getRegistryRawId))) + .then(Commands.literal("dump_values") + .then(Commands.argument("id", ResourceLocationArgument.id()) + .executes(GCApiCommands::dumpRegistryValues)))))); + } + dispatcher.register(Commands.literal("oxygen").requires(source -> source.hasPermission(2)) + .then(Commands.literal("get").then(Commands.argument("start_pos", BlockPosArgument.blockPos()) + .executes(GCApiCommands::getOxygen) + .then(Commands.argument("end_pos", BlockPosArgument.blockPos()) + .executes(GCApiCommands::getOxygenArea)))) + .then(Commands.literal("set") + .then(Commands.argument("start_pos", BlockPosArgument.blockPos()) + .then(Commands.argument("oxygen", BoolArgumentType.bool()) + .executes(GCApiCommands::setOxygen)) + .then(Commands.argument("end_pos", BlockPosArgument.blockPos()) + .then(Commands.argument("oxygen", BoolArgumentType.bool()) + .executes(GCApiCommands::setOxygenArea)))))); + + dispatcher.register(Commands.literal("space_station").requires(source -> source.hasPermission(2)) + .then(Commands.literal("add").then(Commands.argument("world", ResourceLocationArgument.id()) + .executes(GCApiCommands::addSpaceStation) + .then(Commands.argument("structure", ResourceLocationArgument.id()) + .executes(GCApiCommands::addSpaceStationStructured)))) + .then(Commands.literal("remove").then(Commands.argument("id", ResourceLocationArgument.id()) + .executes(GCApiCommands::removeSpaceStation)))); }); } + private static int removeSpaceStation(@NotNull CommandContext ctx) { + if (SpaceStationType.removeSatellite(ctx.getSource().getServer(), ResourceLocationArgument.getId(ctx, "id"))) { + return 1; + } else { + return 0; + } + } + + private static int addSpaceStationStructured(@NotNull CommandContext ctx) { + StructureTemplate structure = ctx.getSource().getServer().getStructureManager().get(ResourceLocationArgument.getId(ctx, "structure")).orElseThrow(); + SpaceStationType.registerSpaceStation(ctx.getSource().getServer(), ctx.getSource().getPlayer(), Objects.requireNonNull(ctx.getSource().registryAccess().registryOrThrow(AddonRegistry.CELESTIAL_BODY_KEY).get(ResourceLocationArgument.getId(ctx, "world"))), structure); + return 1; + } + + private static int addSpaceStation(@NotNull CommandContext ctx) { + SpaceStationType.registerSpaceStation(ctx.getSource().getServer(), ctx.getSource().getPlayer(), Objects.requireNonNull(ctx.getSource().registryAccess().registryOrThrow(AddonRegistry.CELESTIAL_BODY_KEY).get(ResourceLocationArgument.getId(ctx, "world"))), new StructureTemplate()); + return 1; + } + private static int setOxygen(CommandContext context) throws CommandSyntaxException { BlockPos pos = BlockPosArgument.getLoadedBlockPos(context, "start_pos"); boolean b = BoolArgumentType.getBool(context, "oxygen"); @@ -161,4 +179,43 @@ private static int getOxygenArea(CommandContext context) thr } return 1; } + + private static int getRegistryValue(CommandContext context) { + Registry registry = RegistryArgumentType.getRegistry(context, "registry"); + context.getSource().sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.id", registry.key().location(), registry.get(ResourceLocationArgument.getId(context, "id"))), true); + return 1; + } + + private static int getRegistryRawId(CommandContext context) { + Registry registry = RegistryArgumentType.getRegistry(context, "registry"); + Object o = registry.get(ResourceLocationArgument.getId(context, "id")); + context.getSource().sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.id", registry.key().location(), registry.getId(o)), true); + return 1; + } + + private static int dumpRegistryValues(CommandContext context) { + CommandSourceStack source = context.getSource(); + Registry registry = RegistryArgumentType.getRegistry(context, "registry"); + source.sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.dump", registry.key().location().toString()), true); + for (ResourceLocation id : registry.keySet()) { + source.sendSuccess(Component.literal(id.toString() + " - " + registry.get(id)), false); + } + return 1; + } + + private static int dumpRegistries(CommandContext context) { + CommandSourceStack source = context.getSource(); + Registry registry = RegistryArgumentType.getRegistry(context, "registry"); + source.sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.dump", registry.key().location().toString()), true); + for (ResourceLocation id : registry.keySet()) { + source.sendSuccess(Component.literal(id.toString()), false); + } + return 1; + } + + private static int getRegistryValueFromRawId(CommandContext context) { + Registry registry = RegistryArgumentType.getRegistry(context, "registry"); + context.getSource().sendSuccess(Component.translatable("command.galacticraft-api.debug.registry.id", registry.key().location(), registry.byId(IntegerArgumentType.getInteger(context, "id"))), true); + return 1; + } } diff --git a/src/main/java/dev/galacticraft/impl/internal/mixin/DynamicRegistryManagerMixin.java b/src/main/java/dev/galacticraft/impl/internal/mixin/DynamicRegistryManagerMixin.java index 797e89c9..1a0fa6c7 100644 --- a/src/main/java/dev/galacticraft/impl/internal/mixin/DynamicRegistryManagerMixin.java +++ b/src/main/java/dev/galacticraft/impl/internal/mixin/DynamicRegistryManagerMixin.java @@ -44,7 +44,7 @@ public interface DynamicRegistryManagerMixin { @Shadow private static void put(ImmutableMap.Builder>, RegistryAccess.RegistryData> infosBuilder, ResourceKey> registryRef, Codec entryCodec) {} - @Dynamic("1.18.2 synthetic method") + @Dynamic("1.19 synthetic method") @Inject(method = "method_30531", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/RegistryAccess;put(Lcom/google/common/collect/ImmutableMap$Builder;Lnet/minecraft/resources/ResourceKey;Lcom/mojang/serialization/Codec;Lcom/mojang/serialization/Codec;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) private static void galacticraft_registerCustomRegistries(CallbackInfoReturnable>, RegistryAccess.RegistryData>> ci, ImmutableMap.Builder>, RegistryAccess.RegistryData> builder) { put(builder, AddonRegistry.GALAXY_KEY, Galaxy.CODEC); diff --git a/src/main/java/dev/galacticraft/impl/internal/mixin/MinecraftServerMixin.java b/src/main/java/dev/galacticraft/impl/internal/mixin/MinecraftServerMixin.java index 57606e74..3ab5ccb6 100644 --- a/src/main/java/dev/galacticraft/impl/internal/mixin/MinecraftServerMixin.java +++ b/src/main/java/dev/galacticraft/impl/internal/mixin/MinecraftServerMixin.java @@ -22,30 +22,20 @@ package dev.galacticraft.impl.internal.mixin; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import dev.galacticraft.api.accessor.SatelliteAccessor; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import dev.galacticraft.impl.Constant; -import dev.galacticraft.impl.universe.celestialbody.type.SatelliteType; -import dev.galacticraft.impl.universe.position.config.SatelliteConfig; +import dev.galacticraft.impl.universe.celestialbody.type.SpaceStationType; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; import net.fabricmc.fabric.api.util.NbtType; -import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.border.BorderChangeListener; -import net.minecraft.world.level.border.WorldBorder; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.storage.DerivedLevelData; import net.minecraft.world.level.storage.LevelResource; import net.minecraft.world.level.storage.LevelStorageSource; -import net.minecraft.world.level.storage.WorldData; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -60,26 +50,22 @@ import java.nio.file.Path; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.Executor; @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin implements SatelliteAccessor { - @Unique private final Map> satellites = new HashMap<>(); + @Unique private final Map> satellites = new HashMap<>(); @Shadow @Final protected LevelStorageSource.LevelStorageAccess storageSource; - @Shadow @Final private Executor executor; - @Shadow @Final private Map, ServerLevel> levels; - @Shadow public abstract WorldData getWorldData(); - @Shadow @Nullable public abstract ServerLevel getLevel(ResourceKey key); + @Shadow public abstract RegistryAccess.Frozen registryAccess(); @Override - public @Unmodifiable Map> getSatellites() { + public @Unmodifiable Map> getSatellites() { return ImmutableMap.copyOf(this.satellites); } @Override - public void addSatellite(ResourceLocation id, CelestialBody satellite) { + public void addSatellite(ResourceLocation id, CelestialBody satellite) { this.satellites.put(id, satellite); } @@ -92,8 +78,8 @@ public void removeSatellite(ResourceLocation id) { private void galacticraft_saveSatellites(boolean suppressLogs, boolean bl, boolean bl2, CallbackInfoReturnable cir) { Path path = this.storageSource.getLevelPath(LevelResource.ROOT); ListTag nbt = new ListTag(); - for (Map.Entry> entry : this.satellites.entrySet()) { - CompoundTag compound = (CompoundTag) SatelliteConfig.CODEC.encode(entry.getValue().config(), NbtOps.INSTANCE, new CompoundTag()).get().orThrow(); + for (Map.Entry> entry : this.satellites.entrySet()) { + CompoundTag compound = (CompoundTag) SpaceStationConfig.CODEC.encode(entry.getValue().config(), NbtOps.INSTANCE, new CompoundTag()).get().orThrow(); compound.putString("id", entry.getKey().toString()); nbt.add(compound); } @@ -106,7 +92,7 @@ private void galacticraft_saveSatellites(boolean suppressLogs, boolean bl, boole } } - @Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;initServer()Z", shift = At.Shift.AFTER)) + @Inject(method = "loadLevel", at = @At(value = "HEAD")) private void galacticraft_loadSatellites(CallbackInfo ci) { File worldFile = this.storageSource.getLevelPath(LevelResource.ROOT).toFile(); if (new File(worldFile, "satellites.dat").exists()) { @@ -115,19 +101,10 @@ private void galacticraft_loadSatellites(CallbackInfo ci) { assert nbt != null : "NBT list was null"; for (Tag compound : nbt) { assert compound instanceof CompoundTag : "Not a compound?!"; - this.satellites.put(new ResourceLocation(((CompoundTag) compound).getString("id")), new CelestialBody<>(SatelliteType.INSTANCE, SatelliteConfig.CODEC.decode(NbtOps.INSTANCE, compound).get().orThrow().getFirst())); - } - - WorldBorder worldBorder = getLevel(Level.OVERWORLD).getWorldBorder(); - for (Map.Entry> entry : this.satellites.entrySet()) { - ChunkGenerator chunkGenerator = entry.getValue().config().dimensionOptions().generator(); - DerivedLevelData unmodifiableLevelProperties = new DerivedLevelData(getWorldData(), getWorldData().overworldData()); - ServerLevel world = new ServerLevel((MinecraftServer) (Object) this, executor, storageSource, unmodifiableLevelProperties, ResourceKey.create(Registry.DIMENSION_REGISTRY, entry.getKey()), entry.getValue().config().dimensionOptions(), SatelliteType.EMPTY_PROGRESS_LISTENER, getWorldData().worldGenSettings().isDebug(), BiomeManager.obfuscateSeed(getWorldData().worldGenSettings().seed()), ImmutableList.of(), false); - worldBorder.addListener(new BorderChangeListener.DelegateBorderChangeListener(world.getWorldBorder())); - levels.put(ResourceKey.create(Registry.DIMENSION_REGISTRY, entry.getKey()), world); + this.satellites.put(new ResourceLocation(((CompoundTag) compound).getString("id")), new CelestialBody<>(SpaceStationType.INSTANCE, SpaceStationConfig.CODEC.decode(RegistryOps.create(NbtOps.INSTANCE, this.registryAccess()), compound).get().orThrow().getFirst())); } } catch (Throwable exception) { - throw new RuntimeException("Failed to reade satellite data!", exception); + throw new RuntimeException("Failed to read satellite data!", exception); } } } diff --git a/src/main/java/dev/galacticraft/impl/internal/mixin/PlayerManagerMixin.java b/src/main/java/dev/galacticraft/impl/internal/mixin/PlayerManagerMixin.java index 25370e75..fe76e1ce 100644 --- a/src/main/java/dev/galacticraft/impl/internal/mixin/PlayerManagerMixin.java +++ b/src/main/java/dev/galacticraft/impl/internal/mixin/PlayerManagerMixin.java @@ -23,28 +23,36 @@ package dev.galacticraft.impl.internal.mixin; import dev.galacticraft.api.accessor.GearInventoryProvider; +import dev.galacticraft.api.accessor.SatelliteAccessor; import dev.galacticraft.impl.Constant; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.PlayerLookup; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.network.Connection; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; import net.minecraft.world.Container; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Collection; - /** * @author TeamGalacticraft */ @Mixin(PlayerList.class) public abstract class PlayerManagerMixin { + @Shadow public abstract MinecraftServer getServer(); + + @Shadow public abstract void broadcastAll(Packet packet); + @Inject(method = "placeNewPlayer", at = @At("RETURN")) private void galacticraft_syncGearInventory(Connection connection, ServerPlayer player, CallbackInfo ci) { FriendlyByteBuf buf = PacketByteBufs.create(); @@ -55,12 +63,11 @@ private void galacticraft_syncGearInventory(Connection connection, ServerPlayer buf.writeItem(inventory.getItem(i)); } - Collection tracking = PlayerLookup.tracking(player); - if (!tracking.contains(player)) { - ServerPlayNetworking.send(player, new ResourceLocation(Constant.MOD_ID, "gear_inv_sync"), buf); - } - for (ServerPlayer pl : tracking) { - ServerPlayNetworking.send(pl, new ResourceLocation(Constant.MOD_ID, "gear_inv_sync"), PacketByteBufs.copy(buf)); - } + this.broadcastAll(new ClientboundCustomPayloadPacket(new ResourceLocation(Constant.MOD_ID, "gear_inv_sync"), buf)); + + ((SatelliteAccessor) this.getServer()).getSatellites().forEach((id, satellite) -> { + CompoundTag compound = (CompoundTag) SpaceStationConfig.CODEC.encode(satellite.config(), NbtOps.INSTANCE, new CompoundTag()).get().orThrow(); + connection.send(new ClientboundCustomPayloadPacket(new ResourceLocation(Constant.MOD_ID, "add_satellite"), PacketByteBufs.create().writeResourceLocation(id).writeNbt(compound))); + }); } } diff --git a/src/main/java/dev/galacticraft/impl/internal/mixin/client/AbstractClientPlayerEntityMixin.java b/src/main/java/dev/galacticraft/impl/internal/mixin/client/AbstractClientPlayerEntityMixin.java index c11a816d..40c3166c 100644 --- a/src/main/java/dev/galacticraft/impl/internal/mixin/client/AbstractClientPlayerEntityMixin.java +++ b/src/main/java/dev/galacticraft/impl/internal/mixin/client/AbstractClientPlayerEntityMixin.java @@ -66,16 +66,16 @@ private SimpleContainer galacticraft_createGearInventory() { for (int i = 0; i < inventory.getContainerSize(); i++) { ItemStack stack = inventory.getItem(i); if (stack.getItem() instanceof Accessory accessory && accessory.enablesHearing()) { - ((SoundSystemAccessor) ((SoundManagerAccessor) Minecraft.getInstance().getSoundManager()).getSoundSystem()) + ((SoundManagerAccessor) Minecraft.getInstance().getSoundManager()).getSoundSystem() .updateAtmosphericVolumeMultiplier(1.0f); return; } else { - ((SoundSystemAccessor) ((SoundManagerAccessor) Minecraft.getInstance().getSoundManager()).getSoundSystem()) + ((SoundManagerAccessor) Minecraft.getInstance().getSoundManager()).getSoundSystem() .updateAtmosphericVolumeMultiplier(pressure); } } } else { - ((SoundSystemAccessor) ((SoundManagerAccessor) Minecraft.getInstance().getSoundManager()).getSoundSystem()).updateAtmosphericVolumeMultiplier(pressure); + ((SoundManagerAccessor) Minecraft.getInstance().getSoundManager()).getSoundSystem().updateAtmosphericVolumeMultiplier(pressure); } }); return inv; diff --git a/src/main/java/dev/galacticraft/impl/internal/mixin/client/ClientPlayNetworkHandlerMixin.java b/src/main/java/dev/galacticraft/impl/internal/mixin/client/ClientPlayNetworkHandlerMixin.java index 008765e9..302f4acf 100644 --- a/src/main/java/dev/galacticraft/impl/internal/mixin/client/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/dev/galacticraft/impl/internal/mixin/client/ClientPlayNetworkHandlerMixin.java @@ -24,13 +24,19 @@ import dev.galacticraft.api.client.accessor.ClientSatelliteAccessor; import dev.galacticraft.api.universe.celestialbody.CelestialBody; -import dev.galacticraft.impl.universe.celestialbody.type.SatelliteType; -import dev.galacticraft.impl.universe.position.config.SatelliteConfig; +import dev.galacticraft.api.universe.celestialbody.satellite.Orbitable; +import dev.galacticraft.impl.universe.celestialbody.type.SpaceStationType; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import java.util.ArrayList; @@ -41,16 +47,21 @@ @Environment(EnvType.CLIENT) @Mixin(ClientPacketListener.class) public abstract class ClientPlayNetworkHandlerMixin implements ClientSatelliteAccessor { - private final @Unique Map> satellites = new HashMap<>(); + @Shadow public abstract RegistryAccess registryAccess(); + + @Shadow private ClientLevel level; + private final @Unique Map> satellites = new HashMap<>(); private final @Unique List listeners = new ArrayList<>(); @Override - public Map> getSatellites() { + public Map> getSatellites() { return this.satellites; } @Override - public void addSatellite(ResourceLocation id, CelestialBody satellite) { + public void addSatellite(ResourceLocation id, CelestialBody satellite) { + CelestialBody parent = satellite.parent(this.registryAccess()); + ((Orbitable) parent.type()).registerClientWorldHooks(this.registryAccess(), this.level, ResourceKey.create(Registry.DIMENSION_REGISTRY, id), parent.config(), satellite.config()); this.satellites.put(id, satellite); for (SatelliteListener listener : this.listeners) { listener.onSatelliteUpdated(satellite, true); @@ -59,7 +70,7 @@ public void addSatellite(ResourceLocation id, CelestialBody removed = this.satellites.remove(id); + CelestialBody removed = this.satellites.remove(id); for (SatelliteListener listener : this.listeners) { listener.onSatelliteUpdated(removed, false); } diff --git a/src/main/java/dev/galacticraft/impl/internal/mixin/client/MinecraftClientMixin.java b/src/main/java/dev/galacticraft/impl/internal/mixin/client/MinecraftClientMixin.java index 4dffd505..875d186b 100644 --- a/src/main/java/dev/galacticraft/impl/internal/mixin/client/MinecraftClientMixin.java +++ b/src/main/java/dev/galacticraft/impl/internal/mixin/client/MinecraftClientMixin.java @@ -22,7 +22,6 @@ package dev.galacticraft.impl.internal.mixin.client; -import dev.galacticraft.impl.accessor.SoundSystemAccessor; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -47,9 +46,9 @@ public abstract class MinecraftClientMixin { @Inject(method = "setLevel", at = @At("RETURN")) private void galacticraft_updateSoundMultiplier(ClientLevel world, CallbackInfo ci) { if (world != null) { - ((SoundSystemAccessor) ((SoundManagerAccessor) this.getSoundManager()).getSoundSystem()).updateAtmosphericVolumeMultiplier(CelestialBody.getByDimension(world).map(body -> body.atmosphere().pressure()).orElse(1.0f)); + ((SoundManagerAccessor) this.getSoundManager()).getSoundSystem().updateAtmosphericVolumeMultiplier(CelestialBody.getByDimension(world).map(body -> body.atmosphere().pressure()).orElse(1.0f)); } else { - ((SoundSystemAccessor) ((SoundManagerAccessor) this.getSoundManager()).getSoundSystem()).updateAtmosphericVolumeMultiplier(1.0f); + ((SoundManagerAccessor) this.getSoundManager()).getSoundSystem().updateAtmosphericVolumeMultiplier(1.0f); } } } diff --git a/src/main/java/dev/galacticraft/impl/internal/world/gen/SatelliteChunkGenerator.java b/src/main/java/dev/galacticraft/impl/internal/world/gen/SatelliteChunkGenerator.java index 3163b915..ae741026 100644 --- a/src/main/java/dev/galacticraft/impl/internal/world/gen/SatelliteChunkGenerator.java +++ b/src/main/java/dev/galacticraft/impl/internal/world/gen/SatelliteChunkGenerator.java @@ -55,6 +55,7 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; diff --git a/src/main/java/dev/galacticraft/impl/rocket/RocketDataImpl.java b/src/main/java/dev/galacticraft/impl/rocket/RocketDataImpl.java index 06054100..8875b227 100644 --- a/src/main/java/dev/galacticraft/impl/rocket/RocketDataImpl.java +++ b/src/main/java/dev/galacticraft/impl/rocket/RocketDataImpl.java @@ -46,9 +46,9 @@ public record RocketDataImpl(int color, ResourceLocation cone, ResourceLocation public static final RocketDataImpl EMPTY = new RocketDataImpl(0xffffffff, new ResourceLocation(Constant.MOD_ID, "invalid"), new ResourceLocation(Constant.MOD_ID, "invalid"), new ResourceLocation(Constant.MOD_ID, "invalid"), new ResourceLocation(Constant.MOD_ID, "invalid"), new ResourceLocation(Constant.MOD_ID, "invalid"), new ResourceLocation(Constant.MOD_ID, "invalid")); public static RocketDataImpl fromNbt(@NotNull CompoundTag nbt) { - if (nbt.getBoolean("Empty")) return empty(); + if (nbt.getBoolean("empty")) return empty(); return new RocketDataImpl( - nbt.getInt("Color"), + nbt.getInt("color"), new ResourceLocation(nbt.getString("cone")), new ResourceLocation(nbt.getString("body")), new ResourceLocation(nbt.getString("fin")), @@ -66,7 +66,7 @@ public static RocketDataImpl empty() { @Override public @NotNull CompoundTag toNbt(@NotNull CompoundTag nbt) { if (this.isEmpty()) { - nbt.putBoolean("Empty", true); + nbt.putBoolean("empty", true); return nbt; } nbt.putInt("color", this.color()); diff --git a/src/main/java/dev/galacticraft/impl/satellite/SatelliteRecipeImpl.java b/src/main/java/dev/galacticraft/impl/satellite/SpaceStationRecipeImpl.java similarity index 92% rename from src/main/java/dev/galacticraft/impl/satellite/SatelliteRecipeImpl.java rename to src/main/java/dev/galacticraft/impl/satellite/SpaceStationRecipeImpl.java index ee0e8dc1..17c64b8c 100644 --- a/src/main/java/dev/galacticraft/impl/satellite/SatelliteRecipeImpl.java +++ b/src/main/java/dev/galacticraft/impl/satellite/SpaceStationRecipeImpl.java @@ -22,7 +22,7 @@ package dev.galacticraft.impl.satellite; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -31,10 +31,10 @@ import net.minecraft.world.item.crafting.Ingredient; import org.jetbrains.annotations.NotNull; -public class SatelliteRecipeImpl implements SatelliteRecipe { +public class SpaceStationRecipeImpl implements SpaceStationRecipe { private final Object2IntMap ingredients; - public SatelliteRecipeImpl(Object2IntMap list) { + public SpaceStationRecipeImpl(Object2IntMap list) { this.ingredients = list; } diff --git a/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/DecorativePlanetConfig.java b/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/DecorativePlanetConfig.java index 80fd19d4..bc94784b 100644 --- a/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/DecorativePlanetConfig.java +++ b/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/DecorativePlanetConfig.java @@ -26,7 +26,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.galacticraft.api.gas.GasComposition; import dev.galacticraft.api.registry.AddonRegistry; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import dev.galacticraft.api.universe.celestialbody.CelestialBodyConfig; import dev.galacticraft.api.universe.display.CelestialDisplay; @@ -45,7 +45,7 @@ public record DecorativePlanetConfig(@NotNull MutableComponent name, @NotNull Mu @NotNull ResourceKey> parent, @NotNull CelestialPosition position, @NotNull CelestialDisplay display, GasComposition atmosphere, float gravity, - @NotNull Optional satelliteRecipe) implements CelestialBodyConfig { + @NotNull Optional satelliteRecipe) implements CelestialBodyConfig { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.STRING.fieldOf("name").xmap(Component::translatable, Component::getString).forGetter(DecorativePlanetConfig::name), Codec.STRING.fieldOf("description").xmap(Component::translatable, Component::getString).forGetter(DecorativePlanetConfig::description), @@ -55,6 +55,6 @@ public record DecorativePlanetConfig(@NotNull MutableComponent name, @NotNull Mu CelestialDisplay.CODEC.fieldOf("display").forGetter(DecorativePlanetConfig::display), GasComposition.CODEC.fieldOf("atmosphere").forGetter(DecorativePlanetConfig::atmosphere), Codec.FLOAT.fieldOf("gravity").forGetter(DecorativePlanetConfig::gravity), - SatelliteRecipe.CODEC.optionalFieldOf("satellite_recipe").forGetter(DecorativePlanetConfig::satelliteRecipe) + SpaceStationRecipe.CODEC.optionalFieldOf("satellite_recipe").forGetter(DecorativePlanetConfig::satelliteRecipe) ).apply(instance, DecorativePlanetConfig::new)); } diff --git a/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/PlanetConfig.java b/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/PlanetConfig.java index 021d6935..2e3ce69d 100644 --- a/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/PlanetConfig.java +++ b/src/main/java/dev/galacticraft/impl/universe/celestialbody/config/PlanetConfig.java @@ -26,7 +26,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.galacticraft.api.gas.GasComposition; import dev.galacticraft.api.registry.AddonRegistry; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import dev.galacticraft.api.universe.celestialbody.CelestialBodyConfig; import dev.galacticraft.api.universe.display.CelestialDisplay; @@ -46,7 +46,7 @@ public record PlanetConfig(@NotNull MutableComponent name, @NotNull MutableCompo @NotNull CelestialPosition position, @NotNull CelestialDisplay display, @NotNull ResourceKey world, @NotNull GasComposition atmosphere, float gravity, int accessWeight, int dayTemperature, int nightTemperature, - @NotNull Optional satelliteRecipe) implements CelestialBodyConfig { + @NotNull Optional satelliteRecipe) implements CelestialBodyConfig { public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.STRING.fieldOf("name").xmap(Component::translatable, Component::getString).forGetter(PlanetConfig::name), Codec.STRING.fieldOf("description").xmap(Component::translatable, Component::getString).forGetter(PlanetConfig::description), @@ -60,6 +60,6 @@ public record PlanetConfig(@NotNull MutableComponent name, @NotNull MutableCompo Codec.INT.fieldOf("access_weight").forGetter(PlanetConfig::accessWeight), Codec.INT.fieldOf("day_temperature").forGetter(PlanetConfig::dayTemperature), Codec.INT.fieldOf("night_temperature").forGetter(PlanetConfig::nightTemperature), - SatelliteRecipe.CODEC.optionalFieldOf("satellite_recipe").forGetter(PlanetConfig::satelliteRecipe) + SpaceStationRecipe.CODEC.optionalFieldOf("satellite_recipe").forGetter(PlanetConfig::satelliteRecipe) ).apply(instance, PlanetConfig::new)); } diff --git a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/DecorativePlanet.java b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/DecorativePlanet.java index 33f9a667..24c2ef9c 100644 --- a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/DecorativePlanet.java +++ b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/DecorativePlanet.java @@ -23,17 +23,22 @@ package dev.galacticraft.impl.universe.celestialbody.type; import dev.galacticraft.api.gas.GasComposition; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import dev.galacticraft.api.universe.celestialbody.CelestialBodyType; import dev.galacticraft.api.universe.celestialbody.satellite.Orbitable; import dev.galacticraft.api.universe.display.CelestialDisplay; import dev.galacticraft.api.universe.galaxy.Galaxy; import dev.galacticraft.api.universe.position.CelestialPosition; +import dev.galacticraft.impl.internal.client.GCApiDimensionEffects; import dev.galacticraft.impl.universe.celestialbody.config.DecorativePlanetConfig; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; +import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry; import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,7 +90,20 @@ public float gravity(DecorativePlanetConfig config) { } @Override - public @Nullable SatelliteRecipe satelliteRecipe(DecorativePlanetConfig config) { + public @Nullable SpaceStationRecipe getSpaceStationRecipe(DecorativePlanetConfig config) { return config.satelliteRecipe().orElse(null); } + + @Override + public void registerClientWorldHooks(RegistryAccess manager, Level world, ResourceKey key, DecorativePlanetConfig config, SpaceStationConfig spaceStationConfig) { + DimensionRenderingRegistry.registerCloudRenderer(key, GCApiDimensionEffects.NO_CLOUDS); + DimensionRenderingRegistry.registerWeatherRenderer(key, GCApiDimensionEffects.NO_WEATHER); + + Registry> registry = CelestialBody.getRegistry(manager); + CelestialBody celestialBody = registry.get(config.parent()); + while (celestialBody.parent(manager) != null) { + celestialBody = celestialBody.parent(manager); + } + DimensionRenderingRegistry.registerSkyRenderer(key, GCApiDimensionEffects.createSpaceStationRenderer(4, 30, celestialBody.display(), config.display())); + } } diff --git a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/PlanetType.java b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/PlanetType.java index d14d7082..e5913a9c 100644 --- a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/PlanetType.java +++ b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/PlanetType.java @@ -23,7 +23,7 @@ package dev.galacticraft.impl.universe.celestialbody.type; import dev.galacticraft.api.gas.GasComposition; -import dev.galacticraft.api.satellite.SatelliteRecipe; +import dev.galacticraft.api.satellite.SpaceStationRecipe; import dev.galacticraft.api.universe.celestialbody.CelestialBody; import dev.galacticraft.api.universe.celestialbody.CelestialBodyType; import dev.galacticraft.api.universe.celestialbody.landable.Landable; @@ -31,7 +31,10 @@ import dev.galacticraft.api.universe.display.CelestialDisplay; import dev.galacticraft.api.universe.galaxy.Galaxy; import dev.galacticraft.api.universe.position.CelestialPosition; +import dev.galacticraft.impl.internal.client.GCApiDimensionEffects; import dev.galacticraft.impl.universe.celestialbody.config.PlanetConfig; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; +import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; import net.minecraft.network.chat.Component; @@ -78,7 +81,7 @@ protected PlanetType() { } @Override - public @NotNull ResourceKey world(PlanetConfig config) { + public @NotNull ResourceKey world(@NotNull PlanetConfig config) { return config.world(); } @@ -93,7 +96,7 @@ public float gravity(PlanetConfig config) { } @Override - public int accessWeight(PlanetConfig config) { + public int accessWeight(@NotNull PlanetConfig config) { return config.accessWeight(); } @@ -103,7 +106,20 @@ public int temperature(RegistryAccess access, long time, PlanetConfig config) { } @Override - public @Nullable SatelliteRecipe satelliteRecipe(PlanetConfig config) { + public @Nullable SpaceStationRecipe getSpaceStationRecipe(@NotNull PlanetConfig config) { return config.satelliteRecipe().orElse(null); } + + @Override + public void registerClientWorldHooks(RegistryAccess manager, Level world, ResourceKey key, @NotNull PlanetConfig config, SpaceStationConfig spaceStationConfig) { + DimensionRenderingRegistry.registerCloudRenderer(key, GCApiDimensionEffects.NO_CLOUDS); + DimensionRenderingRegistry.registerWeatherRenderer(key, GCApiDimensionEffects.NO_WEATHER); + + Registry> registry = CelestialBody.getRegistry(manager); + CelestialBody celestialBody = registry.get(config.parent()); + while (celestialBody.parent(manager) != null) { + celestialBody = celestialBody.parent(manager); + } + DimensionRenderingRegistry.registerSkyRenderer(key, GCApiDimensionEffects.createSpaceStationRenderer(4, 30, celestialBody.display(), config.display())); + } } diff --git a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/SatelliteType.java b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/SatelliteType.java deleted file mode 100644 index 8e91cd04..00000000 --- a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/SatelliteType.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2019-2022 Team Galacticraft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package dev.galacticraft.impl.universe.celestialbody.type; - -import com.google.common.collect.ImmutableList; -import com.mojang.serialization.Codec; -import dev.galacticraft.api.accessor.SatelliteAccessor; -import dev.galacticraft.api.gas.GasComposition; -import dev.galacticraft.api.registry.AddonRegistry; -import dev.galacticraft.api.satellite.Satellite; -import dev.galacticraft.api.satellite.SatelliteOwnershipData; -import dev.galacticraft.api.universe.celestialbody.CelestialBody; -import dev.galacticraft.api.universe.celestialbody.CelestialBodyType; -import dev.galacticraft.api.universe.celestialbody.landable.Landable; -import dev.galacticraft.api.universe.display.CelestialDisplay; -import dev.galacticraft.api.universe.galaxy.Galaxy; -import dev.galacticraft.api.universe.position.CelestialPosition; -import dev.galacticraft.impl.Constant; -import dev.galacticraft.impl.internal.mixin.MinecraftServerAccessor; -import dev.galacticraft.impl.internal.world.gen.SatelliteChunkGenerator; -import dev.galacticraft.impl.internal.world.gen.biome.GcApiBiomes; -import dev.galacticraft.impl.universe.display.config.IconCelestialDisplayConfig; -import dev.galacticraft.impl.universe.display.type.IconCelestialDisplayType; -import dev.galacticraft.impl.universe.position.config.OrbitalCelestialPositionConfig; -import dev.galacticraft.impl.universe.position.config.SatelliteConfig; -import dev.galacticraft.impl.universe.position.type.OrbitalCelestialPositionType; -import io.netty.buffer.Unpooled; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.core.RegistryAccess; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtOps; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.level.progress.ChunkProgressListener; -import net.minecraft.tags.TagKey; -import net.minecraft.util.valueproviders.UniformInt; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.BiomeManager; -import net.minecraft.world.level.border.BorderChangeListener; -import net.minecraft.world.level.chunk.ChunkStatus; -import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.level.dimension.LevelStem; -import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; -import net.minecraft.world.level.storage.DerivedLevelData; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.LinkedList; -import java.util.Locale; -import java.util.Objects; -import java.util.OptionalLong; - -public class SatelliteType extends CelestialBodyType implements Satellite, Landable { - public static final SatelliteType INSTANCE = new SatelliteType(SatelliteConfig.CODEC); - public static final ChunkProgressListener EMPTY_PROGRESS_LISTENER = new ChunkProgressListener() { - @Override - public void updateSpawnPos(ChunkPos spawnPos) { - } - - @Override - public void onStatusChange(ChunkPos pos, @Nullable ChunkStatus status) { - } - - @Override - public void start() { - } - - @Override - public void stop() { - } - }; - private static final GasComposition EMPTY_GAS_COMPOSITION = new GasComposition.Builder().build(); - private static final Component NAME = Component.translatable("ui.galacticraft-api.satellite.name"); - private static final Component DESCRIPTION = Component.translatable("ui.galacticraft-api.satellite.description"); - - protected SatelliteType(Codec codec) { - super(codec); - } - - @ApiStatus.Internal - public static CelestialBody registerSatellite(@NotNull MinecraftServer server, @NotNull ServerPlayer player, @NotNull CelestialBody parent, StructureTemplate structure) { - ResourceLocation id = new ResourceLocation(Objects.requireNonNull(server.registryAccess().registryOrThrow(AddonRegistry.CELESTIAL_BODY_KEY).getKey(parent)) + "_" + player.getScoreboardName().toLowerCase(Locale.ROOT)); - DimensionType type = new DimensionType(OptionalLong.empty(), true, false, false, true, 1, false, false, 0, 256, 256, TagKey.create(Registry.BLOCK_REGISTRY, new ResourceLocation(Constant.MOD_ID, "infiniburn_space")), new ResourceLocation(Constant.MOD_ID, "space_sky"), 0, new DimensionType.MonsterSettings(false, true, UniformInt.of(0, 7), 0)); - LevelStem options = new LevelStem(Holder.direct(type), new SatelliteChunkGenerator(server.registryAccess().registryOrThrow(Registry.STRUCTURE_SET_REGISTRY), Holder.direct(GcApiBiomes.SPACE), structure)); - SatelliteOwnershipData ownershipData = SatelliteOwnershipData.create(player.getUUID(), player.getScoreboardName(), new LinkedList<>(), false); - CelestialPosition position = new CelestialPosition<>(OrbitalCelestialPositionType.INSTANCE, new OrbitalCelestialPositionConfig(1550, 10.0f, 0.0F, false)); - CelestialDisplay display = new CelestialDisplay<>(IconCelestialDisplayType.INSTANCE, new IconCelestialDisplayConfig(new ResourceLocation(Constant.MOD_ID, "satellite"), 0, 0, 16, 16, 1)); - ResourceKey key = ResourceKey.create(Registry.DIMENSION_REGISTRY, id); - ResourceKey key2 = ResourceKey.create(Registry.DIMENSION_TYPE_REGISTRY, id); - assert server.getLevel(key) == null : "World already registered?!"; - assert server.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).get(key2) == null : "Dimension Type already registered?!"; - Registry.register(server.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY), id, type); - return create(id, server, parent, position, display, options, ownershipData, player.getGameProfile().getName() + "'s Space Station"); - } - - @ApiStatus.Internal - public static CelestialBody create(ResourceLocation id, MinecraftServer server, CelestialBody parent, CelestialPosition position, CelestialDisplay display, - LevelStem options, SatelliteOwnershipData ownershipData, String name) { - SatelliteConfig config = new SatelliteConfig(ResourceKey.create(AddonRegistry.CELESTIAL_BODY_KEY, server.registryAccess().registryOrThrow(AddonRegistry.CELESTIAL_BODY_KEY).getKey(parent)), parent.galaxy(), position, display, ownershipData, ResourceKey.create(Registry.DIMENSION_REGISTRY, id), EMPTY_GAS_COMPOSITION, 0.0f, parent.type() instanceof Landable ? ((Landable) parent.type()).accessWeight(parent.config()) : 1, options); - config.customName(Component.translatable(name)); - CelestialBody satellite = INSTANCE.configure(config); - ((SatelliteAccessor) server).addSatellite(id, satellite); - Constant.LOGGER.debug("Attempting to create a world dynamically ({})", id); - - DerivedLevelData unmodifiableLevelProperties = new DerivedLevelData(server.getWorldData(), server.getWorldData().overworldData()); - ServerLevel serverWorld2 = new ServerLevel(server, ((MinecraftServerAccessor) server).getWorkerExecutor(), ((MinecraftServerAccessor) server).getSession(), unmodifiableLevelProperties, ResourceKey.create(Registry.DIMENSION_REGISTRY, id), options, EMPTY_PROGRESS_LISTENER, server.getWorldData().worldGenSettings().isDebug(), BiomeManager.obfuscateSeed(server.getWorldData().worldGenSettings().seed()), ImmutableList.of(), false); - server.getLevel(Level.OVERWORLD).getWorldBorder().addListener(new BorderChangeListener.DelegateBorderChangeListener(serverWorld2.getWorldBorder())); - ((MinecraftServerAccessor) server).getWorlds().put(ResourceKey.create(Registry.DIMENSION_REGISTRY, id), serverWorld2); - - for (ServerPlayer player : server.getPlayerList().getPlayers()) { - CompoundTag compound = (CompoundTag) SatelliteConfig.CODEC.encode(satellite.config(), NbtOps.INSTANCE, new CompoundTag()).get().orThrow(); - ServerPlayNetworking.send(player, new ResourceLocation(Constant.MOD_ID, "add_satellite"), new FriendlyByteBuf(Unpooled.buffer()).writeResourceLocation(id).writeNbt(compound)); - } - return satellite; - } - - @Override - public @NotNull Component name(SatelliteConfig config) { - return NAME; - } - - @Override - public @Nullable CelestialBody parent(Registry> registry, SatelliteConfig config) { - return registry.get(config.parent()); - } - - @Override - public @NotNull ResourceKey galaxy(SatelliteConfig config) { - return config.galaxy(); - } - - @Override - public @NotNull Component description(SatelliteConfig config) { - return DESCRIPTION; - } - - @Override - public @NotNull CelestialPosition position(SatelliteConfig config) { - return config.position(); - } - - @Override - public @NotNull CelestialDisplay display(SatelliteConfig config) { - return config.display(); - } - - @Override - public SatelliteOwnershipData ownershipData(SatelliteConfig config) { - return config.ownershipData(); - } - - @Override - public void setCustomName(@NotNull Component text, SatelliteConfig config) { - config.customName(text); - } - - @Override - public @NotNull Component getCustomName(SatelliteConfig config) { - return config.customName(); - } - - @Override - public @NotNull ResourceKey world(SatelliteConfig config) { - return config.world(); - } - - @Override - public @NotNull GasComposition atmosphere(SatelliteConfig config) { - return config.atmosphere(); - } - - @Override - public float gravity(SatelliteConfig config) { - return config.gravity(); - } - - @Override - public int accessWeight(SatelliteConfig config) { - return config.accessWeight(); - } - - @Override - public CelestialBody configure(SatelliteConfig config) { - return new CelestialBody<>(this, config); - } - - @Override - public int temperature(RegistryAccess access, long time, SatelliteConfig config) { - return time % 24000 < 12000 ? 121 : -157; //todo: gradual temperature change - } -} diff --git a/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/SpaceStationType.java b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/SpaceStationType.java new file mode 100644 index 00000000..cf9e7558 --- /dev/null +++ b/src/main/java/dev/galacticraft/impl/universe/celestialbody/type/SpaceStationType.java @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2019-2022 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.impl.universe.celestialbody.type; + +import com.mojang.serialization.Codec; +import dev.galacticraft.api.accessor.SatelliteAccessor; +import dev.galacticraft.api.gas.GasComposition; +import dev.galacticraft.api.registry.AddonRegistry; +import dev.galacticraft.api.satellite.Satellite; +import dev.galacticraft.api.satellite.SatelliteOwnershipData; +import dev.galacticraft.api.universe.celestialbody.CelestialBody; +import dev.galacticraft.api.universe.celestialbody.CelestialBodyConfig; +import dev.galacticraft.api.universe.celestialbody.CelestialBodyType; +import dev.galacticraft.api.universe.celestialbody.landable.Landable; +import dev.galacticraft.api.universe.celestialbody.satellite.Orbitable; +import dev.galacticraft.api.universe.display.CelestialDisplay; +import dev.galacticraft.api.universe.galaxy.Galaxy; +import dev.galacticraft.api.universe.position.CelestialPosition; +import dev.galacticraft.dyndims.api.DynamicDimensionRegistry; +import dev.galacticraft.dyndims.api.PlayerRemover; +import dev.galacticraft.impl.Constant; +import dev.galacticraft.impl.internal.world.gen.SatelliteChunkGenerator; +import dev.galacticraft.impl.internal.world.gen.biome.GcApiBiomes; +import dev.galacticraft.impl.universe.display.config.IconCelestialDisplayConfig; +import dev.galacticraft.impl.universe.display.type.IconCelestialDisplayType; +import dev.galacticraft.impl.universe.position.config.OrbitalCelestialPositionConfig; +import dev.galacticraft.impl.universe.position.config.SpaceStationConfig; +import dev.galacticraft.impl.universe.position.type.OrbitalCelestialPositionType; +import io.netty.buffer.Unpooled; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.tags.TagKey; +import net.minecraft.util.valueproviders.ConstantInt; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.LinkedList; +import java.util.Locale; +import java.util.Objects; +import java.util.OptionalLong; + +public class SpaceStationType extends CelestialBodyType implements Satellite, Landable { + public static final SpaceStationType INSTANCE = new SpaceStationType(SpaceStationConfig.CODEC); + private static final PlayerRemover PLAYER_REMOVER = (server, player) -> { + CelestialBody> spaceStation = CelestialBody.getByDimension(server.registryAccess(), player.getLevel().dimension()).orElse(null); + if (spaceStation != null) { + CelestialBody parent = spaceStation.parent(server.registryAccess()); + if (parent != null) { + if (parent.type() instanceof Landable landable) { + ServerLevel level = server.getLevel(landable.world(parent.config())); + player.teleportTo(level, player.getX(), level.getMaxBuildHeight() * 2, player.getZ(), player.getYRot(), player.getXRot()); + player.setDeltaMovement((level.random.nextDouble() - 0.5) * 10.0, level.random.nextDouble() * 12.5, (level.random.nextDouble() - 0.5) * 10.0); + return; + } + } + } + ServerLevel overworld = server.overworld(); + player.teleportTo(overworld, 0, 1000, 0, player.getYRot(), player.getXRot()); + player.setDeltaMovement((overworld.random.nextDouble() - 0.5) * 10.0, overworld.random.nextDouble() * 20.0, (overworld.random.nextDouble() - 0.5) * 10.0); + }; + private static final GasComposition EMPTY_GAS_COMPOSITION = new GasComposition.Builder().build(); + private static final Component NAME = Component.translatable("ui.galacticraft-api.space_station.name"); + private static final Component DESCRIPTION = Component.translatable("ui.galacticraft-api.space_station.description"); + + protected SpaceStationType(Codec codec) { + super(codec); + } + + @ApiStatus.Experimental + public static CelestialBody registerSpaceStation(@NotNull MinecraftServer server, @NotNull ServerPlayer player, @NotNull CelestialBody parent, @NotNull StructureTemplate structure) { + ResourceLocation identifier = Objects.requireNonNull(server.registryAccess().registryOrThrow(AddonRegistry.CELESTIAL_BODY_KEY).getKey(parent)); + ResourceLocation id = new ResourceLocation(identifier.getNamespace(), "sat_" + identifier.getPath() + "_" + player.getGameProfile().getName().toLowerCase(Locale.ROOT)); + DimensionType type = new DimensionType(OptionalLong.empty(), true, false, false, true, 1, false, false, 0, 256, 256, TagKey.create(Registry.BLOCK_REGISTRY, new ResourceLocation(Constant.MOD_ID, "infiniburn_space")), new ResourceLocation(Constant.MOD_ID, "space_sky"), 1, new DimensionType.MonsterSettings(false, false, ConstantInt.of(0), 0)); + SatelliteOwnershipData ownershipData = SatelliteOwnershipData.create(player.getUUID(), player.getScoreboardName(), new LinkedList<>(), false); + CelestialPosition position = new CelestialPosition<>(OrbitalCelestialPositionType.INSTANCE, new OrbitalCelestialPositionConfig(1550, 10.0f, 0.0F, false)); + CelestialDisplay display = new CelestialDisplay<>(IconCelestialDisplayType.INSTANCE, new IconCelestialDisplayConfig(new ResourceLocation(Constant.MOD_ID, "satellite"), 0, 0, 16, 16, 1)); + ResourceKey key = ResourceKey.create(Registry.DIMENSION_REGISTRY, id); + ResourceKey key2 = ResourceKey.create(Registry.DIMENSION_TYPE_REGISTRY, id); + assert server.getLevel(key) == null : "Level already registered?!"; + assert server.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).get(key2) == null : "Dimension Type already registered?!"; + return create(id, server, parent, position, display, new SatelliteChunkGenerator(server.registryAccess().registryOrThrow(Registry.STRUCTURE_SET_REGISTRY), Holder.direct(GcApiBiomes.SPACE), structure), type, ownershipData, player.getGameProfile().getName() + "'s Space Station"); + } + + @ApiStatus.Experimental + public static CelestialBody create(ResourceLocation id, @NotNull MinecraftServer server, CelestialBody parent, CelestialPosition position, CelestialDisplay display, + ChunkGenerator chunkGenerator, DimensionType type, SatelliteOwnershipData ownershipData, String name) { + if (!(parent.type() instanceof Orbitable)) { + throw new IllegalArgumentException("Parent must be orbitable!"); + } + + Constant.LOGGER.debug("Attempting to create a level dynamically ({})", id); + if (!((DynamicDimensionRegistry) server).addDynamicDimension(id, chunkGenerator, type)) { + throw new RuntimeException("Failed to create dynamic level!"); + } + + SpaceStationConfig config = new SpaceStationConfig(ResourceKey.create(AddonRegistry.CELESTIAL_BODY_KEY, Objects.requireNonNull(server.registryAccess().registryOrThrow(AddonRegistry.CELESTIAL_BODY_KEY).getKey(parent))), parent.galaxy(), position, display, ownershipData, ResourceKey.create(Registry.DIMENSION_REGISTRY, id), EMPTY_GAS_COMPOSITION, 0.0f, parent.type() instanceof Landable ? ((Landable) parent.type()).accessWeight(parent.config()) : 1); + config.customName(Component.translatable(name)); + CelestialBody satellite = INSTANCE.configure(config); + ((SatelliteAccessor) server).addSatellite(id, satellite); + + for (ServerPlayer player : server.getPlayerList().getPlayers()) { + CompoundTag compound = (CompoundTag) SpaceStationConfig.CODEC.encode(satellite.config(), NbtOps.INSTANCE, new CompoundTag()).get().orThrow(); + ServerPlayNetworking.send(player, new ResourceLocation(Constant.MOD_ID, "add_satellite"), new FriendlyByteBuf(Unpooled.buffer()).writeResourceLocation(id).writeNbt(compound)); + } + return satellite; + } + + @ApiStatus.Experimental + public static boolean removeSatellite(@NotNull MinecraftServer server, ResourceLocation id) { + if (((DynamicDimensionRegistry) server).removeDynamicDimension(id, PLAYER_REMOVER)) { + ((SatelliteAccessor) server).removeSatellite(id); + + for (ServerPlayer player : server.getPlayerList().getPlayers()) { + ServerPlayNetworking.send(player, new ResourceLocation(Constant.MOD_ID, "remove_satellite"), new FriendlyByteBuf(Unpooled.buffer()).writeResourceLocation(id)); + } + return true; + } else { + return false; + } + } + + @Override + public @NotNull Component name(SpaceStationConfig config) { + return NAME; + } + + @Override + public @Nullable CelestialBody parent(@NotNull Registry> registry, @NotNull SpaceStationConfig config) { + return registry.get(config.parent()); + } + + @Override + public @NotNull ResourceKey galaxy(@NotNull SpaceStationConfig config) { + return config.galaxy(); + } + + @Override + public @NotNull Component description(SpaceStationConfig config) { + return DESCRIPTION; + } + + @Override + public @NotNull CelestialPosition position(@NotNull SpaceStationConfig config) { + return config.position(); + } + + @Override + public @NotNull CelestialDisplay display(@NotNull SpaceStationConfig config) { + return config.display(); + } + + @Override + public SatelliteOwnershipData ownershipData(@NotNull SpaceStationConfig config) { + return config.ownershipData(); + } + + @Override + public void setCustomName(@NotNull Component text, @NotNull SpaceStationConfig config) { + config.customName(text); + } + + @Override + public @NotNull Component getCustomName(@NotNull SpaceStationConfig config) { + return config.customName(); + } + + @Override + public @NotNull ResourceKey world(@NotNull SpaceStationConfig config) { + return config.world(); + } + + @Override + public @NotNull GasComposition atmosphere(@NotNull SpaceStationConfig config) { + return config.atmosphere(); + } + + @Override + public float gravity(@NotNull SpaceStationConfig config) { + return config.gravity(); + } + + @Override + public int accessWeight(@NotNull SpaceStationConfig config) { + return config.accessWeight(); + } + + @Override + public CelestialBody configure(SpaceStationConfig config) { + return new CelestialBody<>(this, config); + } + + @Override + public int temperature(RegistryAccess access, long time, SpaceStationConfig config) { + return time % 24000 < 12000 ? 121 : -157; //todo: gradual temperature change + } +} diff --git a/src/main/java/dev/galacticraft/impl/universe/display/type/EmptyCelestialDisplayType.java b/src/main/java/dev/galacticraft/impl/universe/display/type/EmptyCelestialDisplayType.java index 862581f7..ef9de96c 100644 --- a/src/main/java/dev/galacticraft/impl/universe/display/type/EmptyCelestialDisplayType.java +++ b/src/main/java/dev/galacticraft/impl/universe/display/type/EmptyCelestialDisplayType.java @@ -39,7 +39,7 @@ private EmptyCelestialDisplayType() { } @Override - public Vector4f render(PoseStack matrices, BufferBuilder buffer, int size, double mouseX, double mouseY, float delta, Consumer> shaderSetter, EmptyCelestialDisplayConfig config) { + public Vector4f render(PoseStack matrices, BufferBuilder buffer, float size, double mouseX, double mouseY, float delta, Consumer> shaderSetter, EmptyCelestialDisplayConfig config) { return NULL_VECTOR; } } diff --git a/src/main/java/dev/galacticraft/impl/universe/display/type/IconCelestialDisplayType.java b/src/main/java/dev/galacticraft/impl/universe/display/type/IconCelestialDisplayType.java index 9d4da710..622ff122 100644 --- a/src/main/java/dev/galacticraft/impl/universe/display/type/IconCelestialDisplayType.java +++ b/src/main/java/dev/galacticraft/impl/universe/display/type/IconCelestialDisplayType.java @@ -51,7 +51,7 @@ protected IconCelestialDisplayType(Codec codec) { } @Override - public Vector4f render(PoseStack matrices, BufferBuilder buffer, int size, double mouseX, double mouseY, float delta, Consumer> shaderSetter, IconCelestialDisplayConfig config) { + public Vector4f render(PoseStack matrices, BufferBuilder buffer, float size, double mouseX, double mouseY, float delta, Consumer> shaderSetter, IconCelestialDisplayConfig config) { shaderSetter.accept(GameRenderer::getPositionTexShader); Matrix4f positionMatrix = matrices.last().pose(); AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(config.texture()); diff --git a/src/main/java/dev/galacticraft/impl/universe/position/config/SatelliteConfig.java b/src/main/java/dev/galacticraft/impl/universe/position/config/SpaceStationConfig.java similarity index 81% rename from src/main/java/dev/galacticraft/impl/universe/position/config/SatelliteConfig.java rename to src/main/java/dev/galacticraft/impl/universe/position/config/SpaceStationConfig.java index 5b34e7c9..0a4bb853 100644 --- a/src/main/java/dev/galacticraft/impl/universe/position/config/SatelliteConfig.java +++ b/src/main/java/dev/galacticraft/impl/universe/position/config/SpaceStationConfig.java @@ -38,21 +38,19 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; -import net.minecraft.world.level.dimension.LevelStem; - -public final class SatelliteConfig implements CelestialBodyConfig { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - ResourceLocation.CODEC.fieldOf("parent").xmap(id -> ResourceKey.create(AddonRegistry.CELESTIAL_BODY_KEY, id), ResourceKey::location).forGetter(SatelliteConfig::parent), - ResourceLocation.CODEC.fieldOf("galaxy").xmap(id -> ResourceKey.create(AddonRegistry.GALAXY_KEY, id), ResourceKey::location).forGetter(SatelliteConfig::galaxy), - CelestialPosition.CODEC.fieldOf("position").forGetter(SatelliteConfig::position), - CelestialDisplay.CODEC.fieldOf("display").forGetter(SatelliteConfig::display), - SatelliteOwnershipData.CODEC.fieldOf("ownership_data").forGetter(SatelliteConfig::ownershipData), - ResourceLocation.CODEC.fieldOf("world").xmap(id -> ResourceKey.create(Registry.DIMENSION_REGISTRY, id), ResourceKey::location).forGetter(SatelliteConfig::world), - GasComposition.CODEC.fieldOf("atmosphere").forGetter(SatelliteConfig::atmosphere), - Codec.FLOAT.fieldOf("gravity").forGetter(SatelliteConfig::gravity), - Codec.INT.fieldOf("accessWeight").forGetter(SatelliteConfig::accessWeight), - LevelStem.CODEC.fieldOf("dimension_options").forGetter(SatelliteConfig::dimensionOptions) - ).apply(instance, SatelliteConfig::new)); + +public final class SpaceStationConfig implements CelestialBodyConfig { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ResourceLocation.CODEC.fieldOf("parent").xmap(id -> ResourceKey.create(AddonRegistry.CELESTIAL_BODY_KEY, id), ResourceKey::location).forGetter(SpaceStationConfig::parent), + ResourceLocation.CODEC.fieldOf("galaxy").xmap(id -> ResourceKey.create(AddonRegistry.GALAXY_KEY, id), ResourceKey::location).forGetter(SpaceStationConfig::galaxy), + CelestialPosition.CODEC.fieldOf("position").forGetter(SpaceStationConfig::position), + CelestialDisplay.CODEC.fieldOf("display").forGetter(SpaceStationConfig::display), + SatelliteOwnershipData.CODEC.fieldOf("ownership_data").forGetter(SpaceStationConfig::ownershipData), + ResourceLocation.CODEC.fieldOf("world").xmap(id -> ResourceKey.create(Registry.DIMENSION_REGISTRY, id), ResourceKey::location).forGetter(SpaceStationConfig::world), + GasComposition.CODEC.fieldOf("atmosphere").forGetter(SpaceStationConfig::atmosphere), + Codec.FLOAT.fieldOf("gravity").forGetter(SpaceStationConfig::gravity), + Codec.INT.fieldOf("accessWeight").forGetter(SpaceStationConfig::accessWeight) + ).apply(instance, SpaceStationConfig::new)); private final ResourceKey> parent; private final ResourceKey galaxy; @@ -63,10 +61,9 @@ public final class SatelliteConfig implements CelestialBodyConfig { private final GasComposition atmosphere; private final float gravity; private final int accessWeight; - private final LevelStem options; private Component customName = Component.empty(); - public SatelliteConfig(ResourceKey> parent, ResourceKey galaxy, CelestialPosition position, CelestialDisplay display, SatelliteOwnershipData ownershipData, ResourceKey world, GasComposition atmosphere, float gravity, int accessWeight, LevelStem options) { + public SpaceStationConfig(ResourceKey> parent, ResourceKey galaxy, CelestialPosition position, CelestialDisplay display, SatelliteOwnershipData ownershipData, ResourceKey world, GasComposition atmosphere, float gravity, int accessWeight) { this.parent = parent; this.galaxy = galaxy; this.position = position; @@ -76,7 +73,6 @@ public SatelliteConfig(ResourceKey> parent, ResourceKey> parent() {return parent;} @@ -101,13 +97,11 @@ public SatelliteConfig(ResourceKey> parent, ResourceKey