Skip to content

Commit

Permalink
big changes
Browse files Browse the repository at this point in the history
- make different orbits use separate levels
  • Loading branch information
screret committed Oct 25, 2023
1 parent f5be77a commit 9a8d2f3
Show file tree
Hide file tree
Showing 33 changed files with 161 additions and 182 deletions.
19 changes: 3 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@

0.0.2.b:
- fix Dyson Sphere Casing recipe
- fix lang issues
- add Atomic Casing recipe
- fix dyson crash on fabric

0.0.2.a:
- fix fabric
- make dyson sphere able to collapse if left without maintenance
- add dyson sphere maintenance logic
- remove rocket launch keybind


0.0.2:
- initial release
- make space stations use different dimensions per planet orbit
- remove "orbit" button from planet selection screen, it did nothing
-
2 changes: 1 addition & 1 deletion common/src/main/java/argent_matter/gcys/GCyS.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void onLevelTick(Level ticked, boolean isStart) {
if (sat != null) sat.tickSatellites();
}

IDysonSystem system = DysonSystemSavedData.getOrCreate(level);
IDysonSystem system = GcysCapabilityHelper.getDysonSystem(level);
if (system == null || TICKED_SYSTEMS.get().contains(system)) return;
system.tick();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import argent_matter.gcys.api.space.dyson.DysonSystemSavedData;
import argent_matter.gcys.api.space.satellite.capability.SatelliteWorldSavedData;
import argent_matter.gcys.api.space.station.StationWorldSavedData;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;

import javax.annotation.Nullable;

public class GcysCapabilityHelper {
@Nullable
public static ISpaceStationHolder getSpaceStations(ServerLevel level) {
public static ISpaceStationHolder getSpaceStations(@Nullable ServerLevel level) {
return StationWorldSavedData.getOrCreate(level);
}

Expand All @@ -20,7 +19,7 @@ public static ISatelliteHolder getSatellites(ServerLevel level) {
}

@Nullable
public static IDysonSystem getDysonSystem(ServerLevel level, @Nullable BlockPos pos) {
return DysonSystemSavedData.getOrCreateMaybeSpace(level, pos);
public static IDysonSystem getDysonSystem(ServerLevel level) {
return DysonSystemSavedData.getOrCreate(level);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ public interface ISpaceStationHolder {
*/
Int2ObjectMap<SpaceStation> getStations();

/**
* @return all space stations orbiting this planet.
*/
Set<SpaceStation> getStationsForPlanet(Planet planet);

/**
* @param position the position from which distance is measured from
* @return the closest satellite to this position, or null if none
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package argent_matter.gcys.api.space.dyson;

import argent_matter.gcys.GCyS;
import argent_matter.gcys.api.capability.GcysCapabilityHelper;
import argent_matter.gcys.api.capability.IDysonSystem;
import argent_matter.gcys.api.capability.ISpaceStationHolder;
import argent_matter.gcys.api.space.planet.Planet;
import argent_matter.gcys.common.data.GCySDimensionTypes;
import argent_matter.gcys.common.data.GCySNetworking;
import argent_matter.gcys.common.data.GCySSatellites;
import argent_matter.gcys.common.networking.s2c.PacketSyncDysonSphereStatus;
Expand All @@ -15,9 +12,11 @@
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
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.world.level.saveddata.SavedData;
Expand All @@ -33,10 +32,9 @@ public class DysonSystemSavedData extends SavedData implements IDysonSystem {
public static DysonSystemSavedData getOrCreate(ServerLevel originLevel) {
if (originLevel.dimensionType().hasCeiling()) return null;

Planet planet = PlanetData.getPlanetFromLevel(originLevel.dimension()).orElse(null);
if (planet == null) return null; // A planet definition is required.
ResourceLocation solarSystem = PlanetData.getPlanetFromLevelOrOrbit(originLevel.dimension()).map(Planet::solarSystem).orElse(null);
if (solarSystem == null) return null; // A planet definition is required.

ResourceLocation solarSystem = planet.solarSystem();
List<Planet> planets = PlanetData.getSolarSystemPlanets(solarSystem);
if (planets.isEmpty()) {
internalGetOrCreate(originLevel);
Expand All @@ -45,28 +43,6 @@ public static DysonSystemSavedData getOrCreate(ServerLevel originLevel) {
return internalGetOrCreate(Objects.requireNonNullElse(firstWorldLevel, originLevel));
}

@Nullable
public static DysonSystemSavedData getOrCreateMaybeSpace(ServerLevel level, @Nullable BlockPos pos) {
if (pos != null && level.dimension().location().equals(GCySDimensionTypes.SPACE_LEVEL.location())) {
ISpaceStationHolder spaceStations = GcysCapabilityHelper.getSpaceStations(level);
if (spaceStations == null) return null;
List<Integer> nearbyStationIds = spaceStations.getStationsNearWorldPos(pos, 8 * 8 /*half of max station size*/);
if (nearbyStationIds.isEmpty()) return null;
return getOrCreateForSpace(level.getServer(), nearbyStationIds.get(0));
}
return getOrCreate(level);
}

@Nullable
public static DysonSystemSavedData getOrCreateForSpace(MinecraftServer server, int stationId) {
ISpaceStationHolder spaceStations = GcysCapabilityHelper.getSpaceStations(server.getLevel(GCySDimensionTypes.SPACE_LEVEL));
if (spaceStations == null) return null;

ServerLevel serverLevel = server.getLevel(spaceStations.getStation(stationId).orbitPlanet().level());
if (serverLevel == null) return null;
return getOrCreate(serverLevel);
}

private static DysonSystemSavedData internalGetOrCreate(ServerLevel serverLevel) {
return serverLevel.getDataStorage().computeIfAbsent(tag -> new DysonSystemSavedData(serverLevel, tag), () -> new DysonSystemSavedData(serverLevel), GCyS.MOD_ID + "_dyson_systems");
}
Expand Down Expand Up @@ -99,7 +75,7 @@ public boolean isDysonSphereActive() {

@Override
public int activeDysonSwarmSatelliteCount() {
return (int) swarmSatellites.values().stream().flatMap(Collection::stream).count();
return swarmSatellites.values().stream().mapToInt(Collection::size).sum();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import argent_matter.gcys.GCyS;
import argent_matter.gcys.api.capability.ISpaceStationHolder;
import argent_matter.gcys.api.space.planet.Planet;
import argent_matter.gcys.common.data.GCySDimensionTypes;
import argent_matter.gcys.common.worldgen.SpaceLevelSource;
import argent_matter.gcys.data.loader.PlanetData;
import argent_matter.gcys.util.Vec2i;
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand All @@ -20,15 +19,14 @@
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class StationWorldSavedData extends SavedData implements ISpaceStationHolder {
@Nullable
public static StationWorldSavedData getOrCreate(ServerLevel serverLevel) {
if (serverLevel.dimension() != GCySDimensionTypes.SPACE_LEVEL) return null;
public static StationWorldSavedData getOrCreate(@Nullable ServerLevel serverLevel) {
if (serverLevel == null || !PlanetData.isOrbitLevel(serverLevel.dimension())) return null;
return serverLevel.getDataStorage().computeIfAbsent(tag -> new StationWorldSavedData(serverLevel, tag), () -> new StationWorldSavedData(serverLevel), GCyS.MOD_ID + "_space_stations");
}

Expand All @@ -55,11 +53,6 @@ public Int2ObjectMap<SpaceStation> getStations() {
return stations;
}

@Override
public Set<SpaceStation> getStationsForPlanet(Planet planet) {
return stations.values().stream().filter(spaceStation -> spaceStation.orbitPlanet().equals(planet)).collect(Collectors.toSet());
}

@Override
public int getClosestStationId(Vec2i position) {
var result = stations.int2ObjectEntrySet().stream().min(Comparator.comparingDouble(obj -> obj.getValue().position().distanceToSqr(position))).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.level.Level;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*;
import java.util.function.Consumer;

@Environment(EnvType.CLIENT)
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class PlanetSelectionScreen extends Screen implements MenuAccess<PlanetSelectionMenu> {

public static final ResourceLocation SMALL_MENU_LIST = GCyS.id("textures/gui/selection_menu.png");
Expand Down Expand Up @@ -87,7 +89,6 @@ public PlanetSelectionScreen(PlanetSelectionMenu handler, Inventory inventory, C
}

// Set the initial gui time to the level time. This creates a random start position for each rotating object.
//noinspection resource
guiTime = handler.getPlayer().level().getRandom().nextFloat() * 100000.0f;
}

Expand Down Expand Up @@ -219,8 +220,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.orbitWorld());
createSpaceStationTeleportButton(3, SPACE_STATION_TEXT, planetCategory, planet.buttonColor(), 71, 20, planet.level());
createSpaceStationTeleportButton(2, SPACE_STATION_TEXT, planetCategory, planet.buttonColor(), 71, 20, planet.orbitWorld());
});

this.galaxyCategories.forEach((this::createGalaxyButton));
Expand Down Expand Up @@ -285,7 +285,7 @@ public void createTeleportButton(int row, Component label, Category category, in
LinkedList<ExtendedButton> buttons = this.categoryButtons.getOrDefault(category, new LinkedList<>());

int column = getColumn(category) - (row - 1) * 22;
column -= 44 * (buttons.size() / 3);
column -= 22 * (buttons.size() / 2);
createButton(newRow + 10, column, label, category, colour, sizeX, sizeY, tooltip, planetInfo, onClick);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;

public class GCySDimensionTypes {
public static final ResourceKey<DimensionType> SPACE_DIMENSION = ResourceKey.create(Registries.DIMENSION_TYPE, GCyS.id("space"));
public static final ResourceKey<Level> SPACE_LEVEL = ResourceKey.create(Registries.DIMENSION, GCyS.id("space"));
public static final ResourceKey<DimensionType> SPACE_TYPE = ResourceKey.create(Registries.DIMENSION_TYPE, GCyS.id("space"));

public static void init() {
initGenerator();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package argent_matter.gcys.common.data;

import argent_matter.gcys.common.recipe.DysonSphereCondition;
import argent_matter.gcys.common.recipe.OrbitCondition;
import com.gregtechceu.gtceu.api.registry.GTRegistries;

public class GCySRecipeConditions {

public static void init() {
GTRegistries.RECIPE_CONDITIONS.register(DysonSphereCondition.INSTANCE.getType(), DysonSphereCondition.class);
GTRegistries.RECIPE_CONDITIONS.register(OrbitCondition.INSTANCE.getType(), OrbitCondition.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.List;
import java.util.Set;

@SuppressWarnings("resource")
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class RocketEntity extends Entity implements HasCustomInventoryScreen, IUIHolder {
Expand Down Expand Up @@ -414,12 +415,8 @@ private void goToDestination() {
} else if (GCySItems.KEYCARD.isIn(configStack) && KeyCardBehaviour.getSavedStation(configStack) != SpaceStation.ID_EMPTY) {
this.destinationIsSpaceStation = true;
}
final ServerLevel destinationLevel;
if (this.destinationIsSpaceStation) {
destinationLevel = this.getServer().getLevel(GCySDimensionTypes.SPACE_LEVEL);
} else {
destinationLevel = this.getServer().getLevel(destination.level());
}
final ServerLevel destinationLevel = this.getServer().getLevel(this.destinationIsSpaceStation ? destination.orbitWorld() : destination.level());


Vec3 pos = this.position();

Expand Down Expand Up @@ -652,13 +649,6 @@ protected void readAdditionalSaveData(CompoundTag compound) {
for (int i = 0; i < blocks.size(); ++i) {
this.addBlock(PosWithState.readFromTag(blocks.getCompound(i)));
}
/*
this.getSeatPositions().clear();
ListTag seats = compound.getList("seats", Tag.TAG_COMPOUND);
for (int i = 0; i < seats.size(); ++i) {
this.addSeatPos(NbtUtils.readBlockPos(seats.getCompound(i)));
}
*/

this.setFuelCapacity(compound.getLong("fuelCapacity"));
this.fuelTank.setFluid(FluidStack.loadFromTag(compound.getCompound("fuel")));
Expand All @@ -677,14 +667,6 @@ protected void addAdditionalSaveData(CompoundTag compound) {
for (PosWithState state : blocks) {
blockTag.add(state.writeToTag());
}
/*
var seats = this.getSeatPositions();
ListTag seatsTag = new ListTag();
compound.put("seat", seatsTag);
for (BlockPos seatPos : seats) {
seatsTag.add(NbtUtils.writeBlockPos(seatPos));
}
*/

compound.putLong("fuelCapacity", this.getFuelCapacity());
CompoundTag fuel = new CompoundTag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import argent_matter.gcys.common.data.GCySItems;
import argent_matter.gcys.common.data.GCySMenus;
import argent_matter.gcys.data.loader.PlanetData;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.gregtechceu.gtceu.api.item.component.IAddInformation;
import com.gregtechceu.gtceu.api.item.component.IInteractionItem;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
Expand All @@ -28,8 +25,6 @@
import java.util.List;

public class PlanetIdChipBehaviour implements IInteractionItem, IAddInformation {
private static final BiMap<String, Planet> PLANET_NAME_CACHE = HashBiMap.create();

public static final String CURRENT_STATION_TAG_ID = "gcys:current_station";
public static final String CURRENT_PLANET_TAG_ID = "gcys:current_planet";

Expand All @@ -54,18 +49,12 @@ public static int getSpaceStationId(ItemStack held) {
}

public String getPlanetName(Planet currentTarget) {
return PLANET_NAME_CACHE.inverse().computeIfAbsent(currentTarget, planet -> PlanetData.getLevelFromPlanet(planet).map(level -> "level." + level.location().toLanguageKey()).orElse("UNKNOWN LEVEL"));
}

public static void setPlanetFromName(String planetName, ItemStack held) {
if (!GCySItems.ID_CHIP.isIn(held)) return;
Planet currentTarget = PLANET_NAME_CACHE.computeIfAbsent(planetName, (name) -> PlanetData.getPlanetFromLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.of(name.substring(6), '.'))).orElse(null));
held.getOrCreateTag().putString(CURRENT_PLANET_TAG_ID, currentTarget.level().location().toString());
return currentTarget.translation();
}

@Nullable
public static Planet getPlanetFromStack(ItemStack stack) {
return PlanetData.getPlanetFromLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(stack.getOrCreateTag().getString(CURRENT_PLANET_TAG_ID)))).orElse(null);
return PlanetData.getPlanetFromLevelOrOrbit(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(stack.getOrCreateTag().getString(CURRENT_PLANET_TAG_ID)))).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import argent_matter.gcys.common.item.KeyCardBehaviour;
import argent_matter.gcys.common.item.PlanetIdChipBehaviour;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IDisplayUIMachine;
import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockControllerMachine;
Expand Down Expand Up @@ -73,19 +74,17 @@ public RocketScannerMachine(IMachineBlockEntity holder) {
super(holder);
this.configSaveSlot = new ItemStackTransfer(1);
this.configSaveSlot.setFilter(GCySItems.ID_CHIP::isIn);
this.configSaveSlot.setOnContentsChanged(this::onSaveSlotChanged);

this.configLoadSlot = new ItemStackTransfer(1);
this.configLoadSlot.setFilter(GCySItems.KEYCARD::isIn);
this.configLoadSlot.setOnContentsChanged(this::onLoadSlotChanged);
}

@Override
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")));
modularUI.widget(new ButtonWidget(129, 83, 18, 18, this::onSaveButtonClick).setButtonTexture(GuiTextures.BUTTON).setHoverTooltips(Component.translatable("menu.gcys.save_destination_station")));
return modularUI;
}

Expand Down
Loading

0 comments on commit 9a8d2f3

Please sign in to comment.