Skip to content

Commit

Permalink
add orbit dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
screret committed Oct 25, 2023
1 parent ab7cbcd commit f5be77a
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import java.util.function.Function;

public record Planet(String translation, ResourceLocation galaxy, ResourceLocation solarSystem,
ResourceKey<Level> level,
ResourceKey<Level> parentWorld, int rocketTier, float gravity,
ResourceKey<Level> level, ResourceKey<Level> orbitWorld, ResourceKey<Level> parentWorld,
int rocketTier, float gravity,
boolean hasAtmosphere, int daysInYear, float temperature, long solarPower,
boolean hasOxygen, int buttonColor) {

Expand All @@ -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),
Expand All @@ -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> level, Optional<ResourceKey<Level>> 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> level, ResourceKey<Level> orbitWorld, Optional<ResourceKey<Level>> 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<ResourceKey<Level>> getParentlevel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class PlanetData extends SimpleJsonResourceReloadListener {
private static final BiMap<ResourceLocation, Planet> PLANETS = HashBiMap.create();
private static final BiMap<ResourceLocation, List<Planet>> SOLAR_SYSTEMS = HashBiMap.create();
private static final BiMap<ResourceKey<Level>, Planet> LEVEL_TO_PLANET = HashBiMap.create();
private static final Map<ResourceKey<Level>, Planet> ORBIT_TO_PLANET = new HashMap<>();
private static final Set<ResourceKey<Level>> PLANET_LEVELS = new HashSet<>();
private static final Set<ResourceKey<Level>> ORBITS_LEVELS = new HashSet<>();
private static final Set<ResourceKey<Level>> OXYGEN_LEVELS = new HashSet<>();

public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
Expand Down Expand Up @@ -70,7 +72,9 @@ public static void updatePlanets(Map<ResourceLocation, Planet> 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());
}
Expand All @@ -80,6 +84,9 @@ public static void updatePlanets(Map<ResourceLocation, Planet> planets) {
private static void clear() {
PLANETS.clear();
LEVEL_TO_PLANET.clear();
ORBIT_TO_PLANET.clear();
PLANET_LEVELS.clear();
ORBITS_LEVELS.clear();
OXYGEN_LEVELS.clear();
}

Expand Down Expand Up @@ -134,12 +141,16 @@ public static Optional<Planet> getPlanetFromLevel(ResourceKey<Level> level) {
return Optional.ofNullable(LEVEL_TO_PLANET.get(level));
}

public static Optional<Planet> getPlanetFromOrbit(ResourceKey<Level> level) {
return Optional.ofNullable(ORBIT_TO_PLANET.get(level));
}

public static Optional<ResourceKey<Level>> getLevelFromPlanet(Planet planet) {
return Optional.ofNullable(LEVEL_TO_PLANET.inverse().get(planet));
}

public static boolean isOrbitLevel(ResourceKey<Level> level) {
return level.location().equals(GCySDimensionTypes.SPACE_LEVEL.location());
return ORBITS_LEVELS.contains(level);
}

public static boolean isPlanetLevel(Level level) {
Expand Down
6 changes: 6 additions & 0 deletions common/src/main/resources/data/gcys/dimension/luna_orbit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "gcys:space",
"generator": {
"type": "gcys:space"
}
}

0 comments on commit f5be77a

Please sign in to comment.