Skip to content

Commit

Permalink
Added more reload listeners + Rocket and RocketPart structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Juniper Primavera committed Sep 20, 2023
1 parent 8a2001d commit 8227d3d
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 1.20.1 2023-09-20T18:39:15.494323252 Propulsive/Advancements
2 changes: 1 addition & 1 deletion src/main/java/io/github/teampropulsive/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void register() {
})).build());
}

private static Item registerItem(String path, Item item) {
public static Item registerItem(String path, Item item) {
return Registry.register(Registries.ITEM, Propulsive.id(path), item);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/github/teampropulsive/Propulsive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.teampropulsive.block.Blocks;
import io.github.teampropulsive.celestial.Star;
import io.github.teampropulsive.celestial.Terrestrial;
import io.github.teampropulsive.data.GasReloadListener;
import io.github.teampropulsive.data.RocketReloadListener;
import io.github.teampropulsive.screen.BlueprintTableScreenHandler;
import io.github.teampropulsive.types.AtmoCompositionGas;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void onInitialize() {
BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Feature.UNDERGROUND_ORES, PURE_BAUXITE_CLUSTER_PLACED_KEY);

ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new RocketReloadListener());
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new GasReloadListener());
}

// Dimensions
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/io/github/teampropulsive/data/GasReloadListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.teampropulsive.data;

import com.google.gson.Gson;

import io.github.teampropulsive.Items;
import io.github.teampropulsive.Propulsive;
import io.github.teampropulsive.types.Gas;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

public class GasReloadListener implements SimpleSynchronousResourceReloadListener {
@Override
public Identifier getFabricId() {
return Propulsive.id("gas");
}

@Override
public void reload(ResourceManager manager) {
// Clear caches here

for (Map.Entry<Identifier, Resource> entry : manager.findResources("gases", path -> path.getPath().endsWith(".json")).entrySet()) {
Identifier id = entry.getKey();
Resource resource = entry.getValue();
try (InputStream stream = resource.getInputStream()) { // Pretty sure this works, just gotta register it somehow (?)
Gas new_gas = new Gson().fromJson(new String(stream.readAllBytes(), StandardCharsets.UTF_8), Gas.class);

} catch (Exception e) {
Propulsive.LOGGER.error("Error occurred while loading gas " + id.toString(), e);
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.teampropulsive.data;

import com.google.gson.Gson;
import io.github.teampropulsive.Propulsive;
import io.github.teampropulsive.types.Gas;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

public class PlanetReloadListener implements SimpleSynchronousResourceReloadListener {
@Override
public Identifier getFabricId() {
return Propulsive.id("gas");
}

@Override
public void reload(ResourceManager manager) {
// Clear caches here

for (Map.Entry<Identifier, Resource> entry : manager.findResources("planets", path -> path.getPath().endsWith(".json")).entrySet()) {
Identifier id = entry.getKey();
Resource resource = entry.getValue();
try (InputStream stream = resource.getInputStream()) {

} catch (Exception e) {
Propulsive.LOGGER.error("Error occurred while loading planet " + id.toString(), e);
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/github/teampropulsive/types/Gas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.minecraft.util.Identifier;

public class Gas {
public Identifier type;
public Identifier identifier;
public double density; // g/L at stp
public Gas(Identifier type, double density) {
this.type = type;
this.identifier = type;
this.density = density;
}
}
22 changes: 22 additions & 0 deletions src/main/java/io/github/teampropulsive/types/Rocket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.teampropulsive.types;

import java.util.ArrayList;

public class Rocket {
double mass = 0;
double drag = 1.0;
int cargoSlots = 0;
int playerSeats = 0;
ArrayList<RocketPart> parts;

public Rocket(ArrayList<RocketPart> parts) {
for (RocketPart part : parts) {
this.mass += part.mass;
this.drag *= part.dragMultiplier;
this.cargoSlots += part.extraCargoSlots;
this.playerSeats += part.extraPlayerSeats;


}
}
}
15 changes: 15 additions & 0 deletions src/main/java/io/github/teampropulsive/types/RocketPart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.teampropulsive.types;

public class RocketPart {
public double mass;
public double dragMultiplier;
public int extraCargoSlots;
public int extraPlayerSeats;

public RocketPart(double mass, double dragMultiplier, int extraCargoSlots, int extraPlayerSeats) {
this.mass = mass;
this.dragMultiplier = dragMultiplier;
this.extraCargoSlots = extraCargoSlots;
this.extraPlayerSeats = extraPlayerSeats;
}
}

0 comments on commit 8227d3d

Please sign in to comment.