chunk additions

This commit is contained in:
sylvessa
2026-04-18 18:14:58 -05:00
committed by itsRevela
parent 84e4a77409
commit a3221c9e14
19 changed files with 1607 additions and 5 deletions
+109
View File
@@ -0,0 +1,109 @@
namespace Minecraft.Server.FourKit.Block;
public enum Biome
{
OCEAN = 0,
PLAINS = 1,
DESERT = 2,
EXTREME_HILLS = 3,
FOREST = 4,
TAIGA = 5,
SWAMPLAND = 6,
RIVER = 7,
HELL = 8,
SKY = 9,
FROZEN_OCEAN = 10,
FROZEN_RIVER = 11,
ICE_PLAINS = 12,
ICE_MOUNTAINS = 13,
MUSHROOM_ISLAND = 14,
MUSHROOM_SHORE = 15,
BEACH = 16,
DESERT_HILLS = 17,
FOREST_HILLS = 18,
TAIGA_HILLS = 19,
SMALL_MOUNTAINS = 20,
JUNGLE = 21,
JUNGLE_HILLS = 22,
}
// more for internal
// eliminates unnecessary overhead
internal static class BiomeHelper
{
private static readonly double[] _temperatures = new double[23];
private static readonly double[] _rainfalls = new double[23];
static BiomeHelper()
{
_temperatures[(int)Biome.OCEAN] = 0.5;
_temperatures[(int)Biome.PLAINS] = 0.8;
_temperatures[(int)Biome.DESERT] = 2.0;
_temperatures[(int)Biome.EXTREME_HILLS] = 0.2;
_temperatures[(int)Biome.FOREST] = 0.7;
_temperatures[(int)Biome.TAIGA] = 0.05;
_temperatures[(int)Biome.SWAMPLAND] = 0.8;
_temperatures[(int)Biome.RIVER] = 0.5;
_temperatures[(int)Biome.HELL] = 2.0;
_temperatures[(int)Biome.SKY] = 0.5;
_temperatures[(int)Biome.FROZEN_OCEAN] = 0.0;
_temperatures[(int)Biome.FROZEN_RIVER] = 0.0;
_temperatures[(int)Biome.ICE_PLAINS] = 0.0;
_temperatures[(int)Biome.ICE_MOUNTAINS] = 0.0;
_temperatures[(int)Biome.MUSHROOM_ISLAND] = 0.9;
_temperatures[(int)Biome.MUSHROOM_SHORE] = 0.9;
_temperatures[(int)Biome.BEACH] = 0.8;
_temperatures[(int)Biome.DESERT_HILLS] = 2.0;
_temperatures[(int)Biome.FOREST_HILLS] = 0.7;
_temperatures[(int)Biome.TAIGA_HILLS] = 0.05;
_temperatures[(int)Biome.SMALL_MOUNTAINS] = 0.2;
_temperatures[(int)Biome.JUNGLE] = 1.2;
_temperatures[(int)Biome.JUNGLE_HILLS] = 1.2;
_rainfalls[(int)Biome.OCEAN] = 0.5;
_rainfalls[(int)Biome.PLAINS] = 0.4;
_rainfalls[(int)Biome.DESERT] = 0.0;
_rainfalls[(int)Biome.EXTREME_HILLS] = 0.3;
_rainfalls[(int)Biome.FOREST] = 0.8;
_rainfalls[(int)Biome.TAIGA] = 0.8;
_rainfalls[(int)Biome.SWAMPLAND] = 0.9;
_rainfalls[(int)Biome.RIVER] = 0.5;
_rainfalls[(int)Biome.HELL] = 0.0;
_rainfalls[(int)Biome.SKY] = 0.5;
_rainfalls[(int)Biome.FROZEN_OCEAN] = 0.5;
_rainfalls[(int)Biome.FROZEN_RIVER] = 0.5;
_rainfalls[(int)Biome.ICE_PLAINS] = 0.5;
_rainfalls[(int)Biome.ICE_MOUNTAINS] = 0.5;
_rainfalls[(int)Biome.MUSHROOM_ISLAND] = 1.0;
_rainfalls[(int)Biome.MUSHROOM_SHORE] = 1.0;
_rainfalls[(int)Biome.BEACH] = 0.4;
_rainfalls[(int)Biome.DESERT_HILLS] = 0.0;
_rainfalls[(int)Biome.FOREST_HILLS] = 0.8;
_rainfalls[(int)Biome.TAIGA_HILLS] = 0.8;
_rainfalls[(int)Biome.SMALL_MOUNTAINS] = 0.3;
_rainfalls[(int)Biome.JUNGLE] = 0.9;
_rainfalls[(int)Biome.JUNGLE_HILLS] = 0.9;
}
public static double getTemperature(this Biome biome)
{
int id = (int)biome;
if (id >= 0 && id < _temperatures.Length) return _temperatures[id];
return 0.5;
}
public static double getRainfall(this Biome biome)
{
int id = (int)biome;
if (id >= 0 && id < _rainfalls.Length) return _rainfalls[id];
return 0.5;
}
public static Biome fromId(int id)
{
if (Enum.IsDefined(typeof(Biome), id)) return (Biome)id;
return Biome.PLAINS;
}
}
+98 -1
View File
@@ -134,6 +134,15 @@ public class Block
return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ);
}
/// <summary>
/// Gets the chunk which contains this block.
/// </summary>
/// <returns>Containing Chunk.</returns>
public Chunk.Chunk getChunk()
{
return getWorld().getChunkAt(getX() >> 4, getZ() >> 4);
}
/// <summary>
/// Gets the block at the given face
/// <para>This method is equal to getRelative(face, 1)</para>
@@ -162,5 +171,93 @@ public class Block
{
return getRelative(face.getModX() * distance, face.getModY() * distance, face.getModZ() * distance);
}
/// <summary>
/// Returns the biome that this block resides in.
/// </summary>
/// <returns>Biome type containing this block.</returns>
public Biome getBiome()
{
if (NativeBridge.GetBiomeId != null)
return BiomeHelper.fromId(NativeBridge.GetBiomeId(_world.getDimensionId(), _x, _z));
return Biome.PLAINS;
}
/// <summary>
/// Sets the biome that this block resides in.
/// </summary>
/// <param name="bio">New Biome type for this block.</param>
public void setBiome(Biome bio)
{
NativeBridge.SetBiomeId?.Invoke(_world.getDimensionId(), _x, _z, (int)bio);
}
/// <summary>
/// Gets the humidity of the biome of this block.
/// </summary>
/// <returns>Humidity of this block.</returns>
public double getHumidity()
{
return getBiome().getRainfall();
}
/// <summary>
/// Gets the temperature of the biome of this block.
/// </summary>
/// <returns>Temperature of this block.</returns>
public double getTemperature()
{
return getBiome().getTemperature();
}
/// <summary>
/// Checks if this block is liquid.
/// <para>A block is considered liquid when <see cref="getType()"/> returns
/// <see cref="Material.WATER"/>, <see cref="Material.STATIONARY_WATER"/>,
/// <see cref="Material.LAVA"/> or <see cref="Material.STATIONARY_LAVA"/>.</para>
/// </summary>
/// <returns>true if this block is liquid.</returns>
public bool isLiquid()
{
Material type = getType();
return type == Material.WATER || type == Material.STATIONARY_WATER ||
type == Material.LAVA || type == Material.STATIONARY_LAVA;
}
/// <summary>
/// Gets the light level between 0-15.
/// </summary>
/// <returns>Light level.</returns>
public byte getLightLevel()
{
int sky = getLightFromSky();
int block = getLightFromBlocks();
return (byte)(sky > block ? sky : block);
}
/// <summary>
/// Get the amount of light at this block from the sky.
/// Any light given from other sources (such as blocks like torches) will be ignored.
/// </summary>
/// <returns>Sky light level.</returns>
public byte getLightFromSky()
{
if (NativeBridge.GetSkyLight != null)
return (byte)NativeBridge.GetSkyLight(_world.getDimensionId(), _x, _y, _z);
return 0;
}
/// <summary>
/// Get the amount of light at this block from nearby blocks.
/// Any light given from other sources (such as the sun) will be ignored.
/// </summary>
/// <returns>Block light level.</returns>
public byte getLightFromBlocks()
{
if (NativeBridge.GetBlockLight != null)
return (byte)NativeBridge.GetBlockLight(_world.getDimensionId(), _x, _y, _z);
return 0;
}
}
@@ -92,6 +92,15 @@ public class BlockState
/// <returns>Z-coordinate.</returns>
public int getZ() => _z;
/// <summary>
/// Gets the chunk which contains this block.
/// </summary>
/// <returns>Containing Chunk.</returns>
public Chunk.Chunk getChunk()
{
return _world.getChunkAt(_x >> 4, _z >> 4);
}
/// <summary>
/// Gets the location of this block.
/// </summary>
@@ -194,4 +203,13 @@ public class BlockState
NativeBridge.SetTile(_world.getDimensionId(), _x, _y, _z, _typeId, _data);
return true;
}
/// <summary>
/// Gets the light level between 0-15.
/// </summary>
/// <returns>Light level.</returns>
public byte getLightLevel()
{
return getBlock().getLightLevel();
}
}