Small fixes, custom biome data

This commit is contained in:
paulevsGitch 2021-06-06 20:33:12 +03:00
parent 6487efb3de
commit 6e882d08d9
4 changed files with 48 additions and 11 deletions

View file

@ -8,7 +8,7 @@ yarn_mappings=6
loader_version=0.11.3 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version = 0.1.17 mod_version = 0.1.18
maven_group = ru.bclib maven_group = ru.bclib
archives_base_name = bclib archives_base_name = bclib

View file

@ -1,5 +1,6 @@
package ru.bclib.util; package ru.bclib.util;
import java.util.Locale;
import java.util.Random; import java.util.Random;
public class WeighTree<T> { public class WeighTree<T> {
@ -20,20 +21,20 @@ public class WeighTree<T> {
return root.get(random.nextFloat() * maxWeight); return root.get(random.nextFloat() * maxWeight);
} }
private Node getNode(WeightedList<T> biomes) { private Node getNode(WeightedList<T> list) {
int size = biomes.size(); int size = list.size();
if (size == 1) { if (size == 1) {
return new Leaf(biomes.get(0)); return new Leaf(list.get(0));
} }
else if (size == 2) { else if (size == 2) {
T first = biomes.get(0); T first = list.get(0);
return new Branch(biomes.getWeight(0), new Leaf(first), new Leaf(biomes.get(1))); return new Branch(list.getWeight(0), new Leaf(first), new Leaf(list.get(1)));
} }
else { else {
int index = size >> 1; int index = size >> 1;
float separator = biomes.getWeight(index); float separator = list.getWeight(index);
Node a = getNode(biomes.subList(0, index + 1)); Node a = getNode(list.subList(0, index + 1));
Node b = getNode(biomes.subList(index, size)); Node b = getNode(list.subList(index, size));
return new Branch(separator, a, b); return new Branch(separator, a, b);
} }
} }
@ -57,18 +58,33 @@ public class WeighTree<T> {
T get(float value) { T get(float value) {
return value < separator ? min.get(value) : max.get(value); return value < separator ? min.get(value) : max.get(value);
} }
@Override
public String toString() {
return String.format(Locale.ROOT, "[%f, %s, %s]", separator, min.toString(), max.toString());
}
} }
private class Leaf extends Node { private class Leaf extends Node {
final T biome; final T biome;
Leaf(T biome) { Leaf(T value) {
this.biome = biome; this.biome = value;
} }
@Override @Override
T get(float value) { T get(float value) {
return biome; return biome;
} }
@Override
public String toString() {
return String.format(Locale.ROOT, "[%s]", biome.toString());
}
}
@Override
public String toString() {
return root.toString();
} }
} }

View file

@ -2,9 +2,11 @@ package ru.bclib.world.biomes;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -31,6 +33,7 @@ public class BCLBiome {
protected float maxSubBiomeChance = 1; protected float maxSubBiomeChance = 1;
protected final float genChance; protected final float genChance;
private final Map<String, Object> customData;
private final float fogDensity; private final float fogDensity;
private BCLFeature structuresFeature; private BCLFeature structuresFeature;
private Biome actualBiome; private Biome actualBiome;
@ -44,6 +47,7 @@ public class BCLBiome {
this.biome = definition.build(); this.biome = definition.build();
this.genChance = definition.getGenChance(); this.genChance = definition.getGenChance();
this.fogDensity = definition.getFodDensity(); this.fogDensity = definition.getFodDensity();
this.customData = definition.getCustomData();
} }
public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) { public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) {
@ -52,6 +56,7 @@ public class BCLBiome {
this.genChance = genChance; this.genChance = genChance;
this.fogDensity = fogDensity; this.fogDensity = fogDensity;
this.readStructureList(); this.readStructureList();
this.customData = Maps.newHashMap();
} }
public BCLBiome getEdge() { public BCLBiome getEdge() {
@ -179,4 +184,9 @@ public class BCLBiome {
public int hashCode() { public int hashCode() {
return mcID.hashCode(); return mcID.hashCode();
} }
@SuppressWarnings("unchecked")
public <T> T getCustomData(String name) {
return (T) customData.get(name);
}
} }

View file

@ -1,8 +1,10 @@
package ru.bclib.world.biomes; package ru.bclib.world.biomes;
import java.util.List; import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleOptions;
@ -50,6 +52,7 @@ public class BCLBiomeDef {
private final List<CarverInfo> carvers = Lists.newArrayList(); private final List<CarverInfo> carvers = Lists.newArrayList();
private final List<SpawnInfo> mobs = Lists.newArrayList(); private final List<SpawnInfo> mobs = Lists.newArrayList();
private final List<SpawnerData> spawns = Lists.newArrayList(); private final List<SpawnerData> spawns = Lists.newArrayList();
private final Map<String, Object> customData = Maps.newHashMap();
private final ResourceLocation id; private final ResourceLocation id;
@ -369,4 +372,12 @@ public class BCLBiomeDef {
carvers.add(info); carvers.add(info);
return this; return this;
} }
public void addCustomData(String name, Object value) {
customData.put(name, value);
}
protected Map<String, Object> getCustomData() {
return customData;
}
} }