Skip to content

Commit

Permalink
big fix bom
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed May 22, 2023
1 parent 3f999d5 commit edf3b42
Show file tree
Hide file tree
Showing 42 changed files with 300 additions and 190 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ repositories {
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
}
maven {
url = "https://jitpack.io"
}
}

dependencies {
Expand All @@ -53,6 +56,10 @@ dependencies {

//Modmenu
modImplementation "maven.modrinth:modmenu:${project.mod_menu_version}"

//MixinExtras
implementation("com.github.LlamaLad7:MixinExtras:0.1.1")
annotationProcessor("com.github.LlamaLad7:MixinExtras:0.1.1")
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.19.2+build.28
loader_version=0.14.19

# Mod Properties
mod_version=1.0.6
mod_version=1.1.0
maven_group=dev.sterner
archives_base_name=geocluster

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/dev/sterner/geocluster/Geocluster.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.sterner.geocluster;

import dev.sterner.geocluster.api.GeoclusterAPI;
import dev.sterner.geocluster.client.network.S2CProspectingPacket;
import dev.sterner.geocluster.client.toast.IOreToastManager;
import dev.sterner.geocluster.client.toast.OreToastManager;
Expand All @@ -15,7 +14,6 @@
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.toast.ToastManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand All @@ -37,7 +35,6 @@ public static Identifier id(String id) {
@Override
public void onInitialize() {
MidnightConfig.init(MODID, GeoclusterConfig.class);
GeoclusterAPI.init();
GeoclusterObjects.init();
GeoclusterWorldgenRegistry.init();
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new WorldGenDataReloadListener());
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/dev/sterner/geocluster/GeoclusterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
public class GeoclusterConfig extends MidnightConfig {

@Entry
public static double CHUNK_SKIP_CHANCE = 0.9D;
public static final boolean REMOVE_VEINS = true;

@Entry
public static double CHUNK_SKIP_CHANCE = 0.95D;

@Entry(min = 1, max = Integer.MAX_VALUE)
public static int NUMBER_CLUSTERS_PER_CHUNK = 2;
Expand All @@ -18,7 +21,7 @@ public class GeoclusterConfig extends MidnightConfig {
public static boolean DEBUG_WORLD_GEN = false;

@Entry(min = 1, max = 256)
public static int MAX_SAMPLES_PER_CHUNK = 10;
public static int MAX_SAMPLES_PER_CHUNK = 8;

@Entry
public static List<String> DEFAULT_REPLACEMENT_MATERIALS = Lists.newArrayList("minecraft:stone", "minecraft:andesite", "minecraft:diorite", "minecraft:granite", "minecraft:netherrack", "minecraft:sandstone", "minecraft:deepslate", "minecraft:tuff", "minecraft:calcite", "minecraft:dripstone_block");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/sterner/geocluster/api/DepositCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
import java.util.List;

public class DepositCache {
private static DepositCache cache = new DepositCache();
private ArrayList<IDeposit> deposits;

public DepositCache() {
this.deposits = new ArrayList<>();
}

public static DepositCache getCache(){
return cache;
}

public void clear() {
this.deposits = new ArrayList<>();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/sterner/geocluster/api/DepositUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public class DepositUtils {

private static HashSet<BlockState> defaultMatchersCached = null;

/**
* picks a choice out of a mapping between blockstate to weight
*
* @param map the map between a blockstate and its chance
* @return null if no block should be used or placed, T instanceof BlockState if
* actual block should be placed.
*/
@Nullable
public static BlockState pick(HashMap<BlockState, Float> map, Random random) {
float rng = random.nextFloat();
Expand Down Expand Up @@ -56,6 +63,10 @@ public static boolean addDefaultMatcher(Block block) {
return false;
}

/**
* Returns true if a and b are within epsilon of each other, where epsilon is the minimum
* representable value by a 32-bit floating point number.
*/
public static boolean nearlyEquals(float a, float b) {
return Math.abs(a - b) <= Float.MIN_VALUE;
}
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/dev/sterner/geocluster/api/GeoclusterAPI.java

This file was deleted.

11 changes: 11 additions & 0 deletions src/main/java/dev/sterner/geocluster/api/IDeposit.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@
import java.util.HashSet;

public interface IDeposit {
/**
* Handles full-on generation of this type of cluster. Requires 0 arguments as
* everything is self-contained in this class
*
* @return (int) the number of cluster resource blocks placed. If 0 -- this
* should be evaluted as a false for use of Mojang's sort-of sketchy
* generation code in
*/
int generate(StructureWorldAccess level, BlockPos pos, IWorldDepositComponent deposits, IWorldChunkComponent chunksGenerated);

/**
* Handles what to do after the world has generated
*/
void generatePost(StructureWorldAccess level, BlockPos pos, IWorldDepositComponent deposits, IWorldChunkComponent chunksGenerated);

HashSet<BlockState> getAllOres();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.util.math.random.Random;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.Heightmap;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -53,33 +54,7 @@ public DenseDeposit(HashMap<String, HashMap<BlockState, Float>> oreBlocks, HashM
this.biomeTag = biomeTag;
this.blockStateMatchers = blockStateMatchers;

// Verify that blocks.default exists.
if (!this.oreToWeightMap.containsKey("default")) {
throw new RuntimeException("Cluster blocks should always have a default key");
}

for (Map.Entry<String, HashMap<BlockState, Float>> i : this.oreToWeightMap.entrySet()) {
if (!this.cumulativeOreWeightMap.containsKey(i.getKey())) {
this.cumulativeOreWeightMap.put(i.getKey(), 0.0F);
}

for (Map.Entry<BlockState, Float> j : i.getValue().entrySet()) {
float v = this.cumulativeOreWeightMap.get(i.getKey());
this.cumulativeOreWeightMap.put(i.getKey(), v + j.getValue());
}

if (!DepositUtils.nearlyEquals(this.cumulativeOreWeightMap.get(i.getKey()), 1.0F)) {
throw new RuntimeException("Sum of weights for cluster blocks should equal 1.0" + ", is " + this.cumulativeOreWeightMap.get(i.getKey()));
}
}

for (Map.Entry<BlockState, Float> e : this.sampleToWeightMap.entrySet()) {
this.sumWeightSamples += e.getValue();
}

if (!DepositUtils.nearlyEquals(sumWeightSamples, 1.0F)) {
throw new RuntimeException("Sum of weights for cluster samples should equal 1.0");
}
validateFormat(oreToWeightMap, cumulativeOreWeightMap, sampleToWeightMap, sumWeightSamples);
}

@Nullable
Expand All @@ -103,7 +78,9 @@ public int generate(StructureWorldAccess world, BlockPos pos, IWorldDepositCompo

int totlPlaced = 0;
int randY = this.yMin + world.getRandom().nextInt(this.yMax - this.yMin);
int max = GeoclusterUtils.getTopSolidBlock(world, pos).getY();
int max;
max = GeoclusterUtils.getTopSolidBlock(world, pos).getY();

if (randY > max) {
randY = Math.max(yMin, max);
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/dev/sterner/geocluster/api/deposits/Deposit.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ public Deposit() {

}

public static void validateFormat(HashMap<String, HashMap<BlockState, Float>> oreToWeightMap, HashMap<String, Float> cumulativeOreWeightMap, HashMap<BlockState, Float> sampleToWeightMap, float sumWeightSamples){
if (!oreToWeightMap.containsKey("default")) {
throw new RuntimeException("Cluster blocks should always have a default key");
}

for (Map.Entry<String, HashMap<BlockState, Float>> i : oreToWeightMap.entrySet()) {
if (!cumulativeOreWeightMap.containsKey(i.getKey())) {
cumulativeOreWeightMap.put(i.getKey(), 0.0F);
}

for (Map.Entry<BlockState, Float> j : i.getValue().entrySet()) {
float v = cumulativeOreWeightMap.get(i.getKey());
cumulativeOreWeightMap.put(i.getKey(), v + j.getValue());
}

if (!DepositUtils.nearlyEquals(cumulativeOreWeightMap.get(i.getKey()), 1.0F)) {
throw new RuntimeException("Sum of weights for cluster blocks should equal 1.0, is " + cumulativeOreWeightMap.get(i.getKey()));
}
}

for (Map.Entry<BlockState, Float> e : sampleToWeightMap.entrySet()) {
sumWeightSamples += e.getValue();
}

if (!DepositUtils.nearlyEquals(sumWeightSamples, 1.0F)) {
throw new RuntimeException("Sum of weights for cluster samples should equal 1.0, is " + sumWeightSamples);
}
}

public static void findAndPlaceSample(int maxSampleCnt, BlockState sampleState, StructureWorldAccess world, BlockPos pos, IWorldDepositComponent deposits, IWorldChunkComponent chunksGenerated) {
for (int i = 0; i < maxSampleCnt; i++) {
BlockState tmp = sampleState;
Expand Down
50 changes: 15 additions & 35 deletions src/main/java/dev/sterner/geocluster/api/deposits/DikeDeposit.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
Expand All @@ -37,48 +38,24 @@ public class DikeDeposit extends Deposit implements IDeposit {
public float sumWeightSamples = 0.0F;
private final int yMin;
private final int yMax;
private final int maxHeight;
private final int baseRadius;
private final int weight;
private final HashSet<BlockState> blockStateMatchers;
private final TagKey<Biome> biomeTag;

public DikeDeposit(HashMap<String, HashMap<BlockState, Float>> oreBlocks, HashMap<BlockState, Float> sampleBlocks, int yMin, int yMax, int baseRadius, int weight, TagKey<Biome> biomeTag, HashSet<BlockState> blockStateMatchers) {
public DikeDeposit(HashMap<String, HashMap<BlockState, Float>> oreBlocks, HashMap<BlockState, Float> sampleBlocks, int yMin, int yMax, int baseRadius, int maxHeight, int weight, TagKey<Biome> biomeTag, HashSet<BlockState> blockStateMatchers) {
this.oreToWeightMap = oreBlocks;
this.sampleToWeightMap = sampleBlocks;
this.yMin = yMin;
this.yMax = yMax;
this.maxHeight = maxHeight;
this.baseRadius = baseRadius;
this.weight = weight;
this.biomeTag = biomeTag;
this.blockStateMatchers = blockStateMatchers;

// Verify that blocks.default exists.
if (!this.oreToWeightMap.containsKey("default")) {
throw new RuntimeException("Cluster blocks should always have a default key");
}

for (Map.Entry<String, HashMap<BlockState, Float>> i : this.oreToWeightMap.entrySet()) {
if (!this.cumulativeOreWeightMap.containsKey(i.getKey())) {
this.cumulativeOreWeightMap.put(i.getKey(), 0.0F);
}

for (Map.Entry<BlockState, Float> j : i.getValue().entrySet()) {
float v = this.cumulativeOreWeightMap.get(i.getKey());
this.cumulativeOreWeightMap.put(i.getKey(), v + j.getValue());
}

if (!DepositUtils.nearlyEquals(this.cumulativeOreWeightMap.get(i.getKey()), 1.0F)) {
throw new RuntimeException("Sum of weights for cluster blocks should equal 1.0" + ", is " + i.getKey());
}
}

for (Map.Entry<BlockState, Float> e : this.sampleToWeightMap.entrySet()) {
this.sumWeightSamples += e.getValue();
}

if (!DepositUtils.nearlyEquals(sumWeightSamples, 1.0F)) {
throw new RuntimeException("Sum of weights for cluster samples should equal 1.0");
}
validateFormat(oreToWeightMap, cumulativeOreWeightMap, sampleToWeightMap, sumWeightSamples);
}


Expand Down Expand Up @@ -132,17 +109,18 @@ public int generate(StructureWorldAccess world, BlockPos pos, IWorldDepositCompo
}

ChunkPos thisChunk = new ChunkPos(pos);

int height = Math.abs((this.yMax - this.yMin));
int x = thisChunk.getStartX() + world.getRandom().nextInt(16);
int z = thisChunk.getStartZ() + world.getRandom().nextInt(16);
int yMin = this.yMin + world.getRandom().nextInt(height / 4);
int yMax = this.yMax - world.getRandom().nextInt(height / 4);
int max = GeoclusterUtils.getTopSolidBlock(world, pos).getY();
if (yMin > max) {
yMin = Math.max(yMin, max);
} else if (yMin == yMax) {
yMax = this.yMax;
}

int cmaxHeight = maxHeight - world.getRandom().nextBetween(0, maxHeight / 4);
int maxStart = MathHelper.abs(yMax - cmaxHeight - yMin);
yMin = world.getRandom().nextInt(maxStart + 1) + yMin;
yMax = yMin + cmaxHeight;

BlockPos basePos = new BlockPos(x, yMin, z);

int totlPlaced = 0;
Expand Down Expand Up @@ -219,6 +197,7 @@ public static DikeDeposit deserialize(JsonObject json) {
int yMin = json.get("yMin").getAsInt();
int yMax = json.get("yMax").getAsInt();
int baseRadius = json.get("baseRadius").getAsInt();
int maxHeight = json.get("maxHeight").getAsInt();
int genWt = json.get("generationWeight").getAsInt();
TagKey<Biome> biomeTag = TagKey.of(Registry.BIOME_KEY, new Identifier(json.get("biomeTag").getAsString().replace("#", "")));

Expand All @@ -227,7 +206,7 @@ public static DikeDeposit deserialize(JsonObject json) {
blockStateMatchers = SerializerUtils.toBlockStateList(json.get("blockStateMatchers").getAsJsonArray());
}

return new DikeDeposit(oreBlocks, sampleBlocks, yMin, yMax, baseRadius, genWt, biomeTag, blockStateMatchers);
return new DikeDeposit(oreBlocks, sampleBlocks, yMin, yMax, baseRadius, maxHeight, genWt, biomeTag, blockStateMatchers);
} catch (Exception e) {
Geocluster.LOGGER.error("Failed to parse: {}", e.getMessage());
return null;
Expand All @@ -243,6 +222,7 @@ public JsonElement serialize() {
config.addProperty("yMin", this.yMin);
config.addProperty("yMax", this.yMax);
config.addProperty("baseRadius", this.baseRadius);
config.addProperty("maxHeight", this.maxHeight);
config.addProperty("generationWeight", this.getWeight());
config.addProperty("biomeTag", this.biomeTag.id().toString());
json.addProperty("type", JSON_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,7 @@ public LayerDeposit(HashMap<String, HashMap<BlockState, Float>> oreBlocks, HashM
this.biomeTag = biomeTag;
this.blockStateMatchers = blockStateMatchers;

// Verify that blocks.default exists.
if (!this.oreToWeightMap.containsKey("default")) {
throw new RuntimeException("Cluster blocks should always have a default key");
}

for (Map.Entry<String, HashMap<BlockState, Float>> i : this.oreToWeightMap.entrySet()) {
if (!this.cumulativeOreWeightMap.containsKey(i.getKey())) {
this.cumulativeOreWeightMap.put(i.getKey(), 0.0F);
}

for (Map.Entry<BlockState, Float> j : i.getValue().entrySet()) {
float v = this.cumulativeOreWeightMap.get(i.getKey());
this.cumulativeOreWeightMap.put(i.getKey(), v + j.getValue());
}

if (!DepositUtils.nearlyEquals(this.cumulativeOreWeightMap.get(i.getKey()), 1.0F)) {
throw new RuntimeException("Sum of weights for cluster blocks should equal 1.0" + ", is " + i.getKey());
}
}

for (Map.Entry<BlockState, Float> e : this.sampleToWeightMap.entrySet()) {
this.sumWeightSamples += e.getValue();
}

if (!DepositUtils.nearlyEquals(sumWeightSamples, 1.0F)) {
throw new RuntimeException("Sum of weights for cluster samples should equal 1.0");
}
validateFormat(oreToWeightMap, cumulativeOreWeightMap, sampleToWeightMap, sumWeightSamples);
}


Expand Down
Loading

0 comments on commit edf3b42

Please sign in to comment.