Skip to content

Commit

Permalink
Merge pull request #7
Browse files Browse the repository at this point in the history
Change config records into classes to run on 1.19
  • Loading branch information
MaxenceDC authored Nov 9, 2023
2 parents 7a0eabe + e2506f1 commit 1cc9d5e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.maxencedc.sparsestructures;

import org.jetbrains.annotations.NotNull;

import java.util.List;

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
Expand Up @@ -4,6 +4,14 @@

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,6 +2,7 @@

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.*;
Expand Down Expand Up @@ -30,7 +31,7 @@ private static <E> void load(RegistryOps.RegistryInfoGetter registryInfoGetter,
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();
}).findFirst().orElse(new 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);
if (separation >= spacing) {
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"
}
}

0 comments on commit 1cc9d5e

Please sign in to comment.