Possible hexmap fixes & tests

This commit is contained in:
paulevsGitch 2021-12-02 01:56:26 +03:00
parent 59d2874c1a
commit 0bfefa460f
3 changed files with 37 additions and 14 deletions

View file

@ -26,8 +26,10 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import ru.bclib.util.ColorUtil; import ru.bclib.util.ColorUtil;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.features.BCLFeature; import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.structures.BCLStructureFeature;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer;
public class BCLBiomeBuilder { public class BCLBiomeBuilder {
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
@ -410,17 +412,25 @@ public class BCLBiomeBuilder {
* Adds vanilla Mushrooms. * Adds vanilla Mushrooms.
* @return same {@link BCLBiomeBuilder} instance. * @return same {@link BCLBiomeBuilder} instance.
*/ */
public BCLBiomeBuilder defaultMushrooms(){ public BCLBiomeBuilder defaultMushrooms() {
BiomeDefaultFeatures.addDefaultMushrooms(getGeneration()); return feature(BiomeDefaultFeatures::addDefaultMushrooms);
return this;
} }
/** /**
* Adds vanilla Nether Ores. * Adds vanilla Nether Ores.
* @return same {@link BCLBiomeBuilder} instance. * @return same {@link BCLBiomeBuilder} instance.
*/ */
public BCLBiomeBuilder netherDefaultOres(){ public BCLBiomeBuilder netherDefaultOres() {
BiomeDefaultFeatures.addNetherDefaultOres(getGeneration()); return feature(BiomeDefaultFeatures::addNetherDefaultOres);
}
/**
* Will add features into biome, used for vanilla feature adding functions.
* @param featureAdd {@link Consumer} with {@link BiomeGenerationSettings.Builder}.
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder feature(Consumer<BiomeGenerationSettings.Builder> featureAdd) {
featureAdd.accept(getGeneration());
return this; return this;
} }
@ -433,6 +443,11 @@ public class BCLBiomeBuilder {
return feature(feature.getDecoration(), feature.getPlacedFeature()); return feature(feature.getDecoration(), feature.getPlacedFeature());
} }
// TODO Make feature registration
public BCLBiomeBuilder structure(BCLStructureFeature structure) {
return this;
}
/** /**
* Finalize biome creation. * Finalize biome creation.
* @return created {@link BCLBiome} instance. * @return created {@link BCLBiome} instance.

View file

@ -65,6 +65,9 @@ public class HexBiomeChunk {
} }
for (short index = 0; index < SIZE; index++) { for (short index = 0; index < SIZE; index++) {
if (outBuffer[index] == null) {
System.out.println("Buffer is null at " + index + ": " + (index >> SIDE_OFFSET) + " " + (index & SIDE_MASK));
}
if (outBuffer[index] != null && random.nextInt(4) == 0) { if (outBuffer[index] != null && random.nextInt(4) == 0) {
circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]); circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]);
} }

View file

@ -48,16 +48,16 @@ public class HexBiomeMap implements BiomeMap {
@Override @Override
public BCLBiome getBiome(double x, double z) { public BCLBiome getBiome(double x, double z) {
BCLBiome BCLBiome = getRawBiome(x, z); BCLBiome biome = getRawBiome(x, z);
if (BCLBiome!=null && BCLBiome.getEdge() != null) { if (biome.getEdge() != null) {
float offset = scale * BCLBiome.getEdgeSize(); float offset = scale * biome.getEdgeSize();
for (byte i = 0; i < 8; i++) { for (byte i = 0; i < 8; i++) {
if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != BCLBiome) { if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != biome) {
return BCLBiome.getEdge(); return biome.getEdge();
} }
} }
} }
return BCLBiome; return biome;
} }
private BCLBiome getRawBiome(double x, double z) { private BCLBiome getRawBiome(double x, double z) {
@ -112,13 +112,18 @@ public class HexBiomeMap implements BiomeMap {
cz += 1; cz += 1;
} }
selector.setLocation(cx, cz); HexBiomeChunk chunk;
HexBiomeChunk chunk = chunks.get(selector); synchronized (selector) {
selector.setLocation(cx, cz);
chunk = chunks.get(selector);
}
if (chunk == null) { if (chunk == null) {
RANDOM.setSeed(MHelper.getSeed(seed, cx, cz)); RANDOM.setSeed(MHelper.getSeed(seed, cx, cz));
chunk = new HexBiomeChunk(RANDOM, picker); chunk = new HexBiomeChunk(RANDOM, picker);
chunks.put(new Point(selector), chunk); chunks.put(new Point(cx, cz), chunk);
} }
return chunk.getBiome(x, z); return chunk.getBiome(x, z);
} }