Weight tree & cleanup
This commit is contained in:
parent
aec1216769
commit
2093c747c6
8 changed files with 83 additions and 16 deletions
|
@ -4,7 +4,6 @@ import java.io.Reader;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.patterns.Patterns;
|
import ru.betterend.patterns.Patterns;
|
||||||
|
|
||||||
public class BlockBark extends BlockPillar {
|
public class BlockBark extends BlockPillar {
|
||||||
|
|
|
@ -15,7 +15,6 @@ import net.minecraft.loot.context.LootContext;
|
||||||
import net.minecraft.loot.context.LootContextParameters;
|
import net.minecraft.loot.context.LootContextParameters;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.patterns.Patterns;
|
import ru.betterend.patterns.Patterns;
|
||||||
|
|
||||||
public class BlockBookshelf extends BlockBase {
|
public class BlockBookshelf extends BlockBase {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import net.minecraft.resource.Resource;
|
||||||
import net.minecraft.resource.ResourceManager;
|
import net.minecraft.resource.ResourceManager;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.interfaces.IdentifiedContext;
|
import ru.betterend.interfaces.IdentifiedContext;
|
||||||
import ru.betterend.patterns.Patterned;
|
import ru.betterend.patterns.Patterned;
|
||||||
|
|
|
@ -112,6 +112,9 @@ public class EndBiomes {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
LAND_BIOMES.rebuild();
|
||||||
|
VOID_BIOMES.rebuild();
|
||||||
|
|
||||||
LAND_BIOMES.getBiomes().forEach((endBiome) -> {
|
LAND_BIOMES.getBiomes().forEach((endBiome) -> {
|
||||||
Biome biome = biomeRegistry.get(endBiome.getID());
|
Biome biome = biomeRegistry.get(endBiome.getID());
|
||||||
endBiome.setActualBiome(biome);
|
endBiome.setActualBiome(biome);
|
||||||
|
|
|
@ -3,10 +3,9 @@ package ru.betterend.world.biome;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import ru.betterend.config.Config;
|
import ru.betterend.config.Config;
|
||||||
import ru.betterend.config.ConfigWriter;
|
|
||||||
import ru.betterend.config.ConfigKeeper.Entry;
|
import ru.betterend.config.ConfigKeeper.Entry;
|
||||||
|
import ru.betterend.config.ConfigWriter;
|
||||||
|
|
||||||
public class BiomeConfig extends Config {
|
public class BiomeConfig extends Config {
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@ import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import net.minecraft.structure.Structure;
|
import net.minecraft.structure.Structure;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.WorldAccess;
|
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import ru.betterend.util.JsonFactory;
|
import ru.betterend.util.JsonFactory;
|
||||||
import ru.betterend.util.StructureHelper;
|
import ru.betterend.util.StructureHelper;
|
||||||
|
@ -53,9 +51,6 @@ public class EndBiome {
|
||||||
readStructureList();
|
readStructureList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EndBiome getEdge() {
|
public EndBiome getEdge() {
|
||||||
return edge == null ? this : edge;
|
return edge == null ? this : edge;
|
||||||
}
|
}
|
||||||
|
@ -166,4 +161,8 @@ public class EndBiome {
|
||||||
public Biome getActualBiome() {
|
public Biome getActualBiome() {
|
||||||
return this.actualBiome;
|
return this.actualBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getGenChance() {
|
||||||
|
return this.genChance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import ru.betterend.registry.EndBiomes;
|
|
||||||
import ru.betterend.world.biome.EndBiome;
|
import ru.betterend.world.biome.EndBiome;
|
||||||
|
|
||||||
public class BiomePicker {
|
public class BiomePicker {
|
||||||
|
@ -17,6 +16,7 @@ public class BiomePicker {
|
||||||
private float maxChanceUnmutable = 0;
|
private float maxChanceUnmutable = 0;
|
||||||
private float maxChance = 0;
|
private float maxChance = 0;
|
||||||
private int biomeCount = 0;
|
private int biomeCount = 0;
|
||||||
|
private WeighTree tree;
|
||||||
|
|
||||||
public void addBiome(EndBiome biome) {
|
public void addBiome(EndBiome biome) {
|
||||||
maxChance = biome.mutateGenChance(maxChance);
|
maxChance = biome.mutateGenChance(maxChance);
|
||||||
|
@ -38,11 +38,7 @@ public class BiomePicker {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EndBiome getBiome(Random random) {
|
public EndBiome getBiome(Random random) {
|
||||||
float chance = random.nextFloat() * maxChance;
|
return tree.getBiome(random.nextFloat() * maxChance);
|
||||||
for (EndBiome biome: biomes)
|
|
||||||
if (biome.canGenerate(chance))
|
|
||||||
return biome;
|
|
||||||
return EndBiomes.END;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EndBiome> getBiomes() {
|
public List<EndBiome> getBiomes() {
|
||||||
|
@ -52,4 +48,8 @@ public class BiomePicker {
|
||||||
public boolean containsImmutable(Identifier id) {
|
public boolean containsImmutable(Identifier id) {
|
||||||
return immutableIDs.contains(id);
|
return immutableIDs.contains(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rebuild() {
|
||||||
|
tree = new WeighTree(biomes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
69
src/main/java/ru/betterend/world/generator/WeighTree.java
Normal file
69
src/main/java/ru/betterend/world/generator/WeighTree.java
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
package ru.betterend.world.generator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import ru.betterend.world.biome.EndBiome;
|
||||||
|
|
||||||
|
public class WeighTree {
|
||||||
|
private final Node root;
|
||||||
|
|
||||||
|
public WeighTree(List<EndBiome> biomes) {
|
||||||
|
root = getNode(biomes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EndBiome getBiome(float value) {
|
||||||
|
return root.getBiome(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node getNode(List<EndBiome> biomes) {
|
||||||
|
int size = biomes.size();
|
||||||
|
if (size == 1) {
|
||||||
|
return new Leaf(biomes.get(0));
|
||||||
|
}
|
||||||
|
else if (size == 2) {
|
||||||
|
EndBiome first = biomes.get(0);
|
||||||
|
return new Branch(first.getGenChance(), new Leaf(first), new Leaf(biomes.get(1)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int index = size >> 1;
|
||||||
|
float separator = biomes.get(index).getGenChance();
|
||||||
|
Node a = getNode(biomes.subList(0, index + 1));
|
||||||
|
Node b = getNode(biomes.subList(index, size));
|
||||||
|
return new Branch(separator, a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private abstract class Node {
|
||||||
|
abstract EndBiome getBiome(float value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Branch extends Node {
|
||||||
|
final float separator;
|
||||||
|
final Node min;
|
||||||
|
final Node max;
|
||||||
|
|
||||||
|
public Branch(float separator, Node min, Node max) {
|
||||||
|
this.separator = separator;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
EndBiome getBiome(float value) {
|
||||||
|
return value < separator ? min.getBiome(value) : max.getBiome(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Leaf extends Node {
|
||||||
|
final EndBiome biome;
|
||||||
|
|
||||||
|
Leaf(EndBiome biome) {
|
||||||
|
this.biome = biome;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
EndBiome getBiome(float value) {
|
||||||
|
return biome;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue