Merge branch 'main' of github.com-quiqueck:paulevsGitch/BCLib

This commit is contained in:
Frank 2021-12-07 18:10:18 +01:00
commit 2191733f37
5 changed files with 61 additions and 37 deletions

View file

@ -11,7 +11,7 @@ loader_version= 0.12.8
fabric_version = 0.44.0+1.18
# Mod Properties
mod_version = 1.0.2
mod_version = 1.0.3
maven_group = ru.bclib
archives_base_name = bclib

View file

@ -17,6 +17,7 @@ import ru.bclib.blocks.BaseSignBlock;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.client.render.BaseChestBlockEntityRenderer;
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
import ru.bclib.config.Configs;
import ru.bclib.interfaces.PostInitable;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.interfaces.TagProvider;
@ -57,6 +58,7 @@ public class PostInitAPI {
blockTags = null;
itemTags = null;
BiomeAPI.loadFabricAPIBiomes();
Configs.BIOMES_CONFIG.saveChanges();
}
@Environment(EnvType.CLIENT)

View file

@ -167,7 +167,7 @@ public class BiomeAPI {
*/
public static BCLBiome registerNetherBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome);
configureBiome(bclBiome, 1.0F, 1.0F);
configureBiome(bclBiome);
NETHER_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
return bclBiome;
@ -181,7 +181,7 @@ public class BiomeAPI {
*/
public static BCLBiome registerEndLandBiome(BCLBiome biome) {
registerBiome(biome);
configureBiome(biome, 1.0F, 1.0F);
configureBiome(biome);
END_LAND_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
@ -198,7 +198,7 @@ public class BiomeAPI {
*/
public static BCLBiome registerEndLandBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome);
configureBiome(bclBiome, 1.0F, 1.0F);
configureBiome(bclBiome);
END_LAND_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
return bclBiome;
@ -212,8 +212,8 @@ public class BiomeAPI {
* @return {@link BCLBiome}
*/
public static BCLBiome registerEndLandBiome(Biome biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome);
configureBiome(bclBiome, genChance, 1.0F);
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
configureBiome(bclBiome);
END_LAND_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
return bclBiome;
@ -227,7 +227,7 @@ public class BiomeAPI {
*/
public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
registerBiome(biome);
configureBiome(biome, 1.0F, 1.0F);
configureBiome(biome);
END_VOID_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
@ -243,7 +243,7 @@ public class BiomeAPI {
*/
public static BCLBiome registerEndVoidBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome);
configureBiome(bclBiome, 1.0F, 1.0F);
configureBiome(bclBiome);
END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
return bclBiome;
@ -258,8 +258,8 @@ public class BiomeAPI {
*/
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
BCLBiome bclBiome = new BCLBiome(biome);
configureBiome(bclBiome, genChance, 1.0F);
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
configureBiome(bclBiome);
END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
return bclBiome;
@ -688,10 +688,10 @@ public class BiomeAPI {
return Blocks.AIR.defaultBlockState();
}
private static void configureBiome(BCLBiome biome, float chance, float fog) {
private static void configureBiome(BCLBiome biome) {
String group = biome.getID().getNamespace() + "." + biome.getID().getPath();
chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", chance);
fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", fog);
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", biome.getGenChance());
float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", biome.getFogDensity());
biome.setGenChance(chance).setFogDensity(fog);
}

View file

@ -3,40 +3,47 @@ package ru.bclib.world.generator.map.hex;
import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.generator.BiomePicker;
import java.util.Arrays;
import java.util.Random;
public class HexBiomeChunk {
private static final short SIDE = 32;
private static final byte SIDE_PRE = 4;
private static final short SIZE = SIDE * SIDE;
private static final short MAX_SIDE = SIZE - SIDE;
private static final byte SCALE_PRE = SIDE / SIDE_PRE;
private static final byte SIZE_PRE = SIDE_PRE * SIDE_PRE;
private static final byte SIDE_MASK = SIDE - 1;
private static final byte SIDE_PRE_MASK = SIDE_PRE - 1;
private static final byte SIDE_OFFSET = (byte) Math.round(Math.log(SIDE) / Math.log(2));
private static final byte SIDE_PRE_OFFSET = (byte) Math.round(Math.log(SIDE_PRE) / Math.log(2));
private static final short[][] NEIGHBOURS;
public static final short SCALE = SIDE / 4;
private static final BCLBiome[][] BUFFERS = new BCLBiome[2][SIZE];
private final BCLBiome[] biomes;
private final BCLBiome[] biomes = new BCLBiome[SIZE];
public HexBiomeChunk(Random random, BiomePicker picker) {
BCLBiome[][] buffers = new BCLBiome[2][SIZE];
byte scale = SIDE / 4;
for (byte x = 0; x < 4; x++) {
for (byte z = 0; z < 4; z++) {
byte px = (byte) (x * scale + random.nextInt(scale));
byte pz = (byte) (z * scale + random.nextInt(scale));
circle(buffers[0], getIndex(px, pz), picker.getBiome(random), null);
}
for (BCLBiome[] buffer: BUFFERS) {
Arrays.fill(buffer, null);
}
for (byte index = 0; index < SIZE_PRE; index++) {
byte px = (byte) (index >> SIDE_PRE_OFFSET);
byte pz = (byte) (index & SIDE_PRE_MASK);
px = (byte) (px * SCALE_PRE + random.nextInt(SCALE_PRE));
pz = (byte) (pz * SCALE_PRE + random.nextInt(SCALE_PRE));
circle(BUFFERS[0], getIndex(px, pz), picker.getBiome(random), null);
}
short maxSide = SIZE - SIDE;
boolean hasEmptyCells = true;
byte bufferIndex = 0;
while (hasEmptyCells) {
BCLBiome[] inBuffer = buffers[bufferIndex];
BCLBiome[] inBuffer = BUFFERS[bufferIndex];
bufferIndex = (byte) ((bufferIndex + 1) & 1);
BCLBiome[] outBuffer = buffers[bufferIndex];
BCLBiome[] outBuffer = BUFFERS[bufferIndex];
hasEmptyCells = false;
for (short index = SIDE; index < maxSide; index++) {
for (short index = SIDE; index < MAX_SIDE; index++) {
byte z = (byte) (index & SIDE_MASK);
if (z == 0 || z == SIDE_MASK) {
continue;
@ -55,7 +62,7 @@ public class HexBiomeChunk {
}
}
BCLBiome[] outBuffer = buffers[bufferIndex];
BCLBiome[] outBuffer = BUFFERS[bufferIndex];
byte preN = (byte) (SIDE_MASK - 2);
for (byte index = 0; index < SIDE; index++) {
outBuffer[getIndex(index, (byte) 0)] = outBuffer[getIndex(index, (byte) 2)];
@ -73,7 +80,7 @@ public class HexBiomeChunk {
}
}
this.biomes = outBuffer;
System.arraycopy(outBuffer, 0, this.biomes, 0, SIZE);
}
private void circle(BCLBiome[] buffer, short center, BCLBiome biome, BCLBiome mask) {
@ -113,6 +120,10 @@ public class HexBiomeChunk {
return NEIGHBOURS[z & 1];
}
public static float scaleMap(float size) {
return size / (SIDE >> 2);
}
static {
NEIGHBOURS = new short[2][6];

View file

@ -31,7 +31,7 @@ public class HexBiomeMap implements BiomeMap {
public HexBiomeMap(long seed, int size, BiomePicker picker) {
this.picker = picker;
this.scale = (float) size / HexBiomeChunk.SCALE;
this.scale = HexBiomeChunk.scaleMap(size);
Random random = new Random(seed);
noises[0] = new OpenSimplexNoise(random.nextInt());
noises[1] = new OpenSimplexNoise(random.nextInt());
@ -49,14 +49,25 @@ public class HexBiomeMap implements BiomeMap {
@Override
public BCLBiome getBiome(double x, double z) {
BCLBiome biome = getRawBiome(x, z);
if (biome.getEdge() != null) {
float offset = scale * biome.getEdgeSize();
BCLBiome edge = biome.getEdge();
float offset = biome.getEdgeSize();
if (edge == null && biome.getParentBiome() != null) {
edge = biome.getParentBiome().getEdge();
offset = biome.getParentBiome().getEdgeSize();
}
if (edge == null) {
return biome;
}
offset *= scale;
for (byte i = 0; i < 8; i++) {
if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != biome) {
return biome.getEdge();
}
if (!getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]).isSame(biome)) {
return edge;
}
}
return biome;
}