Merge branch 'main' of github.com-quiqueck:paulevsGitch/BCLib
This commit is contained in:
commit
2191733f37
5 changed files with 61 additions and 37 deletions
|
@ -11,7 +11,7 @@ loader_version= 0.12.8
|
||||||
fabric_version = 0.44.0+1.18
|
fabric_version = 0.44.0+1.18
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.2
|
mod_version = 1.0.3
|
||||||
maven_group = ru.bclib
|
maven_group = ru.bclib
|
||||||
archives_base_name = bclib
|
archives_base_name = bclib
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import ru.bclib.blocks.BaseSignBlock;
|
||||||
import ru.bclib.client.render.BCLRenderLayer;
|
import ru.bclib.client.render.BCLRenderLayer;
|
||||||
import ru.bclib.client.render.BaseChestBlockEntityRenderer;
|
import ru.bclib.client.render.BaseChestBlockEntityRenderer;
|
||||||
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
|
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
|
||||||
|
import ru.bclib.config.Configs;
|
||||||
import ru.bclib.interfaces.PostInitable;
|
import ru.bclib.interfaces.PostInitable;
|
||||||
import ru.bclib.interfaces.RenderLayerProvider;
|
import ru.bclib.interfaces.RenderLayerProvider;
|
||||||
import ru.bclib.interfaces.TagProvider;
|
import ru.bclib.interfaces.TagProvider;
|
||||||
|
@ -57,6 +58,7 @@ public class PostInitAPI {
|
||||||
blockTags = null;
|
blockTags = null;
|
||||||
itemTags = null;
|
itemTags = null;
|
||||||
BiomeAPI.loadFabricAPIBiomes();
|
BiomeAPI.loadFabricAPIBiomes();
|
||||||
|
Configs.BIOMES_CONFIG.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class BiomeAPI {
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerNetherBiome(Biome biome) {
|
public static BCLBiome registerNetherBiome(Biome biome) {
|
||||||
BCLBiome bclBiome = new BCLBiome(biome);
|
BCLBiome bclBiome = new BCLBiome(biome);
|
||||||
configureBiome(bclBiome, 1.0F, 1.0F);
|
configureBiome(bclBiome);
|
||||||
NETHER_BIOME_PICKER.addBiome(bclBiome);
|
NETHER_BIOME_PICKER.addBiome(bclBiome);
|
||||||
registerBiome(bclBiome);
|
registerBiome(bclBiome);
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
|
@ -181,7 +181,7 @@ public class BiomeAPI {
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerEndLandBiome(BCLBiome biome) {
|
public static BCLBiome registerEndLandBiome(BCLBiome biome) {
|
||||||
registerBiome(biome);
|
registerBiome(biome);
|
||||||
configureBiome(biome, 1.0F, 1.0F);
|
configureBiome(biome);
|
||||||
END_LAND_BIOME_PICKER.addBiome(biome);
|
END_LAND_BIOME_PICKER.addBiome(biome);
|
||||||
float weight = biome.getGenChance();
|
float weight = biome.getGenChance();
|
||||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
||||||
|
@ -198,7 +198,7 @@ public class BiomeAPI {
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerEndLandBiome(Biome biome) {
|
public static BCLBiome registerEndLandBiome(Biome biome) {
|
||||||
BCLBiome bclBiome = new BCLBiome(biome);
|
BCLBiome bclBiome = new BCLBiome(biome);
|
||||||
configureBiome(bclBiome, 1.0F, 1.0F);
|
configureBiome(bclBiome);
|
||||||
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
||||||
registerBiome(bclBiome);
|
registerBiome(bclBiome);
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
|
@ -212,8 +212,8 @@ public class BiomeAPI {
|
||||||
* @return {@link BCLBiome}
|
* @return {@link BCLBiome}
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerEndLandBiome(Biome biome, float genChance) {
|
public static BCLBiome registerEndLandBiome(Biome biome, float genChance) {
|
||||||
BCLBiome bclBiome = new BCLBiome(biome);
|
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
|
||||||
configureBiome(bclBiome, genChance, 1.0F);
|
configureBiome(bclBiome);
|
||||||
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
||||||
registerBiome(bclBiome);
|
registerBiome(bclBiome);
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
|
@ -227,7 +227,7 @@ public class BiomeAPI {
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
|
public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
|
||||||
registerBiome(biome);
|
registerBiome(biome);
|
||||||
configureBiome(biome, 1.0F, 1.0F);
|
configureBiome(biome);
|
||||||
END_VOID_BIOME_PICKER.addBiome(biome);
|
END_VOID_BIOME_PICKER.addBiome(biome);
|
||||||
float weight = biome.getGenChance();
|
float weight = biome.getGenChance();
|
||||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
||||||
|
@ -243,7 +243,7 @@ public class BiomeAPI {
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerEndVoidBiome(Biome biome) {
|
public static BCLBiome registerEndVoidBiome(Biome biome) {
|
||||||
BCLBiome bclBiome = new BCLBiome(biome);
|
BCLBiome bclBiome = new BCLBiome(biome);
|
||||||
configureBiome(bclBiome, 1.0F, 1.0F);
|
configureBiome(bclBiome);
|
||||||
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
||||||
registerBiome(bclBiome);
|
registerBiome(bclBiome);
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
|
@ -258,8 +258,8 @@ public class BiomeAPI {
|
||||||
*/
|
*/
|
||||||
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
|
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
|
||||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
||||||
BCLBiome bclBiome = new BCLBiome(biome);
|
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
|
||||||
configureBiome(bclBiome, genChance, 1.0F);
|
configureBiome(bclBiome);
|
||||||
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
||||||
registerBiome(bclBiome);
|
registerBiome(bclBiome);
|
||||||
return bclBiome;
|
return bclBiome;
|
||||||
|
@ -688,10 +688,10 @@ public class BiomeAPI {
|
||||||
return Blocks.AIR.defaultBlockState();
|
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();
|
String group = biome.getID().getNamespace() + "." + biome.getID().getPath();
|
||||||
chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", chance);
|
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", biome.getGenChance());
|
||||||
fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", fog);
|
float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", biome.getFogDensity());
|
||||||
biome.setGenChance(chance).setFogDensity(fog);
|
biome.setGenChance(chance).setFogDensity(fog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,40 +3,47 @@ package ru.bclib.world.generator.map.hex;
|
||||||
import ru.bclib.world.biomes.BCLBiome;
|
import ru.bclib.world.biomes.BCLBiome;
|
||||||
import ru.bclib.world.generator.BiomePicker;
|
import ru.bclib.world.generator.BiomePicker;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class HexBiomeChunk {
|
public class HexBiomeChunk {
|
||||||
private static final short SIDE = 32;
|
private static final short SIDE = 32;
|
||||||
|
private static final byte SIDE_PRE = 4;
|
||||||
private static final short SIZE = SIDE * SIDE;
|
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_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_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;
|
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) {
|
public HexBiomeChunk(Random random, BiomePicker picker) {
|
||||||
BCLBiome[][] buffers = new BCLBiome[2][SIZE];
|
for (BCLBiome[] buffer: BUFFERS) {
|
||||||
|
Arrays.fill(buffer, null);
|
||||||
byte scale = SIDE / 4;
|
}
|
||||||
for (byte x = 0; x < 4; x++) {
|
|
||||||
for (byte z = 0; z < 4; z++) {
|
for (byte index = 0; index < SIZE_PRE; index++) {
|
||||||
byte px = (byte) (x * scale + random.nextInt(scale));
|
byte px = (byte) (index >> SIDE_PRE_OFFSET);
|
||||||
byte pz = (byte) (z * scale + random.nextInt(scale));
|
byte pz = (byte) (index & SIDE_PRE_MASK);
|
||||||
circle(buffers[0], getIndex(px, pz), picker.getBiome(random), null);
|
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;
|
boolean hasEmptyCells = true;
|
||||||
byte bufferIndex = 0;
|
byte bufferIndex = 0;
|
||||||
while (hasEmptyCells) {
|
while (hasEmptyCells) {
|
||||||
BCLBiome[] inBuffer = buffers[bufferIndex];
|
BCLBiome[] inBuffer = BUFFERS[bufferIndex];
|
||||||
bufferIndex = (byte) ((bufferIndex + 1) & 1);
|
bufferIndex = (byte) ((bufferIndex + 1) & 1);
|
||||||
BCLBiome[] outBuffer = buffers[bufferIndex];
|
BCLBiome[] outBuffer = BUFFERS[bufferIndex];
|
||||||
hasEmptyCells = false;
|
hasEmptyCells = false;
|
||||||
|
|
||||||
for (short index = SIDE; index < maxSide; index++) {
|
for (short index = SIDE; index < MAX_SIDE; index++) {
|
||||||
byte z = (byte) (index & SIDE_MASK);
|
byte z = (byte) (index & SIDE_MASK);
|
||||||
if (z == 0 || z == SIDE_MASK) {
|
if (z == 0 || z == SIDE_MASK) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -55,7 +62,7 @@ public class HexBiomeChunk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BCLBiome[] outBuffer = buffers[bufferIndex];
|
BCLBiome[] outBuffer = BUFFERS[bufferIndex];
|
||||||
byte preN = (byte) (SIDE_MASK - 2);
|
byte preN = (byte) (SIDE_MASK - 2);
|
||||||
for (byte index = 0; index < SIDE; index++) {
|
for (byte index = 0; index < SIDE; index++) {
|
||||||
outBuffer[getIndex(index, (byte) 0)] = outBuffer[getIndex(index, (byte) 2)];
|
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) {
|
private void circle(BCLBiome[] buffer, short center, BCLBiome biome, BCLBiome mask) {
|
||||||
|
@ -113,6 +120,10 @@ public class HexBiomeChunk {
|
||||||
return NEIGHBOURS[z & 1];
|
return NEIGHBOURS[z & 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float scaleMap(float size) {
|
||||||
|
return size / (SIDE >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NEIGHBOURS = new short[2][6];
|
NEIGHBOURS = new short[2][6];
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class HexBiomeMap implements BiomeMap {
|
||||||
|
|
||||||
public HexBiomeMap(long seed, int size, BiomePicker picker) {
|
public HexBiomeMap(long seed, int size, BiomePicker picker) {
|
||||||
this.picker = picker;
|
this.picker = picker;
|
||||||
this.scale = (float) size / HexBiomeChunk.SCALE;
|
this.scale = HexBiomeChunk.scaleMap(size);
|
||||||
Random random = new Random(seed);
|
Random random = new Random(seed);
|
||||||
noises[0] = new OpenSimplexNoise(random.nextInt());
|
noises[0] = new OpenSimplexNoise(random.nextInt());
|
||||||
noises[1] = new OpenSimplexNoise(random.nextInt());
|
noises[1] = new OpenSimplexNoise(random.nextInt());
|
||||||
|
@ -49,14 +49,25 @@ public class HexBiomeMap implements BiomeMap {
|
||||||
@Override
|
@Override
|
||||||
public BCLBiome getBiome(double x, double z) {
|
public BCLBiome getBiome(double x, double z) {
|
||||||
BCLBiome biome = getRawBiome(x, z);
|
BCLBiome biome = getRawBiome(x, z);
|
||||||
if (biome.getEdge() != null) {
|
BCLBiome edge = biome.getEdge();
|
||||||
float offset = scale * biome.getEdgeSize();
|
float offset = biome.getEdgeSize();
|
||||||
for (byte i = 0; i < 8; i++) {
|
|
||||||
if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != biome) {
|
if (edge == null && biome.getParentBiome() != null) {
|
||||||
return biome.getEdge();
|
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]).isSame(biome)) {
|
||||||
|
return edge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return biome;
|
return biome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue