-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
157 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/teampotato/sparsestructuresreforged/CustomSpreadFactors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.teampotato.sparsestructuresreforged; | ||
|
||
public class CustomSpreadFactors { | ||
public String structure; | ||
public double factor; | ||
|
||
public CustomSpreadFactors(String structure, double factor) { | ||
this.structure = structure; | ||
this.factor = factor; | ||
} | ||
|
||
public String structure() { | ||
return this.structure; | ||
} | ||
|
||
public double factor() { | ||
return this.factor; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/teampotato/sparsestructuresreforged/SparseStructures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.teampotato.sparsestructuresreforged; | ||
|
||
import com.google.gson.Gson; | ||
import net.minecraftforge.fml.common.Mod; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
@Mod(SparseStructures.MOD_ID) | ||
public class SparseStructures { | ||
public static final String MOD_ID = "sparsestructuresreforged"; | ||
private static final String CONFIG_RESOURCE_NAME = "sparse-structures-default-config.json5"; | ||
private static final String CONFIG_FILENAME = "sparsestructures.json5"; | ||
private static final Path CONFIG_FILE_PATH = Paths.get("config", CONFIG_FILENAME); | ||
public static SparseStructuresConfig config; | ||
|
||
public SparseStructures() { | ||
if (!CONFIG_FILE_PATH.toFile().exists()) { | ||
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(CONFIG_RESOURCE_NAME)) { | ||
if (in == null) throw new IllegalStateException("Failed to load SparseStructure's default config \"" + CONFIG_RESOURCE_NAME +"\""); | ||
Files.createDirectories(CONFIG_FILE_PATH); | ||
Files.copy(in, CONFIG_FILE_PATH, StandardCopyOption.REPLACE_EXISTING); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
try (final InputStream in = Files.newInputStream(CONFIG_FILE_PATH)) { | ||
config = new Gson().fromJson(new InputStreamReader(in), SparseStructuresConfig.class); | ||
} catch (Exception e) { | ||
throw new RuntimeException("SparseStructure's config file is malformed! If you don't know what's causing this, delete the config file and restart the game."); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/teampotato/sparsestructuresreforged/SparseStructuresConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.teampotato.sparsestructuresreforged; | ||
|
||
import java.util.List; | ||
|
||
public class SparseStructuresConfig { | ||
public double spreadFactor; | ||
public List<CustomSpreadFactors> customSpreadFactors; | ||
|
||
public SparseStructuresConfig(double spreadFactor, List<CustomSpreadFactors> customSpreadFactors) { | ||
this.spreadFactor = spreadFactor; | ||
this.customSpreadFactors = customSpreadFactors; | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
src/main/java/com/teampotato/sparsestructuresreforged/SparseStructuresReforged.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/main/java/com/teampotato/sparsestructuresreforged/mixin/RegistryDataLoaderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.teampotato.sparsestructuresreforged.mixin; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.Decoder; | ||
import com.teampotato.sparsestructuresreforged.CustomSpreadFactors; | ||
import com.teampotato.sparsestructuresreforged.SparseStructures; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.WritableRegistry; | ||
import net.minecraft.resources.*; | ||
import net.minecraft.server.packs.resources.Resource; | ||
import net.minecraft.server.packs.resources.ResourceManager; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; | ||
|
||
import java.io.Reader; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
@Mixin(RegistryDataLoader.class) | ||
public abstract class RegistryDataLoaderMixin { | ||
@Inject(method = "loadRegistryContents", at = @At(value = "INVOKE", remap = false, target = "Lcom/mojang/serialization/Decoder;parse(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) | ||
private static <E> void ssr$init(RegistryOps.RegistryInfoLookup lookup, ResourceManager manager, ResourceKey<? extends Registry<E>> registryKey, WritableRegistry<E> registry, Decoder<E> decoder, Map<ResourceKey<?>, Exception> exceptions, CallbackInfo ci, String string, FileToIdConverter converter, RegistryOps<JsonElement> registryOps, Iterator<Map.Entry<ResourceLocation, Resource>> iterator, Map.Entry<ResourceLocation, Resource> entry, ResourceLocation resourcelocation, ResourceKey<E> resourceKey, Resource resource, Reader reader, JsonElement jsonElement) { | ||
JsonObject jsonObject = jsonElement.getAsJsonObject(); | ||
JsonObject placement = jsonObject.getAsJsonObject("placement"); | ||
if (string.equals("worldgen/structure_set") && !placement.get("type").getAsString().equals("minecraft:concentric_rings")) { | ||
double factor = SparseStructures.config.customSpreadFactors.stream().filter(s -> { | ||
if (s == null) return false; | ||
String structure_set = resourceKey.location().toString(); | ||
return structure_set.equals(s.structure()) || jsonObject.getAsJsonArray("structures").asList().stream().anyMatch(p -> p.getAsJsonObject().get("structure").getAsString().equals(s.structure())); | ||
}).findFirst().orElse(new CustomSpreadFactors("", SparseStructures.config.spreadFactor)).factor(); | ||
|
||
int spacing; | ||
int separation; | ||
|
||
if (placement.get("spacing") == null) spacing = 1; | ||
else spacing = (int)(Math.min(placement.get("spacing").getAsDouble() * factor, 4096.0)); | ||
if (placement.get("separation") == null) separation = 1; | ||
else separation = (int)(Math.min(placement.get("separation").getAsDouble() * factor, 4096.0)); | ||
if (separation >= spacing) { | ||
if (spacing == 0) spacing = 1; | ||
separation = spacing - 1; | ||
} | ||
|
||
placement.addProperty("spacing", spacing); | ||
placement.addProperty("separation", separation); | ||
} | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
...ava/com/teampotato/sparsestructuresreforged/mixin/StructureFeatureConfigurationMixin.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// ### THE MOD REQUIRES A RESTART OF THE GAME TO APPLY CHANGES ### | ||
{ | ||
// this is the main spread factor (default is 2) | ||
// | ||
// tips : a spread factor can be a decimal number (such as 1.5) | ||
// a spread factor of 1 means all structure's placement are not modified (useful if you want to use only custom spread factors) | ||
// a spread factor above 1 means all structures are rarer | ||
// a spread factor below 1 means all structure are more common | ||
"spreadFactor": 2, | ||
|
||
// this is a list of custom spread factors | ||
"customSpreadFactors": [ | ||
// example of the mansion being doubled in rarity (the mod's default) | ||
{ | ||
"structure": "minecraft:mansion", | ||
"factor": 2 | ||
}, | ||
// add the structures you want to modify in the format: | ||
// { | ||
// "structure": "namespace:structure_name", | ||
// "factor": number | ||
// }, | ||
// where "structure" is a structure_set or the name of a structure | ||
// /!\ if you put the name of a structure, all structures in its set will be modified | ||
// (example : "minecraft:village_plains" will modify all structures in the "villages" set) | ||
// see https://minecraft.wiki/w/Tutorials/Custom_structures#Structure_Set for more info | ||
// | ||
// tip : the same spread factors rules apply here | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"required": true, | ||
"package": "com.teampotato.sparsestructuresreforged.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"compatibilityLevel": "JAVA_17", | ||
"minVersion": "0.8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
"StructureFeatureConfigurationMixin" | ||
"RegistryDataLoaderMixin" | ||
] | ||
} |