Skip to content

Commit

Permalink
feat: more works
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Oct 28, 2024
1 parent fba5ad1 commit e250a8d
Show file tree
Hide file tree
Showing 33 changed files with 402 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ public class BlockStateData {
@Builder.Default
protected float friction = DEFAULT_FRICTION;
/**
* The light level of the block state.
* The amount that light will be dampened when it passes through the block, in a range (0-15).
* Higher value means the light will be dampened more.
*/
@Builder.Default
protected int light = 15;
protected int lightDampening = 15;
/**
* The light emission of the block state.
* The amount of light this block will emit in a range (0-15).
* Higher value means more light will be emitted.
*/
@Builder.Default
protected int lightEmission = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.allaymc.api.math.location.Location3fc;
import org.allaymc.api.math.location.Location3ic;
import org.allaymc.api.math.position.Position3ic;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.world.Dimension;
import org.allaymc.api.world.World;
import org.allaymc.api.world.chunk.Chunk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.allaymc.api.entity.initinfo.EntityInitInfo;
import org.allaymc.api.entity.type.EntityTypes;
import org.allaymc.api.utils.Identifier;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;

import java.util.concurrent.ThreadLocalRandom;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.allaymc.api.eventbus.event.player.PlayerDropItemEvent;
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.item.interfaces.ItemAirStack;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.cloudburstmc.protocol.bedrock.data.GameType;
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType;
import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.allaymc.api.utils;
package org.allaymc.api.math;

import lombok.experimental.UtilityClass;
import org.joml.*;

import java.lang.Math;
Expand All @@ -12,46 +11,55 @@
*
* @author Cool_Loong | daoge_cmd
*/
@UtilityClass
public class MathUtils {
public final class MathUtils {

public Vector3ic CBVecToJOMLVec(org.cloudburstmc.math.vector.Vector3i cbVec) {
private static final float[] SIN_LOOK_UP_TABLE = new float[65536];

static {
for (int i = 0; i < 65536; i++) {
SIN_LOOK_UP_TABLE[i] = (float) Math.sin(i * Math.PI * 2.0D / 65536.0d);
}
}

private MathUtils() {throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");}

public static Vector3ic CBVecToJOMLVec(org.cloudburstmc.math.vector.Vector3i cbVec) {

Check notice on line 26 in api/src/main/java/org/allaymc/api/math/MathUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

api/src/main/java/org/allaymc/api/math/MathUtils.java#L26

The static method name 'CBVecToJOMLVec' doesn't match '[a-z][a-zA-Z0-9]*'
return new Vector3i(cbVec.getX(), cbVec.getY(), cbVec.getZ());
}

public org.cloudburstmc.math.vector.Vector3i JOMLVecToCBVec(Vector3ic JOMLVec) {
public static org.cloudburstmc.math.vector.Vector3i JOMLVecToCBVec(Vector3ic JOMLVec) {

Check notice on line 30 in api/src/main/java/org/allaymc/api/math/MathUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

api/src/main/java/org/allaymc/api/math/MathUtils.java#L30

The static method name 'JOMLVecToCBVec' doesn't match '[a-z][a-zA-Z0-9]*'
return org.cloudburstmc.math.vector.Vector3i.from(JOMLVec.x(), JOMLVec.y(), JOMLVec.z());
}

public Vector3dc CBVecToJOMLVec(org.cloudburstmc.math.vector.Vector3d cbVec) {
public static Vector3dc CBVecToJOMLVec(org.cloudburstmc.math.vector.Vector3d cbVec) {

Check notice on line 34 in api/src/main/java/org/allaymc/api/math/MathUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

api/src/main/java/org/allaymc/api/math/MathUtils.java#L34

The static method name 'CBVecToJOMLVec' doesn't match '[a-z][a-zA-Z0-9]*'
return new Vector3d(cbVec.getX(), cbVec.getY(), cbVec.getZ());
}

public org.cloudburstmc.math.vector.Vector3d JOMLVecToCBVec(Vector3dc JOMLVec) {
public static org.cloudburstmc.math.vector.Vector3d JOMLVecToCBVec(Vector3dc JOMLVec) {

Check notice on line 38 in api/src/main/java/org/allaymc/api/math/MathUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

api/src/main/java/org/allaymc/api/math/MathUtils.java#L38

The static method name 'JOMLVecToCBVec' doesn't match '[a-z][a-zA-Z0-9]*'
return org.cloudburstmc.math.vector.Vector3d.from(JOMLVec.x(), JOMLVec.y(), JOMLVec.z());
}

public Vector3fc CBVecToJOMLVec(org.cloudburstmc.math.vector.Vector3f cbVec) {
public static Vector3fc CBVecToJOMLVec(org.cloudburstmc.math.vector.Vector3f cbVec) {

Check notice on line 42 in api/src/main/java/org/allaymc/api/math/MathUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

api/src/main/java/org/allaymc/api/math/MathUtils.java#L42

The static method name 'CBVecToJOMLVec' doesn't match '[a-z][a-zA-Z0-9]*'
return new Vector3f(cbVec.getX(), cbVec.getY(), cbVec.getZ());
}

public org.cloudburstmc.math.vector.Vector3f JOMLVecToCBVec(Vector3fc JOMLVec) {
public static org.cloudburstmc.math.vector.Vector3f JOMLVecToCBVec(Vector3fc JOMLVec) {

Check notice on line 46 in api/src/main/java/org/allaymc/api/math/MathUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

api/src/main/java/org/allaymc/api/math/MathUtils.java#L46

The static method name 'JOMLVecToCBVec' doesn't match '[a-z][a-zA-Z0-9]*'
return org.cloudburstmc.math.vector.Vector3f.from(JOMLVec.x(), JOMLVec.y(), JOMLVec.z());
}

public Vector3i floor(Vector3dc vector3d) {
public static Vector3i floor(Vector3dc vector3d) {
return new Vector3i((int) Math.floor(vector3d.x()), (int) Math.floor(vector3d.y()), (int) Math.floor(vector3d.z()));
}

public Vector3i floor(Vector3fc vector3f) {
public static Vector3i floor(Vector3fc vector3f) {
return new Vector3i((int) Math.floor(vector3f.x()), (int) Math.floor(vector3f.y()), (int) Math.floor(vector3f.z()));
}

public Vector3i ceil(Vector3dc vector3d) {
public static Vector3i ceil(Vector3dc vector3d) {
return new Vector3i((int) Math.ceil(vector3d.x()), (int) Math.ceil(vector3d.y()), (int) Math.ceil(vector3d.z()));
}

public Vector3i ceil(Vector3fc vector3f) {
public static Vector3i ceil(Vector3fc vector3f) {
return new Vector3i((int) Math.ceil(vector3f.x()), (int) Math.ceil(vector3f.y()), (int) Math.ceil(vector3f.z()));
}

Expand All @@ -67,7 +75,7 @@ public static double round(double d, int precision) {
*
* @return result.
*/
public float fastFloatInverseSqrt(float x) {
public static float fastFloatInverseSqrt(float x) {
float xHalf = 0.5f * x;
int reEncode = Float.floatToIntBits(x);
reEncode = 0x5f3759df - (reEncode >> 1);
Expand All @@ -83,7 +91,7 @@ public float fastFloatInverseSqrt(float x) {
*
* @return result.
*/
public double fastDoubleInverseSqrt(double x) {
public static double fastDoubleInverseSqrt(double x) {
double xHalf = 0.5d * x;
long reEncode = Double.doubleToLongBits(x);
reEncode = 0x5fe6ec85e7de30daL - (reEncode >> 1);
Expand All @@ -101,7 +109,7 @@ public double fastDoubleInverseSqrt(double x) {
*
* @return {@code true} if the value is in the range, otherwise {@code false}.
*/
public boolean isInRange(float l, float value, float r) {
public static boolean isInRange(float l, float value, float r) {
return l <= value && value <= r;
}

Expand All @@ -113,7 +121,7 @@ public boolean isInRange(float l, float value, float r) {
*
* @return direction vector.
*/
public Vector3f getDirectionVector(double yaw, double pitch) {
public static Vector3f getDirectionVector(double yaw, double pitch) {
var pitch0 = toRadians(pitch + 90);
var yaw0 = toRadians(yaw + 90);
var x = sin(pitch0) * cos(yaw0);
Expand All @@ -129,7 +137,7 @@ public Vector3f getDirectionVector(double yaw, double pitch) {
*
* @return yaw.
*/
public double getYawFromVector(Vector3fc vector) {
public static double getYawFromVector(Vector3fc vector) {
double length = vector.x() * vector.x() + vector.z() * vector.z();
// Prevent NAN
if (length == 0) {
Expand All @@ -146,7 +154,7 @@ public double getYawFromVector(Vector3fc vector) {
*
* @return pitch.
*/
public double getPitchFromVector(Vector3fc vector) {
public static double getPitchFromVector(Vector3fc vector) {
double length =
vector.x() * vector.x() +
vector.z() * vector.z() +
Expand All @@ -158,4 +166,20 @@ public double getPitchFromVector(Vector3fc vector) {
var pitch = toDegrees(asin(-vector.y() / sqrt(length)));
return StrictMath.abs(pitch) < 1E-10 ? 0 : pitch;
}

public static float fastSin(float p) {
return SIN_LOOK_UP_TABLE[((int) (p * 10430.378F) & 0xFFFF)];
}

public static float fastSin(double p) {
return SIN_LOOK_UP_TABLE[((int) (p * 10430.378F) & 0xFFFF)];
}

public static float fastCos(float p) {
return SIN_LOOK_UP_TABLE[((int) (p * 10430.378F + 16384.0F) & 0xFFFF)];
}

public static float fastCos(double p) {
return SIN_LOOK_UP_TABLE[((int) (p * 10430.378F + 16384.0F) & 0xFFFF)];
}
}
3 changes: 1 addition & 2 deletions api/src/main/java/org/allaymc/api/world/Dimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.math.position.Position3i;
import org.allaymc.api.math.position.Position3ic;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.utils.Utils;
import org.allaymc.api.world.generator.WorldGenerator;
import org.allaymc.api.world.service.*;
import org.apache.commons.lang3.function.TriFunction;
import org.cloudburstmc.math.vector.Vector3f;
Expand Down
9 changes: 5 additions & 4 deletions api/src/main/java/org/allaymc/api/world/DimensionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public record DimensionInfo(
int dimensionId,
int minHeight,
int maxHeight,
int chunkSectionSize
int chunkSectionCount,
boolean hasSkyLight
) {

public static final DimensionInfo OVERWORLD = new DimensionInfo(0, -64, 319, 24);
public static final DimensionInfo NETHER = new DimensionInfo(1, 0, 127, 8);
public static final DimensionInfo THE_END = new DimensionInfo(2, 0, 255, 16);
public static final DimensionInfo OVERWORLD = new DimensionInfo(0, -64, 319, 24, true);
public static final DimensionInfo NETHER = new DimensionInfo(1, 0, 127, 8, false);
public static final DimensionInfo THE_END = new DimensionInfo(2, 0, 255, 16, false);

public DimensionInfo(int dimensionId, int minHeight, int maxHeight) {
this(dimensionId, minHeight, maxHeight, (maxHeight - minHeight + 1) / 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public HeightMap() {
Arrays.fill(this.heights, (short) -1);
}

public HeightMap(short defaultValue) {
this.heights = new short[256];
Arrays.fill(this.heights, defaultValue);
}

/**
* Compute the index of the specified position.
*
Expand Down
15 changes: 15 additions & 0 deletions api/src/main/java/org/allaymc/api/world/service/LightService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package org.allaymc.api.world.service;

import org.allaymc.api.world.chunk.Chunk;

/**
* @author daoge_cmd
*/
public interface LightService {
int getSkyLight(int x, int y, int z);

int getInternalLight(int x, int y, int z);

int getInternalSkyLight(int x, int y, int z);

int getBlockLight(int x, int y, int z);

void onBlockChange(int x, int y, int z, int lightEmission, int lightDampening);

void onChunkLoad(Chunk chunk);

void onChunkUnload(Chunk chunk);
}
2 changes: 1 addition & 1 deletion data/resources/block_states.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/resources/unpacked/block_states_raw.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static class RawBlockStateData {
public float explosionResistance;
public int flameOdds;
public float friction;
public int light;
public int lightDampening;
public int lightEmission;
public String mapColor;
public float thickness;
Expand All @@ -59,7 +59,7 @@ public static class NewBlockStateData {
public float explosionResistance;
public int flameOdds;
public float friction;
public int light;
public int lightDampening;
public int lightEmission;
public String mapColor;
public float thickness;
Expand All @@ -75,7 +75,7 @@ public static NewBlockStateData fromRaw(RawBlockStateData raw) {
data.explosionResistance = raw.explosionResistance;
data.flameOdds = raw.flameOdds;
data.friction = raw.friction;
data.light = raw.light;
data.lightDampening = raw.lightDampening;
data.lightEmission = raw.lightEmission;
data.mapColor = raw.mapColor;
data.thickness = raw.thickness;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.allaymc.api.eventbus.event.block.SignWaxEvent;
import org.allaymc.api.item.type.ItemTypes;
import org.allaymc.api.utils.AllayStringUtils;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.server.block.component.event.CBlockOnInteractEvent;
import org.allaymc.server.block.component.event.CBlockOnPlaceEvent;
import org.allaymc.server.blockentity.component.BlockEntityBaseComponentImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.allaymc.api.i18n.TrKeys;

import static java.lang.Runtime.getRuntime;
import static org.allaymc.api.utils.MathUtils.round;
import static org.allaymc.api.math.MathUtils.round;

/**
* @author daoge_cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.allaymc.api.i18n.LangCode;
import org.allaymc.api.i18n.TrKeys;
import org.allaymc.api.item.data.ItemId;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.registry.Registries;
import org.allaymc.api.utils.*;
import org.allaymc.server.block.type.BlockLootTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.i18n.TrKeys;
import org.allaymc.api.math.location.Location3i;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.world.DimensionInfo;
import org.joml.Vector3f;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import static org.allaymc.api.utils.MathUtils.round;
import static org.allaymc.api.math.MathUtils.round;

/**
* @author daoge_cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.allaymc.api.perm.DefaultPermissions;
import org.allaymc.api.perm.tree.PermTree;
import org.allaymc.api.server.Server;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.world.Dimension;
import org.allaymc.api.world.chunk.Chunk;
import org.allaymc.server.component.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.allaymc.api.entity.interfaces.EntityItem;
import org.allaymc.api.entity.type.EntityTypes;
import org.allaymc.api.item.ItemStack;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.protocol.bedrock.packet.AddItemEntityPacket;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.allaymc.api.scoreboard.scorer.PlayerScorer;
import org.allaymc.api.server.Server;
import org.allaymc.api.utils.AllayNbtUtils;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.utils.TextFormat;
import org.allaymc.api.utils.Utils;
import org.allaymc.api.world.chunk.Chunk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.allaymc.api.entity.component.EntityContainerViewerComponent;
import org.allaymc.api.entity.component.player.EntityPlayerBaseComponent;
import org.allaymc.api.entity.component.player.EntityPlayerNetworkComponent;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.server.component.annotation.Dependency;
import org.allaymc.server.component.annotation.Identifier;
import org.cloudburstmc.math.vector.Vector3i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.eventbus.event.player.PlayerBlockPickEvent;
import org.allaymc.api.math.position.Position3i;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.cloudburstmc.protocol.bedrock.data.GameType;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacketType;
import org.cloudburstmc.protocol.bedrock.packet.BlockPickRequestPacket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.allaymc.api.entity.component.EntityDamageComponent;
import org.allaymc.api.entity.damage.DamageContainer;
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.cloudburstmc.protocol.bedrock.data.inventory.transaction.InventorySource;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacketType;
import org.cloudburstmc.protocol.bedrock.packet.InventoryTransactionPacket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.allaymc.api.block.type.BlockState;
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.math.location.Location3f;
import org.allaymc.api.utils.MathUtils;
import org.allaymc.api.math.MathUtils;
import org.allaymc.server.entity.component.EntityBaseComponentImpl;
import org.allaymc.server.entity.component.player.EntityPlayerBaseComponentImpl;
import org.allaymc.server.entity.component.player.EntityPlayerNetworkComponentImpl;
Expand Down
Loading

0 comments on commit e250a8d

Please sign in to comment.