Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use double instead of float #564

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import lombok.ToString;
import lombok.experimental.Accessors;
import org.allaymc.api.math.voxelshape.VoxelShape;
import org.joml.Vector3fc;
import org.joml.Vector3dc;
import org.joml.Vector3ic;
import org.joml.primitives.AABBf;
import org.joml.primitives.AABBd;

import java.awt.*;

Expand All @@ -36,18 +36,16 @@ public class BlockStateData {
protected static Gson SERIALIZER = new GsonBuilder()
.registerTypeAdapter(VoxelShape.class, (JsonDeserializer<Object>) (json, typeOfT, context) -> {
var array = json.getAsJsonArray();
var minX = array.get(0).getAsFloat();
var minY = array.get(1).getAsFloat();
var minZ = array.get(2).getAsFloat();
var maxX = array.get(3).getAsFloat();
var maxY = array.get(4).getAsFloat();
var maxZ = array.get(5).getAsFloat();
var minX = array.get(0).getAsDouble();
var minY = array.get(1).getAsDouble();
var minZ = array.get(2).getAsDouble();
var maxX = array.get(3).getAsDouble();
var maxY = array.get(4).getAsDouble();
var maxZ = array.get(5).getAsDouble();
if (minX == 0 && minY == 0 && minZ == 0 && maxX == 0 && maxY == 0 && maxZ == 0) {
return VoxelShape.EMPTY;
}
return VoxelShape.builder().solid(
new AABBf(minX, minY, minZ, maxX, maxY, maxZ)
).build();
return VoxelShape.builder().solid(new AABBd(minX, minY, minZ, maxX, maxY, maxZ)).build();
})
.registerTypeAdapter(Color.class, (JsonDeserializer<Object>) (json, typeOfT, context) -> {
// Example: #4c4c4cff
Expand Down Expand Up @@ -167,23 +165,23 @@ public boolean hasCollision() {
return !collisionShape.getSolids().isEmpty();
}

public VoxelShape computeOffsetCollisionShape(float x, float y, float z) {
public VoxelShape computeOffsetCollisionShape(double x, double y, double z) {
return collisionShape.translate(x, y, z);
}

public VoxelShape computeOffsetCollisionShape(Vector3fc vector) {
public VoxelShape computeOffsetCollisionShape(Vector3dc vector) {
return computeOffsetCollisionShape(vector.x(), vector.y(), vector.z());
}

public VoxelShape computeOffsetCollisionShape(Vector3ic vector) {
return computeOffsetCollisionShape(vector.x(), vector.y(), vector.z());
}

public VoxelShape computeOffsetShape(float x, float y, float z) {
public VoxelShape computeOffsetShape(double x, double y, double z) {
return shape.translate(x, y, z);
}

public VoxelShape computeOffsetShape(Vector3fc vector) {
public VoxelShape computeOffsetShape(Vector3dc vector) {
return computeOffsetShape(vector.x(), vector.y(), vector.z());
}

Expand Down
26 changes: 13 additions & 13 deletions api/src/main/java/org/allaymc/api/block/data/BlockFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import lombok.Getter;
import org.allaymc.api.block.property.enums.MinecraftCardinalDirection;
import org.jetbrains.annotations.ApiStatus;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.Vector3i;
import org.joml.Vector3ic;
import org.joml.primitives.AABBf;
import org.joml.primitives.AABBfc;
import org.joml.primitives.AABBd;
import org.joml.primitives.AABBdc;

import static java.lang.Math.max;
import static java.lang.Math.min;
Expand Down Expand Up @@ -103,12 +103,12 @@ public Vector3ic offsetPos(Vector3ic pos) {
*
* @return the rotated AABB.
*/
public AABBf rotateAABB(AABBfc aabb) {
var c1 = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
var c2 = new Vector3f(aabb.maxX(), aabb.maxY(), aabb.maxZ());
public AABBd rotateAABB(AABBdc aabb) {
var c1 = new Vector3d(aabb.minX(), aabb.minY(), aabb.minZ());
var c2 = new Vector3d(aabb.maxX(), aabb.maxY(), aabb.maxZ());
var nc1 = rotateVector(c1);
var nc2 = rotateVector(c2);
return new AABBf(
return new AABBd(
min(nc1.x, nc2.x),
min(nc1.y, nc2.y),
min(nc1.z, nc2.z),
Expand All @@ -126,12 +126,12 @@ public AABBf rotateAABB(AABBfc aabb) {
* @return the rotated vector.
*/
@SuppressWarnings("SuspiciousNameCombination")
public Vector3f rotateVector(Vector3fc vec) {
Vector3f result = new Vector3f(vec);
public Vector3d rotateVector(Vector3dc vec) {
Vector3d result = new Vector3d(vec);
// Translate to rotation point (0.5, 0.5, 0.5)
result.sub(0.5f, 0.5f, 0.5f);
result.sub(0.5, 0.5, 0.5);

float temp;
double temp;
switch (this) {
case EAST -> {
// No rotation needed as EAST is the default orientation
Expand Down Expand Up @@ -163,7 +163,7 @@ public Vector3f rotateVector(Vector3fc vec) {
}

// Translate back to original point
result.add(0.5f, 0.5f, 0.5f);
result.add(0.5, 0.5, 0.5);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static PlayerData createEmpty() {
var server = Server.getInstance();
var globalSpawnPoint = server.getWorldPool().getGlobalSpawnPoint();
var builder = NbtMap.builder();
writeVector3f(builder, "Pos", server.getWorldPool().getGlobalSpawnPointVec3f());
writeVector3f(builder, "Pos", globalSpawnPoint.x(), globalSpawnPoint.y(), globalSpawnPoint.z());
var worldName = globalSpawnPoint.dimension().getWorld().getWorldData().getDisplayName();
var dimId = globalSpawnPoint.dimension().getDimensionInfo().dimensionId();
return builder()
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/org/allaymc/api/command/CommandSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.i18n.TextReceiver;
import org.allaymc.api.i18n.TrContainer;
import org.allaymc.api.math.location.Location3fc;
import org.allaymc.api.math.location.Location3dc;
import org.allaymc.api.permission.Permissible;
import org.allaymc.api.server.Server;
import org.allaymc.api.world.gamerule.GameRule;
Expand Down Expand Up @@ -35,7 +35,7 @@ public interface CommandSender extends TextReceiver, Permissible {
*
* @return The location where the command was executed.
*/
Location3fc getCmdExecuteLocation();
Location3dc getCmdExecuteLocation();

/**
* Handle the result of the command execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.allaymc.api.entity.interfaces.EntityNpc;
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.i18n.TrContainer;
import org.allaymc.api.math.location.Location3fc;
import org.allaymc.api.math.location.Location3dc;
import org.allaymc.api.permission.DefaultPermissions;
import org.allaymc.api.permission.tree.PermissionTree;
import org.cloudburstmc.protocol.bedrock.data.command.CommandOriginData;
Expand Down Expand Up @@ -35,7 +35,7 @@ public CommandOriginData getCommandOriginData() {
}

@Override
public Location3fc getCmdExecuteLocation() {
public Location3dc getCmdExecuteLocation() {
return npc.getLocation();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.allaymc.api.command.selector.SelectorSyntaxException;
import org.allaymc.api.command.selector.SelectorType;
import org.allaymc.api.entity.Entity;
import org.allaymc.api.math.location.Location3fc;
import org.allaymc.api.math.location.Location3dc;

import java.util.List;
import java.util.Set;
Expand All @@ -27,7 +27,7 @@ public CachedFilterSelectorArgument() {
}

@Override
public Function<List<Entity>, List<Entity>> getFilter(SelectorType selectorType, CommandSender sender, Location3fc basePos, String... arguments) throws SelectorSyntaxException {
public Function<List<Entity>, List<Entity>> getFilter(SelectorType selectorType, CommandSender sender, Location3dc basePos, String... arguments) throws SelectorSyntaxException {
var value = cache.getIfPresent(Sets.newHashSet(arguments));
if (value == null) {
value = cache(selectorType, sender, basePos, arguments);
Expand Down Expand Up @@ -56,7 +56,7 @@ public boolean isFilter() {
*
* @throws SelectorSyntaxException if there is an error parsing the arguments.
*/
protected abstract Function<List<Entity>, List<Entity>> cache(SelectorType selectorType, CommandSender sender, Location3fc basePos, String... arguments) throws SelectorSyntaxException;
protected abstract Function<List<Entity>, List<Entity>> cache(SelectorType selectorType, CommandSender sender, Location3dc basePos, String... arguments) throws SelectorSyntaxException;

/**
* Provides the cache service used to store filter functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.allaymc.api.command.selector.SelectorSyntaxException;
import org.allaymc.api.command.selector.SelectorType;
import org.allaymc.api.entity.Entity;
import org.allaymc.api.math.location.Location3f;
import org.allaymc.api.math.location.Location3fc;
import org.allaymc.api.math.location.Location3d;
import org.allaymc.api.math.location.Location3dc;

import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand All @@ -27,7 +27,7 @@ public CachedSimpleSelectorArgument() {
}

@Override
public Predicate<Entity> getPredicate(SelectorType selectorType, CommandSender sender, Location3f basePos, String... arguments) throws SelectorSyntaxException {
public Predicate<Entity> getPredicate(SelectorType selectorType, CommandSender sender, Location3d basePos, String... arguments) throws SelectorSyntaxException {
var value = cache.getIfPresent(Sets.newHashSet(arguments));
if (value == null) {
value = cache(selectorType, sender, basePos, arguments);
Expand All @@ -50,7 +50,7 @@ public Predicate<Entity> getPredicate(SelectorType selectorType, CommandSender s
*
* @throws SelectorSyntaxException if the arguments cannot be parsed.
*/
protected abstract Predicate<Entity> cache(SelectorType selectorType, CommandSender sender, Location3fc basePos, String... arguments) throws SelectorSyntaxException;
protected abstract Predicate<Entity> cache(SelectorType selectorType, CommandSender sender, Location3dc basePos, String... arguments) throws SelectorSyntaxException;

/**
* Provides the cache service used to store predicates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.allaymc.api.command.selector.SelectorSyntaxException;
import org.allaymc.api.command.selector.SelectorType;
import org.allaymc.api.entity.Entity;
import org.allaymc.api.math.location.Location3f;
import org.allaymc.api.math.location.Location3fc;
import org.allaymc.api.math.location.Location3d;
import org.allaymc.api.math.location.Location3dc;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand Down Expand Up @@ -33,7 +33,7 @@ public interface SelectorArgument extends Comparable<SelectorArgument> {
*
* @throws SelectorSyntaxException if an error occurs while parsing the arguments.
*/
default Predicate<Entity> getPredicate(SelectorType selectorType, CommandSender sender, Location3f basePos, String... arguments) throws SelectorSyntaxException {
default Predicate<Entity> getPredicate(SelectorType selectorType, CommandSender sender, Location3d basePos, String... arguments) throws SelectorSyntaxException {
return null;
}

Expand All @@ -52,7 +52,7 @@ default Predicate<Entity> getPredicate(SelectorType selectorType, CommandSender
*
* @throws SelectorSyntaxException if an error occurs while parsing the arguments.
*/
default Function<List<Entity>, List<Entity>> getFilter(SelectorType selectorType, CommandSender sender, Location3fc basePos, String... arguments) throws SelectorSyntaxException {
default Function<List<Entity>, List<Entity>> getFilter(SelectorType selectorType, CommandSender sender, Location3dc basePos, String... arguments) throws SelectorSyntaxException {
return null;
}

Expand Down
Loading