From f5be77a66716580aa1b8f5ffdb7e6483290ea131 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Wed, 25 Oct 2023 09:47:42 +0300 Subject: [PATCH] add orbit dimensions --- .../gcys/api/space/planet/Planet.java | 9 +++++---- .../gui/screen/PlanetSelectionScreen.java | 2 +- .../multiblock/RocketScannerMachine.java | 19 ++++++++++++++++--- .../s2c/PacketSyncDysonSphereStatus.java | 5 ----- .../common/worldgen/SpaceLevelSource.java | 10 +++++++++- .../gcys/data/lang/LangHandler.java | 1 + .../gcys/data/loader/PlanetData.java | 13 ++++++++++++- .../data/gcys/dimension/luna_orbit.json | 6 ++++++ 8 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 common/src/main/resources/data/gcys/dimension/luna_orbit.json diff --git a/common/src/main/java/argent_matter/gcys/api/space/planet/Planet.java b/common/src/main/java/argent_matter/gcys/api/space/planet/Planet.java index 0d1beb48..08d1b79a 100644 --- a/common/src/main/java/argent_matter/gcys/api/space/planet/Planet.java +++ b/common/src/main/java/argent_matter/gcys/api/space/planet/Planet.java @@ -15,8 +15,8 @@ import java.util.function.Function; public record Planet(String translation, ResourceLocation galaxy, ResourceLocation solarSystem, - ResourceKey level, - ResourceKey parentWorld, int rocketTier, float gravity, + ResourceKey level, ResourceKey orbitWorld, ResourceKey parentWorld, + int rocketTier, float gravity, boolean hasAtmosphere, int daysInYear, float temperature, long solarPower, boolean hasOxygen, int buttonColor) { @@ -25,6 +25,7 @@ public record Planet(String translation, ResourceLocation galaxy, ResourceLocati ResourceLocation.CODEC.fieldOf("galaxy").forGetter(Planet::galaxy), ResourceLocation.CODEC.fieldOf("solar_system").forGetter(Planet::solarSystem), ResourceKey.codec(Registries.DIMENSION).fieldOf("world").forGetter(Planet::level), + ResourceKey.codec(Registries.DIMENSION).fieldOf("orbit_world").forGetter(Planet::orbitWorld), ResourceKey.codec(Registries.DIMENSION).optionalFieldOf("parent_world").forGetter(Planet::getParentlevel), Codec.INT.fieldOf("rocket_tier").forGetter(Planet::rocketTier), Codec.FLOAT.fieldOf("gravity").forGetter(Planet::gravity), @@ -49,8 +50,8 @@ public record Planet(String translation, ResourceLocation galaxy, ResourceLocati DIRECT_CODEC ).xmap(either -> either.map(Function.identity(), Function.identity()), Either::left); - public Planet(String translation, ResourceLocation galaxy, ResourceLocation solarSystem, ResourceKey level, Optional> parentWorld, int rocketTier, float gravity, boolean hasAtmosphere, int daysInYear, float temperature, long solarPower, boolean hasOxygen, int buttonColor) { - this(translation, galaxy, solarSystem, level, parentWorld.orElse(null), rocketTier, gravity, hasAtmosphere, daysInYear, temperature, solarPower, hasOxygen, buttonColor); + public Planet(String translation, ResourceLocation galaxy, ResourceLocation solarSystem, ResourceKey level, ResourceKey orbitWorld, Optional> parentWorld, int rocketTier, float gravity, boolean hasAtmosphere, int daysInYear, float temperature, long solarPower, boolean hasOxygen, int buttonColor) { + this(translation, galaxy, solarSystem, level, orbitWorld, parentWorld.orElse(null), rocketTier, gravity, hasAtmosphere, daysInYear, temperature, solarPower, hasOxygen, buttonColor); } private Optional> getParentlevel() { diff --git a/common/src/main/java/argent_matter/gcys/client/gui/screen/PlanetSelectionScreen.java b/common/src/main/java/argent_matter/gcys/client/gui/screen/PlanetSelectionScreen.java index a966669e..4a8420d9 100644 --- a/common/src/main/java/argent_matter/gcys/client/gui/screen/PlanetSelectionScreen.java +++ b/common/src/main/java/argent_matter/gcys/client/gui/screen/PlanetSelectionScreen.java @@ -219,7 +219,7 @@ protected void init() { } createTeleportButton(1, label, planetCategory, planet.buttonColor(), 71, 20, TooltipType.PLANET, planet, planet.level()); - createTeleportButton(2, ORBIT_TEXT, planetCategory, planet.buttonColor(), 37, 20, TooltipType.ORBIT, null, planet.level()); + createTeleportButton(2, ORBIT_TEXT, planetCategory, planet.buttonColor(), 37, 20, TooltipType.ORBIT, null, planet.orbitWorld()); createSpaceStationTeleportButton(3, SPACE_STATION_TEXT, planetCategory, planet.buttonColor(), 71, 20, planet.level()); }); diff --git a/common/src/main/java/argent_matter/gcys/common/machine/multiblock/RocketScannerMachine.java b/common/src/main/java/argent_matter/gcys/common/machine/multiblock/RocketScannerMachine.java index 500bde93..5e5dffcd 100644 --- a/common/src/main/java/argent_matter/gcys/common/machine/multiblock/RocketScannerMachine.java +++ b/common/src/main/java/argent_matter/gcys/common/machine/multiblock/RocketScannerMachine.java @@ -20,6 +20,7 @@ import com.gregtechceu.gtceu.common.data.GTMaterials; import com.lowdragmc.lowdraglib.gui.modular.ModularUI; import com.lowdragmc.lowdraglib.gui.util.ClickData; +import com.lowdragmc.lowdraglib.gui.widget.ButtonWidget; import com.lowdragmc.lowdraglib.gui.widget.ComponentPanelWidget; import com.lowdragmc.lowdraglib.gui.widget.SlotWidget; import com.lowdragmc.lowdraglib.misc.ItemStackTransfer; @@ -61,12 +62,9 @@ public class RocketScannerMachine extends MultiblockControllerMachine implements @Persisted private int lDist = 0, rDist = 0, bDist = 0, hDist = 0; - @Persisted @DescSynced @Getter private boolean rocketBuilt; - - @Getter @Persisted private final ItemStackTransfer configSaveSlot, configLoadSlot; @@ -87,6 +85,7 @@ public ModularUI createUI(Player entityPlayer) { ModularUI modularUI = IDisplayUIMachine.super.createUI(entityPlayer); modularUI.widget(new SlotWidget(configSaveSlot, 0, 149, 83)); modularUI.widget(new SlotWidget(configLoadSlot, 0, 149, 105)); + modularUI.widget(new ButtonWidget(129, 105, 18, 18, this::onSaveButtonClick).setHoverTooltips(Component.translatable("menu.gcys.save_destination_station"))); return modularUI; } @@ -113,6 +112,20 @@ public void handleDisplayClick(String componentData, ClickData clickData) { } } + private void onSaveButtonClick(ClickData data) { + if (data.isRemote) return; + + ItemStack saveStack = this.configSaveSlot.getStackInSlot(0); + if (GCySItems.ID_CHIP.isIn(saveStack)) { + Planet planet = PlanetIdChipBehaviour.getPlanetFromStack(saveStack); + if (planet == null) return; + + ItemStack keyCardStack = GCySItems.KEYCARD.asStack(1); + KeyCardBehaviour.setSavedStation(keyCardStack, PlanetIdChipBehaviour.getSpaceStationId(saveStack), planet); + this.configLoadSlot.setStackInSlot(0, keyCardStack); + } + } + private void onSaveSlotChanged() { ItemStack saveStack = this.configSaveSlot.getStackInSlot(0); if (GCySItems.ID_CHIP.isIn(saveStack)) { diff --git a/common/src/main/java/argent_matter/gcys/common/networking/s2c/PacketSyncDysonSphereStatus.java b/common/src/main/java/argent_matter/gcys/common/networking/s2c/PacketSyncDysonSphereStatus.java index a93601a9..5816d8eb 100644 --- a/common/src/main/java/argent_matter/gcys/common/networking/s2c/PacketSyncDysonSphereStatus.java +++ b/common/src/main/java/argent_matter/gcys/common/networking/s2c/PacketSyncDysonSphereStatus.java @@ -22,9 +22,4 @@ public void decode(FriendlyByteBuf buf) { this.isSphereActive = buf.readBoolean(); GCySClient.isDysonSphereActive = isSphereActive; } - - @Override - public void execute(IHandlerContext handler) { - IPacket.super.execute(handler); - } } diff --git a/common/src/main/java/argent_matter/gcys/common/worldgen/SpaceLevelSource.java b/common/src/main/java/argent_matter/gcys/common/worldgen/SpaceLevelSource.java index 3a5aa358..12b497f5 100644 --- a/common/src/main/java/argent_matter/gcys/common/worldgen/SpaceLevelSource.java +++ b/common/src/main/java/argent_matter/gcys/common/worldgen/SpaceLevelSource.java @@ -82,7 +82,7 @@ public int getMinY() { @Override public int getBaseHeight(int x, int z, Heightmap.Types type, LevelHeightAccessor level, RandomState random) { - return 64; + return 0; } @Override @@ -102,6 +102,14 @@ public void applyBiomeDecoration(WorldGenLevel level, ChunkAccess chunk, Structu int chunkX = chunkPos.x; int chunkZ = chunkPos.z; + for (int x1 = 0; x1 < 16; ++x1) { + for (int z1 = 0; z1 < 16; ++z1) { + int blockX = SectionPos.sectionToBlockCoord(chunkX, x1); + int blockZ = SectionPos.sectionToBlockCoord(chunkZ, z1); + level.setBlock(mutableBlockPos.set(blockX, 256, blockZ), Blocks.BARRIER.defaultBlockState(), 2); + } + } + if (chunkX % 16 == 0 && chunkZ % 16 == 0) { //GCyS.LOGGER.info("made platform"); for(int x = -4; x < 4; ++x) { diff --git a/common/src/main/java/argent_matter/gcys/data/lang/LangHandler.java b/common/src/main/java/argent_matter/gcys/data/lang/LangHandler.java index 63b94647..b4a4fc8c 100644 --- a/common/src/main/java/argent_matter/gcys/data/lang/LangHandler.java +++ b/common/src/main/java/argent_matter/gcys/data/lang/LangHandler.java @@ -76,6 +76,7 @@ public static void init(RegistrateLangProvider provider) { provider.add("menu.gcys.dyson_sphere.collapsed", "DYSON SPHERE COLLAPSED"); provider.add("menu.gcys.launch", "LAUNCH"); + provider.add("menu.gcys.save_destination_station", "Save Space Station ID to keycard"); provider.add("menu.gcys.catalog", "Catalog"); provider.add("menu.gcys.back", "Back"); diff --git a/common/src/main/java/argent_matter/gcys/data/loader/PlanetData.java b/common/src/main/java/argent_matter/gcys/data/loader/PlanetData.java index b03e1994..6d0020c9 100644 --- a/common/src/main/java/argent_matter/gcys/data/loader/PlanetData.java +++ b/common/src/main/java/argent_matter/gcys/data/loader/PlanetData.java @@ -37,7 +37,9 @@ public class PlanetData extends SimpleJsonResourceReloadListener { private static final BiMap PLANETS = HashBiMap.create(); private static final BiMap> SOLAR_SYSTEMS = HashBiMap.create(); private static final BiMap, Planet> LEVEL_TO_PLANET = HashBiMap.create(); + private static final Map, Planet> ORBIT_TO_PLANET = new HashMap<>(); private static final Set> PLANET_LEVELS = new HashSet<>(); + private static final Set> ORBITS_LEVELS = new HashSet<>(); private static final Set> OXYGEN_LEVELS = new HashSet<>(); public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); @@ -70,7 +72,9 @@ public static void updatePlanets(Map planets) { PLANETS.put(id, planet); SOLAR_SYSTEMS.computeIfAbsent(planet.solarSystem(), system -> new ArrayList<>()).add(planet); LEVEL_TO_PLANET.put(planet.level(), planet); + ORBIT_TO_PLANET.put(planet.orbitWorld(), planet); PLANET_LEVELS.add(planet.level()); + ORBITS_LEVELS.add(planet.orbitWorld()); if (planet.hasOxygen()) { OXYGEN_LEVELS.add(planet.level()); } @@ -80,6 +84,9 @@ public static void updatePlanets(Map planets) { private static void clear() { PLANETS.clear(); LEVEL_TO_PLANET.clear(); + ORBIT_TO_PLANET.clear(); + PLANET_LEVELS.clear(); + ORBITS_LEVELS.clear(); OXYGEN_LEVELS.clear(); } @@ -134,12 +141,16 @@ public static Optional getPlanetFromLevel(ResourceKey level) { return Optional.ofNullable(LEVEL_TO_PLANET.get(level)); } + public static Optional getPlanetFromOrbit(ResourceKey level) { + return Optional.ofNullable(ORBIT_TO_PLANET.get(level)); + } + public static Optional> getLevelFromPlanet(Planet planet) { return Optional.ofNullable(LEVEL_TO_PLANET.inverse().get(planet)); } public static boolean isOrbitLevel(ResourceKey level) { - return level.location().equals(GCySDimensionTypes.SPACE_LEVEL.location()); + return ORBITS_LEVELS.contains(level); } public static boolean isPlanetLevel(Level level) { diff --git a/common/src/main/resources/data/gcys/dimension/luna_orbit.json b/common/src/main/resources/data/gcys/dimension/luna_orbit.json new file mode 100644 index 00000000..431dd7c6 --- /dev/null +++ b/common/src/main/resources/data/gcys/dimension/luna_orbit.json @@ -0,0 +1,6 @@ +{ + "type": "gcys:space", + "generator": { + "type": "gcys:space" + } +} \ No newline at end of file