From 45d7420397144ae66cad22f3b4b10616734959a0 Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 8 Jul 2021 18:56:40 +0200 Subject: [PATCH] Remove most Position/BlockPosition usage --- .../minestom/demo/largeframebuffers/Demo.java | 5 ++-- .../demo/largeframebuffers/MainDemo.java | 6 ++-- .../server/collision/BoundingBox.java | 5 ++-- .../ArgumentRelativeBlockPosition.java | 3 +- .../net/minestom/server/coordinate/Pos.java | 4 --- .../net/minestom/server/entity/Entity.java | 5 ---- .../server/entity/EntityCreature.java | 4 +-- .../server/entity/EntitySpawnType.java | 9 +++--- .../minestom/server/entity/LivingEntity.java | 11 ++++--- .../net/minestom/server/entity/Metadata.java | 21 +++++++------- .../net/minestom/server/entity/Player.java | 29 +++---------------- .../fakeplayer/FakePlayerController.java | 8 ++--- .../entity/metadata/LivingEntityMeta.java | 6 ++-- .../entity/metadata/animal/TurtleMeta.java | 17 +++++------ .../entity/metadata/golem/ShulkerMeta.java | 6 ++-- .../entity/metadata/other/EndCrystalMeta.java | 7 ++--- .../metadata/other/FallingBlockMeta.java | 9 +++--- .../entity/metadata/water/DolphinMeta.java | 10 +++---- .../entity/pathfinding/PFPathingEntity.java | 7 ++--- .../server/event/entity/EntityShootEvent.java | 2 +- .../net/minestom/server/instance/Chunk.java | 12 ++++---- .../server/instance/DynamicChunk.java | 7 ++--- .../minestom/server/instance/Explosion.java | 18 ++++++------ .../minestom/server/instance/Instance.java | 24 +++++++-------- .../server/instance/InstanceContainer.java | 27 ++++++++--------- .../instance/batch/RelativeBlockBatch.java | 6 ++-- .../rule/vanilla/StairsPlacementRule.java | 29 ++++++++++--------- .../server/item/metadata/CompassMeta.java | 21 +++++++------- .../packet/server/play/ChunkDataPacket.java | 9 +++--- .../server/play/SculkVibrationSignal.java | 3 +- .../server/utils/chunk/ChunkUtils.java | 12 +++----- .../server/utils/entity/EntityFinder.java | 12 ++++---- .../demo/generator/NoiseTestGenerator.java | 4 +-- src/test/java/demo/generator/Structure.java | 15 +++++----- .../UnloadCallbacksExtension.java | 4 +-- 35 files changed, 167 insertions(+), 210 deletions(-) diff --git a/src/lwjgl/java/net/minestom/demo/largeframebuffers/Demo.java b/src/lwjgl/java/net/minestom/demo/largeframebuffers/Demo.java index 31859d35a..5883660b9 100644 --- a/src/lwjgl/java/net/minestom/demo/largeframebuffers/Demo.java +++ b/src/lwjgl/java/net/minestom/demo/largeframebuffers/Demo.java @@ -2,6 +2,7 @@ package net.minestom.demo.largeframebuffers; import net.kyori.adventure.text.Component; import net.minestom.server.MinecraftServer; +import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.GameMode; @@ -19,7 +20,6 @@ import net.minestom.server.map.framebuffers.LargeGLFWFramebuffer; import net.minestom.server.map.framebuffers.LargeGraphics2DFramebuffer; import net.minestom.server.map.framebuffers.MapColorRenderer; import net.minestom.server.network.packet.server.play.MapDataPacket; -import net.minestom.server.utils.Position; import net.minestom.server.utils.time.TimeUnit; import java.awt.*; @@ -86,8 +86,7 @@ public class Demo { itemFrameMeta.setNotifyAboutChanges(true); - itemFrame.setInstance(instance, new Position(x, y, z)); - itemFrame.getPosition().setYaw(180f); + itemFrame.setInstance(instance, new Pos(x, y, z, 180, 0)); } private static void setupMaps(Instance instance, int mapIDStart, int zCoordinate) { diff --git a/src/lwjgl/java/net/minestom/demo/largeframebuffers/MainDemo.java b/src/lwjgl/java/net/minestom/demo/largeframebuffers/MainDemo.java index a459edd3f..e286d3c2b 100644 --- a/src/lwjgl/java/net/minestom/demo/largeframebuffers/MainDemo.java +++ b/src/lwjgl/java/net/minestom/demo/largeframebuffers/MainDemo.java @@ -1,6 +1,7 @@ package net.minestom.demo.largeframebuffers; import net.minestom.server.MinecraftServer; +import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.GameMode; import net.minestom.server.event.player.PlayerLoginEvent; import net.minestom.server.event.player.PlayerSpawnEvent; @@ -8,7 +9,6 @@ import net.minestom.server.instance.*; import net.minestom.server.instance.batch.ChunkBatch; import net.minestom.server.instance.block.Block; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.utils.Position; import net.minestom.server.world.biomes.Biome; import org.jetbrains.annotations.NotNull; @@ -35,12 +35,12 @@ public class MainDemo { // Set the spawning instance player.addEventCallback(PlayerLoginEvent.class, event -> { event.setSpawningInstance(instanceContainer); - player.setRespawnPoint(new Position(0, 45, 0)); + player.setRespawnPoint(new Pos(0, 45, 0)); }); // Teleport the player at spawn player.addEventCallback(PlayerSpawnEvent.class, event -> { - player.teleport(new Position(0, 45, 0)); + player.teleport(new Pos(0, 45, 0)); player.setGameMode(GameMode.CREATIVE); }); }); diff --git a/src/main/java/net/minestom/server/collision/BoundingBox.java b/src/main/java/net/minestom/server/collision/BoundingBox.java index d6ea5ee76..0f14f6100 100644 --- a/src/main/java/net/minestom/server/collision/BoundingBox.java +++ b/src/main/java/net/minestom/server/collision/BoundingBox.java @@ -1,9 +1,8 @@ package net.minestom.server.collision; -import net.minestom.server.entity.Entity; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; +import net.minestom.server.entity.Entity; import org.jetbrains.annotations.NotNull; /** @@ -52,7 +51,7 @@ public class BoundingBox { } /** - * Used to know if the bounding box intersects at a {@link BlockPosition}. + * Used to know if the bounding box intersects at a point. * * @param blockPosition the position to check * @return true if the bounding box intersects with the position, false otherwise diff --git a/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeBlockPosition.java b/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeBlockPosition.java index dc21b063a..f7c5e90d5 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeBlockPosition.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/relative/ArgumentRelativeBlockPosition.java @@ -4,13 +4,12 @@ import net.minestom.server.command.builder.NodeMaker; import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import net.minestom.server.coordinate.Vec; import net.minestom.server.network.packet.server.play.DeclareCommandsPacket; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.StringUtils; import net.minestom.server.utils.location.RelativeVec; import org.jetbrains.annotations.NotNull; /** - * Represents a {@link BlockPosition} with 3 integer numbers (x;y;z) which can take relative coordinates. + * Represents a block position with 3 integers (x;y;z) which can take relative coordinates. *

* Example: 5 ~ -3 */ diff --git a/src/main/java/net/minestom/server/coordinate/Pos.java b/src/main/java/net/minestom/server/coordinate/Pos.java index 78979b262..17177dc54 100644 --- a/src/main/java/net/minestom/server/coordinate/Pos.java +++ b/src/main/java/net/minestom/server/coordinate/Pos.java @@ -46,10 +46,6 @@ public final class Pos implements Point { return new Pos(point.x(), point.y(), point.z()); } - public static @NotNull Pos fromPosition(@NotNull Position position) { - return new Pos(position.getX(), position.getY(), position.getZ(), position.getYaw(), position.getPitch()); - } - @Contract(pure = true) public @NotNull Pos withCoord(double x, double y, double z) { return new Pos(x, y, z, yaw, pitch); diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index a67b09674..6aaca60d6 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -40,7 +40,6 @@ import net.minestom.server.potion.TimedPotion; import net.minestom.server.tag.Tag; import net.minestom.server.tag.TagHandler; import net.minestom.server.thread.ThreadProvider; -import net.minestom.server.utils.Position; import net.minestom.server.utils.callback.OptionalCallback; import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkUtils; @@ -874,10 +873,6 @@ public class Entity implements Viewable, Tickable, EventHandler, Da setInstance(instance, Pos.fromPoint(spawnPosition)); } - public void setInstance(@NotNull Instance instance, @NotNull Position spawnPosition) { - setInstance(instance, Pos.fromPosition(spawnPosition)); - } - /** * Changes the entity instance. * diff --git a/src/main/java/net/minestom/server/entity/EntityCreature.java b/src/main/java/net/minestom/server/entity/EntityCreature.java index 8e776d447..eb8f4761f 100644 --- a/src/main/java/net/minestom/server/entity/EntityCreature.java +++ b/src/main/java/net/minestom/server/entity/EntityCreature.java @@ -2,6 +2,7 @@ package net.minestom.server.entity; import com.extollit.gaming.ai.path.HydrazinePathFinder; import net.minestom.server.attribute.Attribute; +import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.ai.EntityAI; import net.minestom.server.entity.ai.EntityAIGroup; import net.minestom.server.entity.pathfinding.NavigableEntity; @@ -9,7 +10,6 @@ import net.minestom.server.entity.pathfinding.Navigator; import net.minestom.server.event.EventDispatcher; import net.minestom.server.event.entity.EntityAttackEvent; import net.minestom.server.instance.Instance; -import net.minestom.server.utils.Position; import net.minestom.server.utils.time.TimeUnit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,7 +55,7 @@ public class EntityCreature extends LivingEntity implements NavigableEntity, Ent } @Override - public void setInstance(@NotNull Instance instance, @NotNull Position spawnPosition) { + public void setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) { this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace())); super.setInstance(instance, spawnPosition); diff --git a/src/main/java/net/minestom/server/entity/EntitySpawnType.java b/src/main/java/net/minestom/server/entity/EntitySpawnType.java index 5d249a1d6..8d885b03d 100644 --- a/src/main/java/net/minestom/server/entity/EntitySpawnType.java +++ b/src/main/java/net/minestom/server/entity/EntitySpawnType.java @@ -1,12 +1,11 @@ package net.minestom.server.entity; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.metadata.ObjectDataProvider; import net.minestom.server.entity.metadata.other.ExperienceOrbMeta; import net.minestom.server.entity.metadata.other.PaintingMeta; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.play.*; -import net.minestom.server.utils.BlockPosition; -import net.minestom.server.utils.Vector; public enum EntitySpawnType { BASE { @@ -78,7 +77,7 @@ public enum EntitySpawnType { if (entity.getEntityMeta() instanceof PaintingMeta) { PaintingMeta paintingMeta = (PaintingMeta) entity.getEntityMeta(); packet.motive = paintingMeta.getMotive().ordinal(); - packet.position = new BlockPosition( + packet.position = new Vec( Math.max(0, (paintingMeta.getMotive().getWidth() >> 1) - 1), paintingMeta.getMotive().getHeight() >> 1, 0 @@ -98,12 +97,12 @@ public enum EntitySpawnType { break; } } else { - packet.position = new BlockPosition(0, 0, 0); + packet.position = Vec.ZERO; } return packet; } }; public abstract ServerPacket getSpawnPacket(Entity entity); - + } diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index 2ec1f2977..8424090fc 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -5,6 +5,8 @@ import net.minestom.server.attribute.Attribute; import net.minestom.server.attribute.AttributeInstance; import net.minestom.server.attribute.Attributes; import net.minestom.server.collision.BoundingBox; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.damage.DamageType; import net.minestom.server.entity.metadata.LivingEntityMeta; import net.minestom.server.event.EventDispatcher; @@ -25,10 +27,7 @@ import net.minestom.server.network.packet.server.play.SoundEffectPacket; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.scoreboard.Team; import net.minestom.server.sound.SoundEvent; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.block.BlockIterator; -import net.minestom.server.coordinate.Point; -import net.minestom.server.coordinate.Vec; import net.minestom.server.utils.time.Cooldown; import net.minestom.server.utils.time.TimeUnit; import org.jetbrains.annotations.NotNull; @@ -718,10 +717,10 @@ public class LivingEntity extends Entity implements EquipmentHandler { } /** - * Gets the line of sight in {@link BlockPosition} of the entity. + * Gets the line of sight of the entity. * * @param maxDistance The max distance to scan - * @return A list of {@link BlockPosition} in this entities line of sight + * @return A list of {@link Point poiints} in this entities line of sight */ public List getLineOfSight(int maxDistance) { List blocks = new ArrayList<>(); @@ -758,7 +757,7 @@ public class LivingEntity extends Entity implements EquipmentHandler { } /** - * Gets the target (not-air) {@link BlockPosition} of the entity. + * Gets the target (not-air) block position of the entity. * * @param maxDistance The max distance to scan before returning null * @return The block position targeted by this entity, null if non are found diff --git a/src/main/java/net/minestom/server/entity/Metadata.java b/src/main/java/net/minestom/server/entity/Metadata.java index 58ed7b3d6..0a930886e 100644 --- a/src/main/java/net/minestom/server/entity/Metadata.java +++ b/src/main/java/net/minestom/server/entity/Metadata.java @@ -4,16 +4,15 @@ import net.kyori.adventure.text.Component; import net.minestom.server.MinecraftServer; import net.minestom.server.chat.ColoredText; import net.minestom.server.chat.JsonMessage; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.play.EntityMetaDataPacket; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.Direction; -import net.minestom.server.utils.Vector; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.Readable; import net.minestom.server.utils.binary.Writeable; -import net.minestom.server.coordinate.Point; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jglrxavpok.hephaistos.nbt.NBT; @@ -98,12 +97,12 @@ public class Metadata { return new Value<>(TYPE_BOOLEAN, value, writer -> writer.writeBoolean(value), BinaryReader::readBoolean); } - public static Value Rotation(@NotNull Vector value) { + public static Value Rotation(@NotNull Point value) { return new Value<>(TYPE_ROTATION, value, writer -> { - writer.writeFloat((float) value.getX()); - writer.writeFloat((float) value.getY()); - writer.writeFloat((float) value.getZ()); - }, reader -> new Vector(reader.readFloat(), reader.readFloat(), reader.readFloat())); + writer.writeFloat((float) value.x()); + writer.writeFloat((float) value.y()); + writer.writeFloat((float) value.z()); + }, reader -> new Vec(reader.readFloat(), reader.readFloat(), reader.readFloat())); } public static Value Position(@NotNull Point value) { @@ -339,7 +338,7 @@ public class Metadata { case TYPE_STRING: return (Value) String(""); case TYPE_CHAT: - return (Value) Chat(ColoredText.of("")); + return (Value) Chat(Component.empty()); case TYPE_OPTCHAT: return (Value) OptChat((Component) null); case TYPE_SLOT: @@ -347,9 +346,9 @@ public class Metadata { case TYPE_BOOLEAN: return (Value) Boolean(false); case TYPE_ROTATION: - return (Value) Rotation(new Vector()); + return (Value) Rotation(Vec.ZERO); case TYPE_POSITION: - return (Value) Position(new BlockPosition(0, 0, 0)); + return (Value) Position(Vec.ZERO); case TYPE_OPTPOSITION: return (Value) OptPosition(null); case TYPE_DIRECTION: diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 5509c3b6a..f9b4e6aba 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -26,6 +26,9 @@ import net.minestom.server.chat.JsonMessage; import net.minestom.server.collision.BoundingBox; import net.minestom.server.command.CommandManager; import net.minestom.server.command.CommandSender; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Pos; +import net.minestom.server.coordinate.Vec; import net.minestom.server.effects.Effects; import net.minestom.server.entity.damage.DamageType; import net.minestom.server.entity.fakeplayer.FakePlayer; @@ -68,8 +71,6 @@ import net.minestom.server.stat.PlayerStatistic; import net.minestom.server.utils.*; import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkUtils; -import net.minestom.server.coordinate.Point; -import net.minestom.server.coordinate.Pos; import net.minestom.server.utils.entity.EntityUtils; import net.minestom.server.utils.identity.NamedAndIdentified; import net.minestom.server.utils.instance.InstanceUtils; @@ -700,17 +701,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable, playerConnection.sendPacket(soundEffectPacket); } - /** - * Plays a sound from the {@link SoundEvent} enum. - * - * @see #playSound(SoundEvent, SoundCategory, int, int, int, float, float) - * @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)} - */ - @Deprecated - public void playSound(@NotNull SoundEvent sound, @NotNull SoundCategory soundCategory, BlockPosition position, float volume, float pitch) { - playSound(sound, soundCategory, position.getX(), position.getY(), position.getZ(), volume, pitch); - } - /** * Plays a sound from an identifier (represents a custom sound in a resource pack). * @@ -736,17 +726,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable, playerConnection.sendPacket(namedSoundEffectPacket); } - /** - * Plays a sound from an identifier (represents a custom sound in a resource pack). - * - * @see #playSound(String, SoundCategory, int, int, int, float, float) - * @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)} - */ - @Deprecated - public void playSound(@NotNull String identifier, @NotNull SoundCategory soundCategory, BlockPosition position, float volume, float pitch) { - playSound(identifier, soundCategory, position.getX(), position.getY(), position.getZ(), volume, pitch); - } - /** * Plays a sound directly to the player (constant volume). * @@ -808,7 +787,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, public void playEffect(@NotNull Effects effect, int x, int y, int z, int data, boolean disableRelativeVolume) { EffectPacket packet = new EffectPacket(); packet.effectId = effect.getId(); - packet.position = new BlockPosition(x, y, z); + packet.position = new Vec(x, y, z); packet.data = data; packet.disableRelativeVolume = disableRelativeVolume; playerConnection.sendPacket(packet); diff --git a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java index 1a3d21b84..2bd9c0cec 100644 --- a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java +++ b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayerController.java @@ -1,5 +1,6 @@ package net.minestom.server.entity.fakeplayer; +import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Player; import net.minestom.server.instance.block.BlockFace; @@ -13,7 +14,6 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.play.KeepAlivePacket; import net.minestom.server.network.packet.server.play.PlayerPositionAndLookPacket; import net.minestom.server.network.player.PlayerConnection; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.inventory.PlayerInventoryUtils; import net.minestom.server.utils.validate.Check; @@ -179,7 +179,7 @@ public class FakePlayerController { * @param blockPosition The position of the block to be excavated. * @param blockFace From where the block is struck. */ - public void startDigging(BlockPosition blockPosition, BlockFace blockFace) { + public void startDigging(Point blockPosition, BlockFace blockFace) { ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket(); playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.STARTED_DIGGING; playerDiggingPacket.blockPosition = blockPosition; @@ -193,7 +193,7 @@ public class FakePlayerController { * @param blockPosition The position of the block to be excavated. * @param blockFace From where the block is struck. */ - public void stopDigging(BlockPosition blockPosition, BlockFace blockFace) { + public void stopDigging(Point blockPosition, BlockFace blockFace) { ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket(); playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.CANCELLED_DIGGING; playerDiggingPacket.blockPosition = blockPosition; @@ -207,7 +207,7 @@ public class FakePlayerController { * @param blockPosition The position of the block to be excavated. * @param blockFace From where the block is struck. */ - public void finishDigging(BlockPosition blockPosition, BlockFace blockFace) { + public void finishDigging(Point blockPosition, BlockFace blockFace) { ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket(); playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.FINISHED_DIGGING; playerDiggingPacket.blockPosition = blockPosition; diff --git a/src/main/java/net/minestom/server/entity/metadata/LivingEntityMeta.java b/src/main/java/net/minestom/server/entity/metadata/LivingEntityMeta.java index 7bc461571..5fb47c1d5 100644 --- a/src/main/java/net/minestom/server/entity/metadata/LivingEntityMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/LivingEntityMeta.java @@ -1,9 +1,9 @@ package net.minestom.server.entity.metadata; +import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; import net.minestom.server.entity.Player; -import net.minestom.server.utils.BlockPosition; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,11 +85,11 @@ public class LivingEntityMeta extends EntityMeta { } @Nullable - public BlockPosition getBedInWhichSleepingPosition() { + public Point getBedInWhichSleepingPosition() { return super.metadata.getIndex(OFFSET + 6, null); } - public void setBedInWhichSleepingPosition(@Nullable BlockPosition value) { + public void setBedInWhichSleepingPosition(@Nullable Point value) { super.metadata.setIndex(OFFSET + 6, Metadata.OptPosition(value)); } diff --git a/src/main/java/net/minestom/server/entity/metadata/animal/TurtleMeta.java b/src/main/java/net/minestom/server/entity/metadata/animal/TurtleMeta.java index ade516a38..2f12487ae 100644 --- a/src/main/java/net/minestom/server/entity/metadata/animal/TurtleMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/animal/TurtleMeta.java @@ -1,8 +1,9 @@ package net.minestom.server.entity.metadata.animal; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; -import net.minestom.server.utils.BlockPosition; import org.jetbrains.annotations.NotNull; public class TurtleMeta extends AnimalMeta { @@ -13,12 +14,11 @@ public class TurtleMeta extends AnimalMeta { super(entity, metadata); } - @NotNull - public BlockPosition getHomePosition() { - return super.metadata.getIndex(OFFSET, new BlockPosition(0, 0, 0)); + public @NotNull Point getHomePosition() { + return super.metadata.getIndex(OFFSET, Vec.ZERO); } - public void setBlockPosition(@NotNull BlockPosition value) { + public void setBlockPosition(@NotNull Point value) { super.metadata.setIndex(OFFSET, Metadata.Position(value)); } @@ -38,12 +38,11 @@ public class TurtleMeta extends AnimalMeta { super.metadata.setIndex(OFFSET + 2, Metadata.Boolean(value)); } - @NotNull - public BlockPosition getTravelPosition() { - return super.metadata.getIndex(OFFSET + 3, new BlockPosition(0, 0, 0)); + public @NotNull Point getTravelPosition() { + return super.metadata.getIndex(OFFSET + 3, Vec.ZERO); } - public void setTravelPosition(@NotNull BlockPosition value) { + public void setTravelPosition(@NotNull Point value) { super.metadata.setIndex(OFFSET + 3, Metadata.Position(value)); } diff --git a/src/main/java/net/minestom/server/entity/metadata/golem/ShulkerMeta.java b/src/main/java/net/minestom/server/entity/metadata/golem/ShulkerMeta.java index 169c23738..7996fee89 100644 --- a/src/main/java/net/minestom/server/entity/metadata/golem/ShulkerMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/golem/ShulkerMeta.java @@ -1,8 +1,8 @@ package net.minestom.server.entity.metadata.golem; +import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.Direction; import org.jetbrains.annotations.NotNull; @@ -22,11 +22,11 @@ public class ShulkerMeta extends AbstractGolemMeta { super.metadata.setIndex(OFFSET, Metadata.Direction(value)); } - public BlockPosition getAttachmentPosition() { + public Point getAttachmentPosition() { return super.metadata.getIndex(OFFSET + 1, null); } - public void setAttachmentPosition(BlockPosition value) { + public void setAttachmentPosition(Point value) { super.metadata.setIndex(OFFSET + 1, Metadata.OptPosition(value)); } diff --git a/src/main/java/net/minestom/server/entity/metadata/other/EndCrystalMeta.java b/src/main/java/net/minestom/server/entity/metadata/other/EndCrystalMeta.java index b5ff2147a..c4889ddaa 100644 --- a/src/main/java/net/minestom/server/entity/metadata/other/EndCrystalMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/other/EndCrystalMeta.java @@ -1,9 +1,9 @@ package net.minestom.server.entity.metadata.other; +import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; import net.minestom.server.entity.metadata.EntityMeta; -import net.minestom.server.utils.BlockPosition; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,12 +15,11 @@ public class EndCrystalMeta extends EntityMeta { super(entity, metadata); } - @Nullable - public BlockPosition getBeamTarget() { + public @Nullable Point getBeamTarget() { return super.metadata.getIndex(OFFSET, null); } - public void setBeamTarget(@Nullable BlockPosition value) { + public void setBeamTarget(@Nullable Point value) { super.metadata.setIndex(OFFSET, Metadata.OptPosition(value)); } diff --git a/src/main/java/net/minestom/server/entity/metadata/other/FallingBlockMeta.java b/src/main/java/net/minestom/server/entity/metadata/other/FallingBlockMeta.java index 683bd8d43..fa449d1b3 100644 --- a/src/main/java/net/minestom/server/entity/metadata/other/FallingBlockMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/other/FallingBlockMeta.java @@ -1,11 +1,12 @@ package net.minestom.server.entity.metadata.other; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; import net.minestom.server.entity.metadata.EntityMeta; import net.minestom.server.entity.metadata.ObjectDataProvider; import net.minestom.server.instance.block.Block; -import net.minestom.server.utils.BlockPosition; import org.jetbrains.annotations.NotNull; public class FallingBlockMeta extends EntityMeta implements ObjectDataProvider { @@ -18,11 +19,11 @@ public class FallingBlockMeta extends EntityMeta implements ObjectDataProvider { super(entity, metadata); } - public BlockPosition getSpawnPosition() { - return super.metadata.getIndex(OFFSET, new BlockPosition(0, 0, 0)); + public Point getSpawnPosition() { + return super.metadata.getIndex(OFFSET, Vec.ZERO); } - public void setSpawnPosition(BlockPosition value) { + public void setSpawnPosition(Point value) { super.metadata.setIndex(OFFSET, Metadata.Position(value)); } diff --git a/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java b/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java index b0b1d1a90..549027447 100644 --- a/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java +++ b/src/main/java/net/minestom/server/entity/metadata/water/DolphinMeta.java @@ -1,9 +1,9 @@ package net.minestom.server.entity.metadata.water; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; import net.minestom.server.entity.Metadata; -import net.minestom.server.entity.metadata.EntityMeta; -import net.minestom.server.utils.BlockPosition; import org.jetbrains.annotations.NotNull; public class DolphinMeta extends WaterAnimalMeta { @@ -15,11 +15,11 @@ public class DolphinMeta extends WaterAnimalMeta { } @NotNull - public BlockPosition getTreasurePosition() { - return super.metadata.getIndex(OFFSET, new BlockPosition(0, 0, 0)); + public Point getTreasurePosition() { + return super.metadata.getIndex(OFFSET, Vec.ZERO); } - public void setTreasurePosition(@NotNull BlockPosition value) { + public void setTreasurePosition(@NotNull Point value) { super.metadata.setIndex(OFFSET, Metadata.Position(value)); } diff --git a/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java b/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java index 75a6df53d..67935a7a5 100644 --- a/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java +++ b/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java @@ -5,10 +5,10 @@ import com.extollit.gaming.ai.path.model.IPathingEntity; import com.extollit.gaming.ai.path.model.Passibility; import com.extollit.linalg.immutable.Vec3d; import net.minestom.server.attribute.Attribute; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; import net.minestom.server.entity.LivingEntity; -import net.minestom.server.utils.Position; -import net.minestom.server.coordinate.Point; import org.jetbrains.annotations.NotNull; public class PFPathingEntity implements IPathingEntity { @@ -194,8 +194,7 @@ public class PFPathingEntity implements IPathingEntity { @Override public void moveTo(Vec3d position, Passibility passibility, Gravitation gravitation) { - this.targetPosition = new Position(position.x, position.y, position.z); - + this.targetPosition = new Vec(position.x, position.y, position.z); final double entityY = entity.getPosition().y(); if (entityY < targetPosition.y()) { this.navigator.jump(1); diff --git a/src/main/java/net/minestom/server/event/entity/EntityShootEvent.java b/src/main/java/net/minestom/server/event/entity/EntityShootEvent.java index 7f1b5d1be..5ab190e69 100644 --- a/src/main/java/net/minestom/server/event/entity/EntityShootEvent.java +++ b/src/main/java/net/minestom/server/event/entity/EntityShootEvent.java @@ -9,7 +9,7 @@ import net.minestom.server.coordinate.Point; import org.jetbrains.annotations.NotNull; /** - * Called with {@link EntityProjectile#shoot(Position, double, double)} + * Called with {@link EntityProjectile#shoot(Point, double, double)} */ public class EntityShootEvent implements EntityEvent, CancellableEvent { diff --git a/src/main/java/net/minestom/server/instance/Chunk.java b/src/main/java/net/minestom/server/instance/Chunk.java index 6d5166854..222ee3146 100644 --- a/src/main/java/net/minestom/server/instance/Chunk.java +++ b/src/main/java/net/minestom/server/instance/Chunk.java @@ -2,6 +2,8 @@ package net.minestom.server.instance; import net.minestom.server.Tickable; import net.minestom.server.Viewable; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.data.Data; import net.minestom.server.data.DataContainer; import net.minestom.server.entity.Player; @@ -15,10 +17,9 @@ import net.minestom.server.instance.block.BlockSetter; import net.minestom.server.network.packet.server.play.ChunkDataPacket; import net.minestom.server.network.packet.server.play.UpdateLightPacket; import net.minestom.server.network.player.PlayerConnection; -import net.minestom.server.utils.ArrayUtils; import net.minestom.server.tag.Tag; import net.minestom.server.tag.TagHandler; -import net.minestom.server.utils.PacketUtils; +import net.minestom.server.utils.ArrayUtils; import net.minestom.server.utils.Position; import net.minestom.server.utils.chunk.ChunkSupplier; import net.minestom.server.world.biomes.Biome; @@ -208,13 +209,12 @@ public abstract class Chunk implements BlockGetter, BlockSetter, Viewable, Ticka } /** - * Creates a {@link Position} object based on this chunk. + * Gets the world position of this chunk. * * @return the position of this chunk */ - @NotNull - public Position toPosition() { - return new Position(CHUNK_SIZE_Z * getChunkX(), 0, CHUNK_SIZE_Z * getChunkZ()); + public @NotNull Point toPosition() { + return new Vec(CHUNK_SIZE_Z * getChunkX(), 0, CHUNK_SIZE_Z * getChunkZ()); } /** diff --git a/src/main/java/net/minestom/server/instance/DynamicChunk.java b/src/main/java/net/minestom/server/instance/DynamicChunk.java index 232f4e5fa..67598baea 100644 --- a/src/main/java/net/minestom/server/instance/DynamicChunk.java +++ b/src/main/java/net/minestom/server/instance/DynamicChunk.java @@ -2,14 +2,12 @@ package net.minestom.server.instance; import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.pathfinding.PFBlock; import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.BlockHandler; import net.minestom.server.network.packet.server.play.ChunkDataPacket; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.chunk.ChunkUtils; -import net.minestom.server.utils.time.Cooldown; -import net.minestom.server.utils.validate.Check; import net.minestom.server.world.biomes.Biome; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,7 +15,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound; import java.lang.ref.SoftReference; import java.util.Map; -import java.time.Duration; import java.util.Set; import java.util.TreeMap; @@ -99,7 +96,7 @@ public class DynamicChunk extends Chunk { final int x = ChunkUtils.blockIndexToChunkPositionX(index); final int y = ChunkUtils.blockIndexToChunkPositionY(index); final int z = ChunkUtils.blockIndexToChunkPositionZ(index); - final BlockPosition blockPosition = new BlockPosition(x, y, z); + final Vec blockPosition = new Vec(x, y, z); final Block block = getBlock(blockPosition); entry.getValue().tick(new BlockHandler.Tick(block, instance, blockPosition)); diff --git a/src/main/java/net/minestom/server/instance/Explosion.java b/src/main/java/net/minestom/server/instance/Explosion.java index 5e57a13d1..2deca9808 100644 --- a/src/main/java/net/minestom/server/instance/Explosion.java +++ b/src/main/java/net/minestom/server/instance/Explosion.java @@ -1,8 +1,8 @@ package net.minestom.server.instance; +import net.minestom.server.coordinate.Point; import net.minestom.server.instance.block.Block; import net.minestom.server.network.packet.server.play.ExplosionPacket; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.PacketUtils; import org.jetbrains.annotations.NotNull; @@ -48,7 +48,7 @@ public abstract class Explosion { * @param instance instance to perform this explosion in * @return list of blocks that will be broken. */ - protected abstract List prepare(Instance instance); + protected abstract List prepare(Instance instance); /** * Performs the explosion and send the corresponding packet @@ -56,7 +56,7 @@ public abstract class Explosion { * @param instance instance to perform this explosion in */ public void apply(@NotNull Instance instance) { - List blocks = prepare(instance); + List blocks = prepare(instance); ExplosionPacket packet = new ExplosionPacket(); packet.x = getCenterX(); packet.y = getCenterY(); @@ -68,11 +68,11 @@ public abstract class Explosion { packet.records = new byte[3 * blocks.size()]; for (int i = 0; i < blocks.size(); i++) { - final BlockPosition pos = blocks.get(i); + final var pos = blocks.get(i); instance.setBlock(pos, Block.AIR); - final byte x = (byte) (pos.getX() - Math.floor(getCenterX())); - final byte y = (byte) (pos.getY() - Math.floor(getCenterY())); - final byte z = (byte) (pos.getZ() - Math.floor(getCenterZ())); + final byte x = (byte) (pos.x() - Math.floor(getCenterX())); + final byte y = (byte) (pos.y() - Math.floor(getCenterY())); + final byte z = (byte) (pos.z() - Math.floor(getCenterZ())); packet.records[i * 3 + 0] = x; packet.records[i * 3 + 1] = y; packet.records[i * 3 + 2] = z; @@ -96,7 +96,7 @@ public abstract class Explosion { * stored in the packet before this call, but you are free to modify 'records' to modify the blocks sent to the client. * Just be careful, you might just crash the server or the client. Or you're lucky, both at the same time. */ - protected void postExplosion(Instance instance, List blocks, ExplosionPacket packet) { + protected void postExplosion(Instance instance, List blocks, ExplosionPacket packet) { } /** @@ -106,6 +106,6 @@ public abstract class Explosion { * @param instance the instance in which the explosion occurs * @param blocks the block positions returned by prepare */ - protected void postSend(Instance instance, List blocks) { + protected void postSend(Instance instance, List blocks) { } } diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index df05555fd..192e68747 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -6,6 +6,8 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.Tickable; import net.minestom.server.UpdateManager; import net.minestom.server.adventure.audience.PacketGroupingAudience; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Pos; import net.minestom.server.data.Data; import net.minestom.server.data.DataContainer; import net.minestom.server.entity.Entity; @@ -29,13 +31,9 @@ import net.minestom.server.storage.StorageLocation; import net.minestom.server.tag.Tag; import net.minestom.server.tag.TagHandler; import net.minestom.server.thread.ThreadProvider; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.PacketUtils; -import net.minestom.server.utils.Position; import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkUtils; -import net.minestom.server.coordinate.Point; -import net.minestom.server.coordinate.Pos; import net.minestom.server.utils.entity.EntityUtils; import net.minestom.server.utils.time.Cooldown; import net.minestom.server.utils.time.TimeUnit; @@ -534,9 +532,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta } /** - * Loads the chunk at the given {@link Position} with a callback. + * Loads the chunk at the given {@link Point} with a callback. * - * @param point the chunk position + * @param point the chunk position * @param callback the optional callback to run when the chunk is loaded */ public void loadChunk(@NotNull Point point, @Nullable ChunkCallback callback) { @@ -547,9 +545,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta /** * Loads a {@link Chunk} (if {@link #hasEnabledAutoChunkLoad()} returns true) - * at the given {@link Position} with a callback. + * at the given {@link Point} with a callback. * - * @param point the chunk position + * @param point the chunk position * @param callback the optional callback executed when the chunk is loaded (or with a null chunk if not) */ public void loadOptionalChunk(@NotNull Point point, @Nullable ChunkCallback callback) { @@ -587,7 +585,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta * @param actionParam the action parameter, depends on the block * @see BlockActionPacket for the action id & param */ - public void sendBlockAction(@NotNull BlockPosition blockPosition, byte actionId, byte actionParam) { + public void sendBlockAction(@NotNull Point blockPosition, byte actionId, byte actionParam) { final Block block = getBlock(blockPosition); BlockActionPacket blockActionPacket = new BlockActionPacket(); @@ -602,14 +600,13 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta } /** - * Gets the {@link Chunk} at the given {@link BlockPosition}, null if not loaded. + * Gets the {@link Chunk} at the given block position, null if not loaded. * * @param x the X position * @param z the Z position * @return the chunk at the given position, null if not loaded */ - @Nullable - public Chunk getChunkAt(double x, double z) { + public @Nullable Chunk getChunkAt(double x, double z) { final int chunkX = ChunkUtils.getChunkCoordinate(x); final int chunkZ = ChunkUtils.getChunkCoordinate(z); return getChunk(chunkX, chunkZ); @@ -621,8 +618,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta * @param point the chunk position * @return the chunk at the given position, null if not loaded */ - @Nullable - public Chunk getChunkAt(@NotNull Point point) { + public @Nullable Chunk getChunkAt(@NotNull Point point) { return getChunkAt(point.x(), point.z()); } diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index a9b6dec6c..ce0928dd7 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -1,6 +1,8 @@ package net.minestom.server.instance; import net.minestom.server.MinecraftServer; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.data.Data; import net.minestom.server.data.SerializableData; import net.minestom.server.entity.Player; @@ -23,7 +25,6 @@ import net.minestom.server.utils.callback.OptionalCallback; import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkSupplier; import net.minestom.server.utils.chunk.ChunkUtils; -import net.minestom.server.coordinate.Point; import net.minestom.server.utils.validate.Check; import net.minestom.server.world.DimensionType; import net.minestom.server.world.biomes.Biome; @@ -59,7 +60,7 @@ public class InstanceContainer extends Instance { protected final Set scheduledChunksToRemove = new HashSet<>(); private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock(); - private final Map currentlyChangingBlocks = new HashMap<>(); + private final Map currentlyChangingBlocks = new HashMap<>(); // the chunk loader, used when trying to load/save a chunk from another source private IChunkLoader chunkLoader; @@ -137,7 +138,7 @@ public class InstanceContainer extends Instance { synchronized (chunk) { // Refresh the last block change time this.lastBlockChangeTime = System.currentTimeMillis(); - final BlockPosition blockPosition = new BlockPosition(x, y, z); + final Vec blockPosition = new Vec(x, y, z); if (isAlreadyChanged(blockPosition, block)) { // do NOT change the block again. // Avoids StackOverflowExceptions when onDestroy tries to destroy the block itself // This can happen with nether portals which break the entire frame when a portal block is broken @@ -565,7 +566,7 @@ public class InstanceContainer extends Instance { } /** - * Sends a {@link BlockChangePacket} at the specified {@link BlockPosition} to set the block as {@code blockStateId}. + * Sends a {@link BlockChangePacket} at the specified position to set the block as {@code blockStateId}. *

* WARNING: this does not change the internal block data, this is strictly visual for the players. * @@ -573,7 +574,7 @@ public class InstanceContainer extends Instance { * @param blockPosition the block position * @param block the new block */ - private void sendBlockChange(@NotNull Chunk chunk, @NotNull BlockPosition blockPosition, @NotNull Block block) { + private void sendBlockChange(@NotNull Chunk chunk, @NotNull Point blockPosition, @NotNull Block block) { chunk.sendPacketToViewers(new BlockChangePacket(blockPosition, block.stateId())); } @@ -637,7 +638,7 @@ public class InstanceContainer extends Instance { } } - private void setAlreadyChanged(@NotNull BlockPosition blockPosition, Block block) { + private void setAlreadyChanged(@NotNull Point blockPosition, Block block) { currentlyChangingBlocks.put(blockPosition, block); } @@ -649,7 +650,7 @@ public class InstanceContainer extends Instance { * @param block the block * @return true if the block changed since the last update */ - private boolean isAlreadyChanged(@NotNull BlockPosition blockPosition, @NotNull Block block) { + private boolean isAlreadyChanged(@NotNull Point blockPosition, @NotNull Block block) { final Block changedBlock = currentlyChangingBlocks.get(blockPosition); if (changedBlock == null) return false; @@ -663,7 +664,7 @@ public class InstanceContainer extends Instance { * @param blockPosition the block position * @return the modified block state id */ - private Block executeBlockPlacementRule(Block block, @NotNull BlockPosition blockPosition) { + private Block executeBlockPlacementRule(Block block, @NotNull Point blockPosition) { final BlockPlacementRule blockPlacementRule = BLOCK_MANAGER.getBlockPlacementRule(block); if (blockPlacementRule != null) { return blockPlacementRule.blockUpdate(this, blockPosition, block); @@ -678,15 +679,15 @@ public class InstanceContainer extends Instance { * * @param blockPosition the position of the modified block */ - private void executeNeighboursBlockPlacementRule(@NotNull BlockPosition blockPosition) { + private void executeNeighboursBlockPlacementRule(@NotNull Point blockPosition) { for (int offsetX = -1; offsetX < 2; offsetX++) { for (int offsetY = -1; offsetY < 2; offsetY++) { for (int offsetZ = -1; offsetZ < 2; offsetZ++) { if (offsetX == 0 && offsetY == 0 && offsetZ == 0) continue; - final int neighborX = blockPosition.getX() + offsetX; - final int neighborY = blockPosition.getY() + offsetY; - final int neighborZ = blockPosition.getZ() + offsetZ; + final int neighborX = blockPosition.blockX() + offsetX; + final int neighborY = blockPosition.blockY() + offsetY; + final int neighborZ = blockPosition.blockZ() + offsetZ; final Chunk chunk = getChunkAt(neighborX, neighborZ); // Do not try to get neighbour in an unloaded chunk @@ -696,7 +697,7 @@ public class InstanceContainer extends Instance { final Block neighborBlock = chunk.getBlock(neighborX, neighborY, neighborZ); final BlockPlacementRule neighborBlockPlacementRule = BLOCK_MANAGER.getBlockPlacementRule(neighborBlock); if (neighborBlockPlacementRule != null) { - final BlockPosition neighborPosition = new BlockPosition(neighborX, neighborY, neighborZ); + final Vec neighborPosition = new Vec(neighborX, neighborY, neighborZ); final Block newNeighborBlock = neighborBlockPlacementRule.blockUpdate(this, neighborPosition, neighborBlock); if (neighborBlock != newNeighborBlock) { diff --git a/src/main/java/net/minestom/server/instance/batch/RelativeBlockBatch.java b/src/main/java/net/minestom/server/instance/batch/RelativeBlockBatch.java index 8e6569338..4af6ae084 100644 --- a/src/main/java/net/minestom/server/instance/batch/RelativeBlockBatch.java +++ b/src/main/java/net/minestom/server/instance/batch/RelativeBlockBatch.java @@ -2,9 +2,9 @@ package net.minestom.server.instance.batch; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import net.minestom.server.coordinate.Point; import net.minestom.server.instance.Instance; import net.minestom.server.instance.block.Block; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -106,8 +106,8 @@ public class RelativeBlockBatch implements Batch { * @param callback The callback to be executed when the batch is applied * @return The inverse of this batch, if inverse is enabled in the {@link BatchOption} */ - public AbsoluteBlockBatch apply(@NotNull Instance instance, @NotNull BlockPosition position, @Nullable Runnable callback) { - return apply(instance, position.getX(), position.getY(), position.getZ(), callback); + public AbsoluteBlockBatch apply(@NotNull Instance instance, @NotNull Point position, @Nullable Runnable callback) { + return apply(instance, position.blockX(), position.blockY(), position.blockZ(), callback); } /** diff --git a/src/main/java/net/minestom/server/instance/block/rule/vanilla/StairsPlacementRule.java b/src/main/java/net/minestom/server/instance/block/rule/vanilla/StairsPlacementRule.java index 216cc1e86..c621398a6 100644 --- a/src/main/java/net/minestom/server/instance/block/rule/vanilla/StairsPlacementRule.java +++ b/src/main/java/net/minestom/server/instance/block/rule/vanilla/StairsPlacementRule.java @@ -1,6 +1,7 @@ package net.minestom.server.instance.block.rule.vanilla; import it.unimi.dsi.fastutil.Pair; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Player; import net.minestom.server.instance.Instance; import net.minestom.server.instance.block.Block; @@ -51,26 +52,26 @@ public class StairsPlacementRule extends BlockPlacementRule { private enum Facing { NORTH( - new BlockPosition(0, 0, 1), - new BlockPosition(0, 0, -1) + new Vec(0, 0, 1), + new Vec(0, 0, -1) ), EAST( - new BlockPosition(-1, 0, 0), - new BlockPosition(1, 0, 0) + new Vec(-1, 0, 0), + new Vec(1, 0, 0) ), SOUTH( - new BlockPosition(0, 0, -1), - new BlockPosition(0, 0, 1) + new Vec(0, 0, -1), + new Vec(0, 0, 1) ), WEST( - new BlockPosition(1, 0, 0), - new BlockPosition(-1, 0, 0) + new Vec(1, 0, 0), + new Vec(-1, 0, 0) ); - private final BlockPosition front; - private final BlockPosition back; + private final Point front; + private final Point back; - Facing(@NotNull BlockPosition front, @NotNull BlockPosition back) { + Facing(@NotNull Point front, @NotNull Point back) { this.front = front; this.back = back; } @@ -83,12 +84,12 @@ public class StairsPlacementRule extends BlockPlacementRule { } @NotNull - public Pair<@Nullable Shape, @Nullable Facing> getBack(@NotNull Instance instance, @NotNull BlockPosition blockPosition) { - return this.getProperties(instance, blockPosition.clone().add(this.back)); + public Pair<@Nullable Shape, @Nullable Facing> getBack(@NotNull Instance instance, @NotNull Point blockPosition) { + return this.getProperties(instance, blockPosition.add(this.back)); } @NotNull - private Pair<@Nullable Shape, @Nullable Facing> getProperties(@NotNull Instance instance, @NotNull BlockPosition blockPosition) { + private Pair<@Nullable Shape, @Nullable Facing> getProperties(@NotNull Instance instance, @NotNull Point blockPosition) { Block block = instance.getBlock(blockPosition); if (block.isAir()) { return Pair.of(null, null); diff --git a/src/main/java/net/minestom/server/item/metadata/CompassMeta.java b/src/main/java/net/minestom/server/item/metadata/CompassMeta.java index 2393fbe90..db7e004b0 100644 --- a/src/main/java/net/minestom/server/item/metadata/CompassMeta.java +++ b/src/main/java/net/minestom/server/item/metadata/CompassMeta.java @@ -1,8 +1,9 @@ package net.minestom.server.item.metadata; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.item.ItemMeta; import net.minestom.server.item.ItemMetaBuilder; -import net.minestom.server.utils.Position; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jglrxavpok.hephaistos.nbt.NBTCompound; @@ -13,12 +14,12 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider { if (lodestonePosition != null) { NBTCompound posCompound = new NBTCompound(); - posCompound.setInt("X", (int) lodestonePosition.getX()); - posCompound.setInt("Y", (int) lodestonePosition.getY()); - posCompound.setInt("Z", (int) lodestonePosition.getZ()); + posCompound.setInt("X", lodestonePosition.blockX()); + posCompound.setInt("Y", lodestonePosition.blockY()); + posCompound.setInt("Z", lodestonePosition.blockZ()); compound.set("LodestonePos", posCompound); } else { compound.removeTag("LodestonePos"); @@ -99,7 +100,7 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider 0) { - final BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ); + final var blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ); resultNbt.setString("id", handler.getNamespaceId().asString()) - .setInt("x", blockPosition.getX()) - .setInt("y", blockPosition.getY()) - .setInt("z", blockPosition.getZ()); + .setInt("x", blockPosition.blockX()) + .setInt("y", blockPosition.blockY()) + .setInt("z", blockPosition.blockZ()); compounds.add(resultNbt); } } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SculkVibrationSignal.java b/src/main/java/net/minestom/server/network/packet/server/play/SculkVibrationSignal.java index 7c593fadc..7a0eff331 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SculkVibrationSignal.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SculkVibrationSignal.java @@ -1,5 +1,6 @@ package net.minestom.server.network.packet.server.play; +import net.minestom.server.coordinate.Point; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.utils.BlockPosition; @@ -9,7 +10,7 @@ import org.jetbrains.annotations.NotNull; public class SculkVibrationSignal implements ServerPacket { - public BlockPosition position; + public Point position; public String destinationIdentifier; // TODO 'varies' destination public int arrivalTicks; diff --git a/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java b/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java index 14a3b3f47..a92028dda 100644 --- a/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java +++ b/src/main/java/net/minestom/server/utils/chunk/ChunkUtils.java @@ -1,11 +1,12 @@ package net.minestom.server.utils.chunk; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Instance; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.callback.OptionalCallback; -import net.minestom.server.coordinate.Point; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -99,10 +100,6 @@ public final class ChunkUtils { return retrieve(instance, originChunk, position.x(), position.z()); } - public static Chunk retrieve(Instance instance, Chunk originChunk, BlockPosition blockPosition) { - return retrieve(instance, originChunk, blockPosition.getX(), blockPosition.getZ()); - } - /** * @param xz the instance coordinate to convert * @return the chunk X or Z based on the argument @@ -231,12 +228,11 @@ public final class ChunkUtils { * @param chunkZ the chunk Z * @return the instance position of the block located in {@code index} */ - @NotNull - public static BlockPosition getBlockPosition(int index, int chunkX, int chunkZ) { + public static @NotNull Point getBlockPosition(int index, int chunkX, int chunkZ) { final int x = blockIndexToPositionX(index, chunkX); final int y = blockIndexToPositionY(index); final int z = blockIndexToPositionZ(index, chunkZ); - return new BlockPosition(x, y, z); + return new Vec(x, y, z); } /** diff --git a/src/main/java/net/minestom/server/utils/entity/EntityFinder.java b/src/main/java/net/minestom/server/utils/entity/EntityFinder.java index 301656def..2a2c4f1b7 100644 --- a/src/main/java/net/minestom/server/utils/entity/EntityFinder.java +++ b/src/main/java/net/minestom/server/utils/entity/EntityFinder.java @@ -4,6 +4,8 @@ import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import net.minestom.server.MinecraftServer; import net.minestom.server.command.CommandSender; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.GameMode; @@ -33,7 +35,7 @@ public class EntityFinder { private EntitySort entitySort = EntitySort.ARBITRARY; // Position - private Position startPosition = new Position(); + private Point startPosition = Vec.ZERO; private Float dx, dy, dz; private IntRange distance; @@ -159,17 +161,17 @@ public class EntityFinder { final var entityPosition = entity.getPosition(); if (dx != null && !MathUtils.isBetweenUnordered( entityPosition.x(), - startPosition.getX(), dx)) + startPosition.x(), dx)) return false; if (dy != null && !MathUtils.isBetweenUnordered( entityPosition.y(), - startPosition.getY(), dy)) + startPosition.y(), dy)) return false; if (dz != null && !MathUtils.isBetweenUnordered( entityPosition.z(), - startPosition.getZ(), dz)) + startPosition.z(), dz)) return false; return true; @@ -337,7 +339,7 @@ public class EntityFinder { @NotNull private static List findTarget(@Nullable Instance instance, @NotNull TargetSelector targetSelector, - @NotNull Position startPosition, @Nullable Entity self) { + @NotNull Point startPosition, @Nullable Entity self) { if (targetSelector == TargetSelector.NEAREST_PLAYER) { Entity entity = null; diff --git a/src/test/java/demo/generator/NoiseTestGenerator.java b/src/test/java/demo/generator/NoiseTestGenerator.java index 757478774..c12d48303 100644 --- a/src/test/java/demo/generator/NoiseTestGenerator.java +++ b/src/test/java/demo/generator/NoiseTestGenerator.java @@ -3,12 +3,12 @@ package demo.generator; import de.articdive.jnoise.JNoise; import de.articdive.jnoise.interpolation.InterpolationType; import net.minestom.server.MinecraftServer; +import net.minestom.server.coordinate.Vec; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.ChunkGenerator; import net.minestom.server.instance.ChunkPopulator; import net.minestom.server.instance.batch.ChunkBatch; import net.minestom.server.instance.block.Block; -import net.minestom.server.utils.BlockPosition; import net.minestom.server.world.biomes.Biome; import org.jetbrains.annotations.NotNull; @@ -165,7 +165,7 @@ public class NoiseTestGenerator implements ChunkGenerator { for (int j = -2; j < 18; j++) { if (jNoise2.getNoise(i + chunk.getChunkX() * 16, j + chunk.getChunkZ() * 16) > 0.75) { int y = getHeight(i + chunk.getChunkX() * 16, j + chunk.getChunkZ() * 16); - tree.build(batch, new BlockPosition(i, y, j)); + tree.build(batch, new Vec(i, y, j)); } } } diff --git a/src/test/java/demo/generator/Structure.java b/src/test/java/demo/generator/Structure.java index 6403676d5..68fd05d35 100644 --- a/src/test/java/demo/generator/Structure.java +++ b/src/test/java/demo/generator/Structure.java @@ -1,29 +1,30 @@ package demo.generator; +import net.minestom.server.coordinate.Point; +import net.minestom.server.coordinate.Vec; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.batch.ChunkBatch; import net.minestom.server.instance.block.Block; -import net.minestom.server.utils.BlockPosition; import java.util.HashMap; import java.util.Map; public class Structure { - private final Map blocks = new HashMap<>(); + private final Map blocks = new HashMap<>(); - public void build(ChunkBatch batch, BlockPosition pos) { + public void build(ChunkBatch batch, Point pos) { blocks.forEach((bPos, block) -> { - if (bPos.getX() + pos.getX() >= Chunk.CHUNK_SIZE_X || bPos.getX() + pos.getX() < 0) + if (bPos.x() + pos.x() >= Chunk.CHUNK_SIZE_X || bPos.x() + pos.x() < 0) return; - if (bPos.getZ() + pos.getZ() >= Chunk.CHUNK_SIZE_Z || bPos.getZ() + pos.getZ() < 0) + if (bPos.z() + pos.z() >= Chunk.CHUNK_SIZE_Z || bPos.z() + pos.z() < 0) return; - batch.setBlock(bPos.clone().add(pos), block); + batch.setBlock(bPos.add(pos), block); }); } public void addBlock(Block block, int localX, int localY, int localZ) { - blocks.put(new BlockPosition(localX, localY, localZ), block); + blocks.put(new Vec(localX, localY, localZ), block); } } diff --git a/src/test/java/improveextensions/unloadcallbacks/UnloadCallbacksExtension.java b/src/test/java/improveextensions/unloadcallbacks/UnloadCallbacksExtension.java index a2a74fcb3..d4a34a24a 100644 --- a/src/test/java/improveextensions/unloadcallbacks/UnloadCallbacksExtension.java +++ b/src/test/java/improveextensions/unloadcallbacks/UnloadCallbacksExtension.java @@ -1,6 +1,7 @@ package improveextensions.unloadcallbacks; import net.minestom.server.MinecraftServer; +import net.minestom.server.coordinate.Vec; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.EntityType; import net.minestom.server.event.EventCallback; @@ -10,7 +11,6 @@ import net.minestom.server.event.instance.InstanceTickEvent; import net.minestom.server.extensions.Extension; import net.minestom.server.extras.selfmodification.MinestomRootClassLoader; import net.minestom.server.instance.Instance; -import net.minestom.server.utils.Position; import net.minestom.server.utils.time.TimeUnit; import org.junit.jupiter.api.Assertions; import org.opentest4j.AssertionFailedError; @@ -50,7 +50,7 @@ public class UnloadCallbacksExtension extends Extension { zombie.addEventCallback(EntityTickEvent.class, e -> { zombieTicked = true; }); - zombie.setInstance(instance, new Position(8, 64, 8) /* middle of chunk */); + zombie.setInstance(instance, new Vec(8, 64, 8) /* middle of chunk */); // this callback will be cancelled MinecraftServer.getSchedulerManager().buildTask(() -> {