Skip to content

Commit

Permalink
Compatible with 1.19 & 1.20.
Browse files Browse the repository at this point in the history
Fixed #8 and #5 (related).
Fixed #3.
  • Loading branch information
MaxenceDC committed Nov 9, 2023
1 parent 7a0eabe commit f6864cd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ For now (v2.0), you have to restart the game for the config to be reloaded. This
This mod doesn't have any (not even fabric-api).

## Future Updates
* World-specific configs
* *Open an issue on this project's repo if you have any suggestion!*
* *~~Add an option to blacklist mods/structures.~~* (added in v2.0)
* *~~Add an option to change the spread factor.~~* (added in v2.0)
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23
loader_version=0.14.24

# Mod Properties
mod_version = 2.0
mod_version = 2.1
maven_group = io.github.maxencedc
archives_base_name = sparsestructures

# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.90.0+1.20.2
fabric_version=0.90.7+1.20.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.maxencedc.sparsestructures;

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;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package io.github.maxencedc.sparsestructures;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public record SparseStructuresConfig(double spreadFactor, List<customSpreadFactors> customSpreadFactors) {
public record customSpreadFactors(String structure, double factor) {}
public class SparseStructuresConfig {
public double spreadFactor;
public double spreadFactor() { return this.spreadFactor; }
public List<CustomSpreadFactors> customSpreadFactors;
public List<CustomSpreadFactors> customSpreadFactors() { return this.customSpreadFactors; }
public SparseStructuresConfig(double spreadFactor, List<CustomSpreadFactors> customSpreadFactors)
{
this.spreadFactor = spreadFactor;
this.customSpreadFactors = customSpreadFactors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import com.google.gson.JsonElement;
import com.mojang.serialization.Decoder;
import io.github.maxencedc.sparsestructures.CustomSpreadFactors;
import io.github.maxencedc.sparsestructures.SparseStructures;
import io.github.maxencedc.sparsestructures.SparseStructuresConfig;
import net.minecraft.registry.*;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceFinder;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -25,14 +24,14 @@ public abstract class SparseStructuresRegistryLoaderMixin {

@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/Decoder;parse(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;"), method = "load(Lnet/minecraft/registry/RegistryOps$RegistryInfoGetter;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V", locals = LocalCapture.CAPTURE_FAILHARD)
private static <E> void load(RegistryOps.RegistryInfoGetter registryInfoGetter, ResourceManager resourceManager, RegistryKey<? extends Registry<E>> registryRef, MutableRegistry<E> newRegistry, Decoder<E> decoder, Map<RegistryKey<?>, Exception> exceptions, CallbackInfo ci, String string, ResourceFinder resourceFinder, RegistryOps registryOps, Iterator var9, Map.Entry entry, Identifier identifier, RegistryKey registryKey, Resource resource, Reader reader, JsonElement jsonElement) {
if (string.equals("worldgen/structure_set") && jsonElement.getAsJsonObject().getAsJsonObject("placement").get("type").getAsString().equals("minecraft:random_spread")) {
if (string.equals("worldgen/structure_set") && !jsonElement.getAsJsonObject().getAsJsonObject("placement").get("type").getAsString().equals("minecraft:concentric_rings")) {
double factor = SparseStructures.config.customSpreadFactors().stream().filter(s -> {
if (s == null) return false;
String structure_set = registryKey.getValue().toString();
return structure_set.equals(s.structure()) || jsonElement.getAsJsonObject().getAsJsonArray("structures").asList().stream().anyMatch(p -> p.getAsJsonObject().get("structure").getAsString().equals(s.structure()));
}).findFirst().orElse(new SparseStructuresConfig.customSpreadFactors("", SparseStructures.config.spreadFactor())).factor();
int spacing = (int)(jsonElement.getAsJsonObject().getAsJsonObject("placement").get("spacing").getAsDouble() * factor);
int separation = (int)(jsonElement.getAsJsonObject().getAsJsonObject("placement").get("separation").getAsDouble() * factor);
}).findFirst().orElse(new CustomSpreadFactors("", SparseStructures.config.spreadFactor())).factor();
int spacing = (int)(Math.min(jsonElement.getAsJsonObject().getAsJsonObject("placement").get("spacing").getAsDouble() * factor, 4096.0));
int separation = (int)(Math.min(jsonElement.getAsJsonObject().getAsJsonObject("placement").get("separation").getAsDouble() * factor, 4096.0));
if (separation >= spacing) {
if (spacing == 0) spacing = 1;
separation = spacing - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
},

"depends": {
"minecraft": "1.20.x"
"minecraft": ["1.19.x", "1.20.x"]
}
}

0 comments on commit f6864cd

Please sign in to comment.