mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Remove most Position/BlockPosition usage
This commit is contained in:
parent
90ce845cdb
commit
45d7420397
@ -2,6 +2,7 @@ package net.minestom.demo.largeframebuffers;
|
|||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.entity.GameMode;
|
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.LargeGraphics2DFramebuffer;
|
||||||
import net.minestom.server.map.framebuffers.MapColorRenderer;
|
import net.minestom.server.map.framebuffers.MapColorRenderer;
|
||||||
import net.minestom.server.network.packet.server.play.MapDataPacket;
|
import net.minestom.server.network.packet.server.play.MapDataPacket;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -86,8 +86,7 @@ public class Demo {
|
|||||||
|
|
||||||
itemFrameMeta.setNotifyAboutChanges(true);
|
itemFrameMeta.setNotifyAboutChanges(true);
|
||||||
|
|
||||||
itemFrame.setInstance(instance, new Position(x, y, z));
|
itemFrame.setInstance(instance, new Pos(x, y, z, 180, 0));
|
||||||
itemFrame.getPosition().setYaw(180f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupMaps(Instance instance, int mapIDStart, int zCoordinate) {
|
private static void setupMaps(Instance instance, int mapIDStart, int zCoordinate) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.demo.largeframebuffers;
|
package net.minestom.demo.largeframebuffers;
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
import net.minestom.server.event.player.PlayerLoginEvent;
|
import net.minestom.server.event.player.PlayerLoginEvent;
|
||||||
import net.minestom.server.event.player.PlayerSpawnEvent;
|
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.batch.ChunkBatch;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.network.ConnectionManager;
|
import net.minestom.server.network.ConnectionManager;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import net.minestom.server.world.biomes.Biome;
|
import net.minestom.server.world.biomes.Biome;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -35,12 +35,12 @@ public class MainDemo {
|
|||||||
// Set the spawning instance
|
// Set the spawning instance
|
||||||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||||
event.setSpawningInstance(instanceContainer);
|
event.setSpawningInstance(instanceContainer);
|
||||||
player.setRespawnPoint(new Position(0, 45, 0));
|
player.setRespawnPoint(new Pos(0, 45, 0));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Teleport the player at spawn
|
// Teleport the player at spawn
|
||||||
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
||||||
player.teleport(new Position(0, 45, 0));
|
player.teleport(new Pos(0, 45, 0));
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package net.minestom.server.collision;
|
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.Point;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
|
import net.minestom.server.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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
|
* @param blockPosition the position to check
|
||||||
* @return true if the bounding box intersects with the position, false otherwise
|
* @return true if the bounding box intersects with the position, false otherwise
|
||||||
|
@ -4,13 +4,12 @@ import net.minestom.server.command.builder.NodeMaker;
|
|||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
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.StringUtils;
|
||||||
import net.minestom.server.utils.location.RelativeVec;
|
import net.minestom.server.utils.location.RelativeVec;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.
|
||||||
* <p>
|
* <p>
|
||||||
* Example: 5 ~ -3
|
* Example: 5 ~ -3
|
||||||
*/
|
*/
|
||||||
|
@ -46,10 +46,6 @@ public final class Pos implements Point {
|
|||||||
return new Pos(point.x(), point.y(), point.z());
|
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)
|
@Contract(pure = true)
|
||||||
public @NotNull Pos withCoord(double x, double y, double z) {
|
public @NotNull Pos withCoord(double x, double y, double z) {
|
||||||
return new Pos(x, y, z, yaw, pitch);
|
return new Pos(x, y, z, yaw, pitch);
|
||||||
|
@ -40,7 +40,6 @@ import net.minestom.server.potion.TimedPotion;
|
|||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
import net.minestom.server.tag.TagHandler;
|
import net.minestom.server.tag.TagHandler;
|
||||||
import net.minestom.server.thread.ThreadProvider;
|
import net.minestom.server.thread.ThreadProvider;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import net.minestom.server.utils.callback.OptionalCallback;
|
import net.minestom.server.utils.callback.OptionalCallback;
|
||||||
import net.minestom.server.utils.chunk.ChunkCallback;
|
import net.minestom.server.utils.chunk.ChunkCallback;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||||
@ -874,10 +873,6 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
setInstance(instance, Pos.fromPoint(spawnPosition));
|
setInstance(instance, Pos.fromPoint(spawnPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInstance(@NotNull Instance instance, @NotNull Position spawnPosition) {
|
|
||||||
setInstance(instance, Pos.fromPosition(spawnPosition));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the entity instance.
|
* Changes the entity instance.
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,7 @@ package net.minestom.server.entity;
|
|||||||
|
|
||||||
import com.extollit.gaming.ai.path.HydrazinePathFinder;
|
import com.extollit.gaming.ai.path.HydrazinePathFinder;
|
||||||
import net.minestom.server.attribute.Attribute;
|
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.EntityAI;
|
||||||
import net.minestom.server.entity.ai.EntityAIGroup;
|
import net.minestom.server.entity.ai.EntityAIGroup;
|
||||||
import net.minestom.server.entity.pathfinding.NavigableEntity;
|
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.EventDispatcher;
|
||||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -55,7 +55,7 @@ public class EntityCreature extends LivingEntity implements NavigableEntity, Ent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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()));
|
this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace()));
|
||||||
|
|
||||||
super.setInstance(instance, spawnPosition);
|
super.setInstance(instance, spawnPosition);
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.metadata.ObjectDataProvider;
|
import net.minestom.server.entity.metadata.ObjectDataProvider;
|
||||||
import net.minestom.server.entity.metadata.other.ExperienceOrbMeta;
|
import net.minestom.server.entity.metadata.other.ExperienceOrbMeta;
|
||||||
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.play.*;
|
import net.minestom.server.network.packet.server.play.*;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.Vector;
|
|
||||||
|
|
||||||
public enum EntitySpawnType {
|
public enum EntitySpawnType {
|
||||||
BASE {
|
BASE {
|
||||||
@ -78,7 +77,7 @@ public enum EntitySpawnType {
|
|||||||
if (entity.getEntityMeta() instanceof PaintingMeta) {
|
if (entity.getEntityMeta() instanceof PaintingMeta) {
|
||||||
PaintingMeta paintingMeta = (PaintingMeta) entity.getEntityMeta();
|
PaintingMeta paintingMeta = (PaintingMeta) entity.getEntityMeta();
|
||||||
packet.motive = paintingMeta.getMotive().ordinal();
|
packet.motive = paintingMeta.getMotive().ordinal();
|
||||||
packet.position = new BlockPosition(
|
packet.position = new Vec(
|
||||||
Math.max(0, (paintingMeta.getMotive().getWidth() >> 1) - 1),
|
Math.max(0, (paintingMeta.getMotive().getWidth() >> 1) - 1),
|
||||||
paintingMeta.getMotive().getHeight() >> 1,
|
paintingMeta.getMotive().getHeight() >> 1,
|
||||||
0
|
0
|
||||||
@ -98,12 +97,12 @@ public enum EntitySpawnType {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
packet.position = new BlockPosition(0, 0, 0);
|
packet.position = Vec.ZERO;
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public abstract ServerPacket getSpawnPacket(Entity entity);
|
public abstract ServerPacket getSpawnPacket(Entity entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import net.minestom.server.attribute.Attribute;
|
|||||||
import net.minestom.server.attribute.AttributeInstance;
|
import net.minestom.server.attribute.AttributeInstance;
|
||||||
import net.minestom.server.attribute.Attributes;
|
import net.minestom.server.attribute.Attributes;
|
||||||
import net.minestom.server.collision.BoundingBox;
|
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.damage.DamageType;
|
||||||
import net.minestom.server.entity.metadata.LivingEntityMeta;
|
import net.minestom.server.entity.metadata.LivingEntityMeta;
|
||||||
import net.minestom.server.event.EventDispatcher;
|
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.network.player.PlayerConnection;
|
||||||
import net.minestom.server.scoreboard.Team;
|
import net.minestom.server.scoreboard.Team;
|
||||||
import net.minestom.server.sound.SoundEvent;
|
import net.minestom.server.sound.SoundEvent;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.block.BlockIterator;
|
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.Cooldown;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
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
|
* @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<Point> getLineOfSight(int maxDistance) {
|
public List<Point> getLineOfSight(int maxDistance) {
|
||||||
List<Point> blocks = new ArrayList<>();
|
List<Point> 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
|
* @param maxDistance The max distance to scan before returning null
|
||||||
* @return The block position targeted by this entity, null if non are found
|
* @return The block position targeted by this entity, null if non are found
|
||||||
|
@ -4,16 +4,15 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.chat.ColoredText;
|
import net.minestom.server.chat.ColoredText;
|
||||||
import net.minestom.server.chat.JsonMessage;
|
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.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.server.play.EntityMetaDataPacket;
|
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.Direction;
|
||||||
import net.minestom.server.utils.Vector;
|
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import net.minestom.server.utils.binary.Readable;
|
import net.minestom.server.utils.binary.Readable;
|
||||||
import net.minestom.server.utils.binary.Writeable;
|
import net.minestom.server.utils.binary.Writeable;
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
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);
|
return new Value<>(TYPE_BOOLEAN, value, writer -> writer.writeBoolean(value), BinaryReader::readBoolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Value<Vector> Rotation(@NotNull Vector value) {
|
public static Value<Point> Rotation(@NotNull Point value) {
|
||||||
return new Value<>(TYPE_ROTATION, value, writer -> {
|
return new Value<>(TYPE_ROTATION, value, writer -> {
|
||||||
writer.writeFloat((float) value.getX());
|
writer.writeFloat((float) value.x());
|
||||||
writer.writeFloat((float) value.getY());
|
writer.writeFloat((float) value.y());
|
||||||
writer.writeFloat((float) value.getZ());
|
writer.writeFloat((float) value.z());
|
||||||
}, reader -> new Vector(reader.readFloat(), reader.readFloat(), reader.readFloat()));
|
}, reader -> new Vec(reader.readFloat(), reader.readFloat(), reader.readFloat()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Value<Point> Position(@NotNull Point value) {
|
public static Value<Point> Position(@NotNull Point value) {
|
||||||
@ -339,7 +338,7 @@ public class Metadata {
|
|||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
return (Value<T>) String("");
|
return (Value<T>) String("");
|
||||||
case TYPE_CHAT:
|
case TYPE_CHAT:
|
||||||
return (Value<T>) Chat(ColoredText.of(""));
|
return (Value<T>) Chat(Component.empty());
|
||||||
case TYPE_OPTCHAT:
|
case TYPE_OPTCHAT:
|
||||||
return (Value<T>) OptChat((Component) null);
|
return (Value<T>) OptChat((Component) null);
|
||||||
case TYPE_SLOT:
|
case TYPE_SLOT:
|
||||||
@ -347,9 +346,9 @@ public class Metadata {
|
|||||||
case TYPE_BOOLEAN:
|
case TYPE_BOOLEAN:
|
||||||
return (Value<T>) Boolean(false);
|
return (Value<T>) Boolean(false);
|
||||||
case TYPE_ROTATION:
|
case TYPE_ROTATION:
|
||||||
return (Value<T>) Rotation(new Vector());
|
return (Value<T>) Rotation(Vec.ZERO);
|
||||||
case TYPE_POSITION:
|
case TYPE_POSITION:
|
||||||
return (Value<T>) Position(new BlockPosition(0, 0, 0));
|
return (Value<T>) Position(Vec.ZERO);
|
||||||
case TYPE_OPTPOSITION:
|
case TYPE_OPTPOSITION:
|
||||||
return (Value<T>) OptPosition(null);
|
return (Value<T>) OptPosition(null);
|
||||||
case TYPE_DIRECTION:
|
case TYPE_DIRECTION:
|
||||||
|
@ -26,6 +26,9 @@ import net.minestom.server.chat.JsonMessage;
|
|||||||
import net.minestom.server.collision.BoundingBox;
|
import net.minestom.server.collision.BoundingBox;
|
||||||
import net.minestom.server.command.CommandManager;
|
import net.minestom.server.command.CommandManager;
|
||||||
import net.minestom.server.command.CommandSender;
|
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.effects.Effects;
|
||||||
import net.minestom.server.entity.damage.DamageType;
|
import net.minestom.server.entity.damage.DamageType;
|
||||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
|
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.*;
|
||||||
import net.minestom.server.utils.chunk.ChunkCallback;
|
import net.minestom.server.utils.chunk.ChunkCallback;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
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.entity.EntityUtils;
|
||||||
import net.minestom.server.utils.identity.NamedAndIdentified;
|
import net.minestom.server.utils.identity.NamedAndIdentified;
|
||||||
import net.minestom.server.utils.instance.InstanceUtils;
|
import net.minestom.server.utils.instance.InstanceUtils;
|
||||||
@ -700,17 +701,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
playerConnection.sendPacket(soundEffectPacket);
|
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).
|
* 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);
|
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).
|
* 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) {
|
public void playEffect(@NotNull Effects effect, int x, int y, int z, int data, boolean disableRelativeVolume) {
|
||||||
EffectPacket packet = new EffectPacket();
|
EffectPacket packet = new EffectPacket();
|
||||||
packet.effectId = effect.getId();
|
packet.effectId = effect.getId();
|
||||||
packet.position = new BlockPosition(x, y, z);
|
packet.position = new Vec(x, y, z);
|
||||||
packet.data = data;
|
packet.data = data;
|
||||||
packet.disableRelativeVolume = disableRelativeVolume;
|
packet.disableRelativeVolume = disableRelativeVolume;
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.entity.fakeplayer;
|
package net.minestom.server.entity.fakeplayer;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.instance.block.BlockFace;
|
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.KeepAlivePacket;
|
||||||
import net.minestom.server.network.packet.server.play.PlayerPositionAndLookPacket;
|
import net.minestom.server.network.packet.server.play.PlayerPositionAndLookPacket;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.inventory.PlayerInventoryUtils;
|
import net.minestom.server.utils.inventory.PlayerInventoryUtils;
|
||||||
import net.minestom.server.utils.validate.Check;
|
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 blockPosition The position of the block to be excavated.
|
||||||
* @param blockFace From where the block is struck.
|
* @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();
|
ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket();
|
||||||
playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.STARTED_DIGGING;
|
playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.STARTED_DIGGING;
|
||||||
playerDiggingPacket.blockPosition = blockPosition;
|
playerDiggingPacket.blockPosition = blockPosition;
|
||||||
@ -193,7 +193,7 @@ public class FakePlayerController {
|
|||||||
* @param blockPosition The position of the block to be excavated.
|
* @param blockPosition The position of the block to be excavated.
|
||||||
* @param blockFace From where the block is struck.
|
* @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();
|
ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket();
|
||||||
playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.CANCELLED_DIGGING;
|
playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.CANCELLED_DIGGING;
|
||||||
playerDiggingPacket.blockPosition = blockPosition;
|
playerDiggingPacket.blockPosition = blockPosition;
|
||||||
@ -207,7 +207,7 @@ public class FakePlayerController {
|
|||||||
* @param blockPosition The position of the block to be excavated.
|
* @param blockPosition The position of the block to be excavated.
|
||||||
* @param blockFace From where the block is struck.
|
* @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();
|
ClientPlayerDiggingPacket playerDiggingPacket = new ClientPlayerDiggingPacket();
|
||||||
playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.FINISHED_DIGGING;
|
playerDiggingPacket.status = ClientPlayerDiggingPacket.Status.FINISHED_DIGGING;
|
||||||
playerDiggingPacket.blockPosition = blockPosition;
|
playerDiggingPacket.blockPosition = blockPosition;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.minestom.server.entity.metadata;
|
package net.minestom.server.entity.metadata;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.Metadata;
|
import net.minestom.server.entity.Metadata;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -85,11 +85,11 @@ public class LivingEntityMeta extends EntityMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BlockPosition getBedInWhichSleepingPosition() {
|
public Point getBedInWhichSleepingPosition() {
|
||||||
return super.metadata.getIndex(OFFSET + 6, null);
|
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));
|
super.metadata.setIndex(OFFSET + 6, Metadata.OptPosition(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package net.minestom.server.entity.metadata.animal;
|
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.Entity;
|
||||||
import net.minestom.server.entity.Metadata;
|
import net.minestom.server.entity.Metadata;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class TurtleMeta extends AnimalMeta {
|
public class TurtleMeta extends AnimalMeta {
|
||||||
@ -13,12 +14,11 @@ public class TurtleMeta extends AnimalMeta {
|
|||||||
super(entity, metadata);
|
super(entity, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public @NotNull Point getHomePosition() {
|
||||||
public BlockPosition getHomePosition() {
|
return super.metadata.getIndex(OFFSET, Vec.ZERO);
|
||||||
return super.metadata.getIndex(OFFSET, new BlockPosition(0, 0, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockPosition(@NotNull BlockPosition value) {
|
public void setBlockPosition(@NotNull Point value) {
|
||||||
super.metadata.setIndex(OFFSET, Metadata.Position(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));
|
super.metadata.setIndex(OFFSET + 2, Metadata.Boolean(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public @NotNull Point getTravelPosition() {
|
||||||
public BlockPosition getTravelPosition() {
|
return super.metadata.getIndex(OFFSET + 3, Vec.ZERO);
|
||||||
return super.metadata.getIndex(OFFSET + 3, new BlockPosition(0, 0, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTravelPosition(@NotNull BlockPosition value) {
|
public void setTravelPosition(@NotNull Point value) {
|
||||||
super.metadata.setIndex(OFFSET + 3, Metadata.Position(value));
|
super.metadata.setIndex(OFFSET + 3, Metadata.Position(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.minestom.server.entity.metadata.golem;
|
package net.minestom.server.entity.metadata.golem;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.Metadata;
|
import net.minestom.server.entity.Metadata;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.Direction;
|
import net.minestom.server.utils.Direction;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -22,11 +22,11 @@ public class ShulkerMeta extends AbstractGolemMeta {
|
|||||||
super.metadata.setIndex(OFFSET, Metadata.Direction(value));
|
super.metadata.setIndex(OFFSET, Metadata.Direction(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPosition getAttachmentPosition() {
|
public Point getAttachmentPosition() {
|
||||||
return super.metadata.getIndex(OFFSET + 1, null);
|
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));
|
super.metadata.setIndex(OFFSET + 1, Metadata.OptPosition(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.minestom.server.entity.metadata.other;
|
package net.minestom.server.entity.metadata.other;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.Metadata;
|
import net.minestom.server.entity.Metadata;
|
||||||
import net.minestom.server.entity.metadata.EntityMeta;
|
import net.minestom.server.entity.metadata.EntityMeta;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -15,12 +15,11 @@ public class EndCrystalMeta extends EntityMeta {
|
|||||||
super(entity, metadata);
|
super(entity, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public @Nullable Point getBeamTarget() {
|
||||||
public BlockPosition getBeamTarget() {
|
|
||||||
return super.metadata.getIndex(OFFSET, null);
|
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));
|
super.metadata.setIndex(OFFSET, Metadata.OptPosition(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package net.minestom.server.entity.metadata.other;
|
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.Entity;
|
||||||
import net.minestom.server.entity.Metadata;
|
import net.minestom.server.entity.Metadata;
|
||||||
import net.minestom.server.entity.metadata.EntityMeta;
|
import net.minestom.server.entity.metadata.EntityMeta;
|
||||||
import net.minestom.server.entity.metadata.ObjectDataProvider;
|
import net.minestom.server.entity.metadata.ObjectDataProvider;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class FallingBlockMeta extends EntityMeta implements ObjectDataProvider {
|
public class FallingBlockMeta extends EntityMeta implements ObjectDataProvider {
|
||||||
@ -18,11 +19,11 @@ public class FallingBlockMeta extends EntityMeta implements ObjectDataProvider {
|
|||||||
super(entity, metadata);
|
super(entity, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockPosition getSpawnPosition() {
|
public Point getSpawnPosition() {
|
||||||
return super.metadata.getIndex(OFFSET, new BlockPosition(0, 0, 0));
|
return super.metadata.getIndex(OFFSET, Vec.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpawnPosition(BlockPosition value) {
|
public void setSpawnPosition(Point value) {
|
||||||
super.metadata.setIndex(OFFSET, Metadata.Position(value));
|
super.metadata.setIndex(OFFSET, Metadata.Position(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.minestom.server.entity.metadata.water;
|
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.Entity;
|
||||||
import net.minestom.server.entity.Metadata;
|
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.NotNull;
|
||||||
|
|
||||||
public class DolphinMeta extends WaterAnimalMeta {
|
public class DolphinMeta extends WaterAnimalMeta {
|
||||||
@ -15,11 +15,11 @@ public class DolphinMeta extends WaterAnimalMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public BlockPosition getTreasurePosition() {
|
public Point getTreasurePosition() {
|
||||||
return super.metadata.getIndex(OFFSET, new BlockPosition(0, 0, 0));
|
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));
|
super.metadata.setIndex(OFFSET, Metadata.Position(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ import com.extollit.gaming.ai.path.model.IPathingEntity;
|
|||||||
import com.extollit.gaming.ai.path.model.Passibility;
|
import com.extollit.gaming.ai.path.model.Passibility;
|
||||||
import com.extollit.linalg.immutable.Vec3d;
|
import com.extollit.linalg.immutable.Vec3d;
|
||||||
import net.minestom.server.attribute.Attribute;
|
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.Entity;
|
||||||
import net.minestom.server.entity.LivingEntity;
|
import net.minestom.server.entity.LivingEntity;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PFPathingEntity implements IPathingEntity {
|
public class PFPathingEntity implements IPathingEntity {
|
||||||
@ -194,8 +194,7 @@ public class PFPathingEntity implements IPathingEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void moveTo(Vec3d position, Passibility passibility, Gravitation gravitation) {
|
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();
|
final double entityY = entity.getPosition().y();
|
||||||
if (entityY < targetPosition.y()) {
|
if (entityY < targetPosition.y()) {
|
||||||
this.navigator.jump(1);
|
this.navigator.jump(1);
|
||||||
|
@ -9,7 +9,7 @@ import net.minestom.server.coordinate.Point;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public class EntityShootEvent implements EntityEvent, CancellableEvent {
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package net.minestom.server.instance;
|
|||||||
|
|
||||||
import net.minestom.server.Tickable;
|
import net.minestom.server.Tickable;
|
||||||
import net.minestom.server.Viewable;
|
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.Data;
|
||||||
import net.minestom.server.data.DataContainer;
|
import net.minestom.server.data.DataContainer;
|
||||||
import net.minestom.server.entity.Player;
|
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.ChunkDataPacket;
|
||||||
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import net.minestom.server.utils.ArrayUtils;
|
|
||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
import net.minestom.server.tag.TagHandler;
|
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.Position;
|
||||||
import net.minestom.server.utils.chunk.ChunkSupplier;
|
import net.minestom.server.utils.chunk.ChunkSupplier;
|
||||||
import net.minestom.server.world.biomes.Biome;
|
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
|
* @return the position of this chunk
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull Point toPosition() {
|
||||||
public Position toPosition() {
|
return new Vec(CHUNK_SIZE_Z * getChunkX(), 0, CHUNK_SIZE_Z * getChunkZ());
|
||||||
return new Position(CHUNK_SIZE_Z * getChunkX(), 0, CHUNK_SIZE_Z * getChunkZ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,14 +2,12 @@ package net.minestom.server.instance;
|
|||||||
|
|
||||||
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
|
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.pathfinding.PFBlock;
|
import net.minestom.server.entity.pathfinding.PFBlock;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.instance.block.BlockHandler;
|
import net.minestom.server.instance.block.BlockHandler;
|
||||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
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.chunk.ChunkUtils;
|
||||||
import net.minestom.server.utils.time.Cooldown;
|
|
||||||
import net.minestom.server.utils.validate.Check;
|
|
||||||
import net.minestom.server.world.biomes.Biome;
|
import net.minestom.server.world.biomes.Biome;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -17,7 +15,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
|||||||
|
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
@ -99,7 +96,7 @@ public class DynamicChunk extends Chunk {
|
|||||||
final int x = ChunkUtils.blockIndexToChunkPositionX(index);
|
final int x = ChunkUtils.blockIndexToChunkPositionX(index);
|
||||||
final int y = ChunkUtils.blockIndexToChunkPositionY(index);
|
final int y = ChunkUtils.blockIndexToChunkPositionY(index);
|
||||||
final int z = ChunkUtils.blockIndexToChunkPositionZ(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);
|
final Block block = getBlock(blockPosition);
|
||||||
entry.getValue().tick(new BlockHandler.Tick(block, instance, blockPosition));
|
entry.getValue().tick(new BlockHandler.Tick(block, instance, blockPosition));
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.minestom.server.instance;
|
package net.minestom.server.instance;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.network.packet.server.play.ExplosionPacket;
|
import net.minestom.server.network.packet.server.play.ExplosionPacket;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.PacketUtils;
|
import net.minestom.server.utils.PacketUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public abstract class Explosion {
|
|||||||
* @param instance instance to perform this explosion in
|
* @param instance instance to perform this explosion in
|
||||||
* @return list of blocks that will be broken.
|
* @return list of blocks that will be broken.
|
||||||
*/
|
*/
|
||||||
protected abstract List<BlockPosition> prepare(Instance instance);
|
protected abstract List<Point> prepare(Instance instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the explosion and send the corresponding packet
|
* Performs the explosion and send the corresponding packet
|
||||||
@ -56,7 +56,7 @@ public abstract class Explosion {
|
|||||||
* @param instance instance to perform this explosion in
|
* @param instance instance to perform this explosion in
|
||||||
*/
|
*/
|
||||||
public void apply(@NotNull Instance instance) {
|
public void apply(@NotNull Instance instance) {
|
||||||
List<BlockPosition> blocks = prepare(instance);
|
List<Point> blocks = prepare(instance);
|
||||||
ExplosionPacket packet = new ExplosionPacket();
|
ExplosionPacket packet = new ExplosionPacket();
|
||||||
packet.x = getCenterX();
|
packet.x = getCenterX();
|
||||||
packet.y = getCenterY();
|
packet.y = getCenterY();
|
||||||
@ -68,11 +68,11 @@ public abstract class Explosion {
|
|||||||
|
|
||||||
packet.records = new byte[3 * blocks.size()];
|
packet.records = new byte[3 * blocks.size()];
|
||||||
for (int i = 0; i < blocks.size(); i++) {
|
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);
|
instance.setBlock(pos, Block.AIR);
|
||||||
final byte x = (byte) (pos.getX() - Math.floor(getCenterX()));
|
final byte x = (byte) (pos.x() - Math.floor(getCenterX()));
|
||||||
final byte y = (byte) (pos.getY() - Math.floor(getCenterY()));
|
final byte y = (byte) (pos.y() - Math.floor(getCenterY()));
|
||||||
final byte z = (byte) (pos.getZ() - Math.floor(getCenterZ()));
|
final byte z = (byte) (pos.z() - Math.floor(getCenterZ()));
|
||||||
packet.records[i * 3 + 0] = x;
|
packet.records[i * 3 + 0] = x;
|
||||||
packet.records[i * 3 + 1] = y;
|
packet.records[i * 3 + 1] = y;
|
||||||
packet.records[i * 3 + 2] = z;
|
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.
|
* 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.
|
* 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<BlockPosition> blocks, ExplosionPacket packet) {
|
protected void postExplosion(Instance instance, List<Point> blocks, ExplosionPacket packet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,6 +106,6 @@ public abstract class Explosion {
|
|||||||
* @param instance the instance in which the explosion occurs
|
* @param instance the instance in which the explosion occurs
|
||||||
* @param blocks the block positions returned by prepare
|
* @param blocks the block positions returned by prepare
|
||||||
*/
|
*/
|
||||||
protected void postSend(Instance instance, List<BlockPosition> blocks) {
|
protected void postSend(Instance instance, List<Point> blocks) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import net.minestom.server.MinecraftServer;
|
|||||||
import net.minestom.server.Tickable;
|
import net.minestom.server.Tickable;
|
||||||
import net.minestom.server.UpdateManager;
|
import net.minestom.server.UpdateManager;
|
||||||
import net.minestom.server.adventure.audience.PacketGroupingAudience;
|
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.Data;
|
||||||
import net.minestom.server.data.DataContainer;
|
import net.minestom.server.data.DataContainer;
|
||||||
import net.minestom.server.entity.Entity;
|
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.Tag;
|
||||||
import net.minestom.server.tag.TagHandler;
|
import net.minestom.server.tag.TagHandler;
|
||||||
import net.minestom.server.thread.ThreadProvider;
|
import net.minestom.server.thread.ThreadProvider;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.PacketUtils;
|
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.ChunkCallback;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
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.entity.EntityUtils;
|
||||||
import net.minestom.server.utils.time.Cooldown;
|
import net.minestom.server.utils.time.Cooldown;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
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
|
* @param callback the optional callback to run when the chunk is loaded
|
||||||
*/
|
*/
|
||||||
public void loadChunk(@NotNull Point point, @Nullable ChunkCallback callback) {
|
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)
|
* 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)
|
* @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) {
|
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
|
* @param actionParam the action parameter, depends on the block
|
||||||
* @see <a href="https://wiki.vg/Protocol#Block_Action">BlockActionPacket</a> for the action id & param
|
* @see <a href="https://wiki.vg/Protocol#Block_Action">BlockActionPacket</a> 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);
|
final Block block = getBlock(blockPosition);
|
||||||
|
|
||||||
BlockActionPacket blockActionPacket = new BlockActionPacket();
|
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 x the X position
|
||||||
* @param z the Z position
|
* @param z the Z position
|
||||||
* @return the chunk at the given position, null if not loaded
|
* @return the chunk at the given position, null if not loaded
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable Chunk getChunkAt(double x, double z) {
|
||||||
public Chunk getChunkAt(double x, double z) {
|
|
||||||
final int chunkX = ChunkUtils.getChunkCoordinate(x);
|
final int chunkX = ChunkUtils.getChunkCoordinate(x);
|
||||||
final int chunkZ = ChunkUtils.getChunkCoordinate(z);
|
final int chunkZ = ChunkUtils.getChunkCoordinate(z);
|
||||||
return getChunk(chunkX, chunkZ);
|
return getChunk(chunkX, chunkZ);
|
||||||
@ -621,8 +618,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
|||||||
* @param point the chunk position
|
* @param point the chunk position
|
||||||
* @return the chunk at the given position, null if not loaded
|
* @return the chunk at the given position, null if not loaded
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable Chunk getChunkAt(@NotNull Point point) {
|
||||||
public Chunk getChunkAt(@NotNull Point point) {
|
|
||||||
return getChunkAt(point.x(), point.z());
|
return getChunkAt(point.x(), point.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.minestom.server.instance;
|
package net.minestom.server.instance;
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
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.Data;
|
||||||
import net.minestom.server.data.SerializableData;
|
import net.minestom.server.data.SerializableData;
|
||||||
import net.minestom.server.entity.Player;
|
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.ChunkCallback;
|
||||||
import net.minestom.server.utils.chunk.ChunkSupplier;
|
import net.minestom.server.utils.chunk.ChunkSupplier;
|
||||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import net.minestom.server.world.DimensionType;
|
import net.minestom.server.world.DimensionType;
|
||||||
import net.minestom.server.world.biomes.Biome;
|
import net.minestom.server.world.biomes.Biome;
|
||||||
@ -59,7 +60,7 @@ public class InstanceContainer extends Instance {
|
|||||||
protected final Set<Chunk> scheduledChunksToRemove = new HashSet<>();
|
protected final Set<Chunk> scheduledChunksToRemove = new HashSet<>();
|
||||||
|
|
||||||
private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
|
||||||
private final Map<BlockPosition, Block> currentlyChangingBlocks = new HashMap<>();
|
private final Map<Point, Block> currentlyChangingBlocks = new HashMap<>();
|
||||||
|
|
||||||
// the chunk loader, used when trying to load/save a chunk from another source
|
// the chunk loader, used when trying to load/save a chunk from another source
|
||||||
private IChunkLoader chunkLoader;
|
private IChunkLoader chunkLoader;
|
||||||
@ -137,7 +138,7 @@ public class InstanceContainer extends Instance {
|
|||||||
synchronized (chunk) {
|
synchronized (chunk) {
|
||||||
// Refresh the last block change time
|
// Refresh the last block change time
|
||||||
this.lastBlockChangeTime = System.currentTimeMillis();
|
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.
|
if (isAlreadyChanged(blockPosition, block)) { // do NOT change the block again.
|
||||||
// Avoids StackOverflowExceptions when onDestroy tries to destroy the block itself
|
// 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
|
// 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}.
|
||||||
* <p>
|
* <p>
|
||||||
* WARNING: this does not change the internal block data, this is strictly visual for the players.
|
* 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 blockPosition the block position
|
||||||
* @param block the new block
|
* @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()));
|
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);
|
currentlyChangingBlocks.put(blockPosition, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,7 +650,7 @@ public class InstanceContainer extends Instance {
|
|||||||
* @param block the block
|
* @param block the block
|
||||||
* @return true if the block changed since the last update
|
* @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);
|
final Block changedBlock = currentlyChangingBlocks.get(blockPosition);
|
||||||
if (changedBlock == null)
|
if (changedBlock == null)
|
||||||
return false;
|
return false;
|
||||||
@ -663,7 +664,7 @@ public class InstanceContainer extends Instance {
|
|||||||
* @param blockPosition the block position
|
* @param blockPosition the block position
|
||||||
* @return the modified block state id
|
* @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);
|
final BlockPlacementRule blockPlacementRule = BLOCK_MANAGER.getBlockPlacementRule(block);
|
||||||
if (blockPlacementRule != null) {
|
if (blockPlacementRule != null) {
|
||||||
return blockPlacementRule.blockUpdate(this, blockPosition, block);
|
return blockPlacementRule.blockUpdate(this, blockPosition, block);
|
||||||
@ -678,15 +679,15 @@ public class InstanceContainer extends Instance {
|
|||||||
*
|
*
|
||||||
* @param blockPosition the position of the modified block
|
* @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 offsetX = -1; offsetX < 2; offsetX++) {
|
||||||
for (int offsetY = -1; offsetY < 2; offsetY++) {
|
for (int offsetY = -1; offsetY < 2; offsetY++) {
|
||||||
for (int offsetZ = -1; offsetZ < 2; offsetZ++) {
|
for (int offsetZ = -1; offsetZ < 2; offsetZ++) {
|
||||||
if (offsetX == 0 && offsetY == 0 && offsetZ == 0)
|
if (offsetX == 0 && offsetY == 0 && offsetZ == 0)
|
||||||
continue;
|
continue;
|
||||||
final int neighborX = blockPosition.getX() + offsetX;
|
final int neighborX = blockPosition.blockX() + offsetX;
|
||||||
final int neighborY = blockPosition.getY() + offsetY;
|
final int neighborY = blockPosition.blockY() + offsetY;
|
||||||
final int neighborZ = blockPosition.getZ() + offsetZ;
|
final int neighborZ = blockPosition.blockZ() + offsetZ;
|
||||||
final Chunk chunk = getChunkAt(neighborX, neighborZ);
|
final Chunk chunk = getChunkAt(neighborX, neighborZ);
|
||||||
|
|
||||||
// Do not try to get neighbour in an unloaded chunk
|
// 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 Block neighborBlock = chunk.getBlock(neighborX, neighborY, neighborZ);
|
||||||
final BlockPlacementRule neighborBlockPlacementRule = BLOCK_MANAGER.getBlockPlacementRule(neighborBlock);
|
final BlockPlacementRule neighborBlockPlacementRule = BLOCK_MANAGER.getBlockPlacementRule(neighborBlock);
|
||||||
if (neighborBlockPlacementRule != null) {
|
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,
|
final Block newNeighborBlock = neighborBlockPlacementRule.blockUpdate(this,
|
||||||
neighborPosition, neighborBlock);
|
neighborPosition, neighborBlock);
|
||||||
if (neighborBlock != newNeighborBlock) {
|
if (neighborBlock != newNeighborBlock) {
|
||||||
|
@ -2,9 +2,9 @@ package net.minestom.server.instance.batch;
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -106,8 +106,8 @@ public class RelativeBlockBatch implements Batch<Runnable> {
|
|||||||
* @param callback The callback to be executed when the batch is applied
|
* @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}
|
* @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) {
|
public AbsoluteBlockBatch apply(@NotNull Instance instance, @NotNull Point position, @Nullable Runnable callback) {
|
||||||
return apply(instance, position.getX(), position.getY(), position.getZ(), callback);
|
return apply(instance, position.blockX(), position.blockY(), position.blockZ(), callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.instance.block.rule.vanilla;
|
package net.minestom.server.instance.block.rule.vanilla;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.Pair;
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
@ -51,26 +52,26 @@ public class StairsPlacementRule extends BlockPlacementRule {
|
|||||||
|
|
||||||
private enum Facing {
|
private enum Facing {
|
||||||
NORTH(
|
NORTH(
|
||||||
new BlockPosition(0, 0, 1),
|
new Vec(0, 0, 1),
|
||||||
new BlockPosition(0, 0, -1)
|
new Vec(0, 0, -1)
|
||||||
),
|
),
|
||||||
EAST(
|
EAST(
|
||||||
new BlockPosition(-1, 0, 0),
|
new Vec(-1, 0, 0),
|
||||||
new BlockPosition(1, 0, 0)
|
new Vec(1, 0, 0)
|
||||||
),
|
),
|
||||||
SOUTH(
|
SOUTH(
|
||||||
new BlockPosition(0, 0, -1),
|
new Vec(0, 0, -1),
|
||||||
new BlockPosition(0, 0, 1)
|
new Vec(0, 0, 1)
|
||||||
),
|
),
|
||||||
WEST(
|
WEST(
|
||||||
new BlockPosition(1, 0, 0),
|
new Vec(1, 0, 0),
|
||||||
new BlockPosition(-1, 0, 0)
|
new Vec(-1, 0, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
private final BlockPosition front;
|
private final Point front;
|
||||||
private final BlockPosition back;
|
private final Point back;
|
||||||
|
|
||||||
Facing(@NotNull BlockPosition front, @NotNull BlockPosition back) {
|
Facing(@NotNull Point front, @NotNull Point back) {
|
||||||
this.front = front;
|
this.front = front;
|
||||||
this.back = back;
|
this.back = back;
|
||||||
}
|
}
|
||||||
@ -83,12 +84,12 @@ public class StairsPlacementRule extends BlockPlacementRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Pair<@Nullable Shape, @Nullable Facing> getBack(@NotNull Instance instance, @NotNull BlockPosition blockPosition) {
|
public Pair<@Nullable Shape, @Nullable Facing> getBack(@NotNull Instance instance, @NotNull Point blockPosition) {
|
||||||
return this.getProperties(instance, blockPosition.clone().add(this.back));
|
return this.getProperties(instance, blockPosition.add(this.back));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
Block block = instance.getBlock(blockPosition);
|
||||||
if (block.isAir()) {
|
if (block.isAir()) {
|
||||||
return Pair.of(null, null);
|
return Pair.of(null, null);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package net.minestom.server.item.metadata;
|
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.ItemMeta;
|
||||||
import net.minestom.server.item.ItemMetaBuilder;
|
import net.minestom.server.item.ItemMetaBuilder;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
@ -13,12 +14,12 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
|
|||||||
|
|
||||||
private final boolean lodestoneTracked;
|
private final boolean lodestoneTracked;
|
||||||
private final String lodestoneDimension;
|
private final String lodestoneDimension;
|
||||||
private final Position lodestonePosition;
|
private final Point lodestonePosition;
|
||||||
|
|
||||||
protected CompassMeta(ItemMetaBuilder metaBuilder,
|
protected CompassMeta(ItemMetaBuilder metaBuilder,
|
||||||
boolean lodestoneTracked,
|
boolean lodestoneTracked,
|
||||||
@Nullable String lodestoneDimension,
|
@Nullable String lodestoneDimension,
|
||||||
@Nullable Position lodestonePosition) {
|
@Nullable Point lodestonePosition) {
|
||||||
super(metaBuilder);
|
super(metaBuilder);
|
||||||
this.lodestoneTracked = lodestoneTracked;
|
this.lodestoneTracked = lodestoneTracked;
|
||||||
this.lodestoneDimension = lodestoneDimension;
|
this.lodestoneDimension = lodestoneDimension;
|
||||||
@ -33,7 +34,7 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
|
|||||||
return lodestoneDimension;
|
return lodestoneDimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Position getLodestonePosition() {
|
public @Nullable Point getLodestonePosition() {
|
||||||
return lodestonePosition;
|
return lodestonePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
|
|||||||
|
|
||||||
private boolean lodestoneTracked;
|
private boolean lodestoneTracked;
|
||||||
private String lodestoneDimension;
|
private String lodestoneDimension;
|
||||||
private Position lodestonePosition;
|
private Point lodestonePosition;
|
||||||
|
|
||||||
public Builder lodestoneTracked(boolean lodestoneTracked) {
|
public Builder lodestoneTracked(boolean lodestoneTracked) {
|
||||||
this.lodestoneTracked = lodestoneTracked;
|
this.lodestoneTracked = lodestoneTracked;
|
||||||
@ -63,15 +64,15 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder lodestonePosition(@Nullable Position lodestonePosition) {
|
public Builder lodestonePosition(@Nullable Point lodestonePosition) {
|
||||||
this.lodestonePosition = lodestonePosition;
|
this.lodestonePosition = lodestonePosition;
|
||||||
|
|
||||||
mutateNbt(compound -> {
|
mutateNbt(compound -> {
|
||||||
if (lodestonePosition != null) {
|
if (lodestonePosition != null) {
|
||||||
NBTCompound posCompound = new NBTCompound();
|
NBTCompound posCompound = new NBTCompound();
|
||||||
posCompound.setInt("X", (int) lodestonePosition.getX());
|
posCompound.setInt("X", lodestonePosition.blockX());
|
||||||
posCompound.setInt("Y", (int) lodestonePosition.getY());
|
posCompound.setInt("Y", lodestonePosition.blockY());
|
||||||
posCompound.setInt("Z", (int) lodestonePosition.getZ());
|
posCompound.setInt("Z", lodestonePosition.blockZ());
|
||||||
compound.set("LodestonePos", posCompound);
|
compound.set("LodestonePos", posCompound);
|
||||||
} else {
|
} else {
|
||||||
compound.removeTag("LodestonePos");
|
compound.removeTag("LodestonePos");
|
||||||
@ -99,7 +100,7 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
|
|||||||
final int x = posCompound.getInt("X");
|
final int x = posCompound.getInt("X");
|
||||||
final int y = posCompound.getInt("Y");
|
final int y = posCompound.getInt("Y");
|
||||||
final int z = posCompound.getInt("Z");
|
final int z = posCompound.getInt("Z");
|
||||||
lodestonePosition(new Position(x, y, z));
|
lodestonePosition(new Vec(x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import net.minestom.server.instance.block.BlockHandler;
|
|||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import net.minestom.server.tag.Tag;
|
import net.minestom.server.tag.Tag;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.utils.Utils;
|
import net.minestom.server.utils.Utils;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
@ -147,11 +146,11 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resultNbt.getSize() > 0) {
|
if (resultNbt.getSize() > 0) {
|
||||||
final BlockPosition blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
|
final var blockPosition = ChunkUtils.getBlockPosition(index, chunkX, chunkZ);
|
||||||
resultNbt.setString("id", handler.getNamespaceId().asString())
|
resultNbt.setString("id", handler.getNamespaceId().asString())
|
||||||
.setInt("x", blockPosition.getX())
|
.setInt("x", blockPosition.blockX())
|
||||||
.setInt("y", blockPosition.getY())
|
.setInt("y", blockPosition.blockY())
|
||||||
.setInt("z", blockPosition.getZ());
|
.setInt("z", blockPosition.blockZ());
|
||||||
compounds.add(resultNbt);
|
compounds.add(resultNbt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
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.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
@ -9,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class SculkVibrationSignal implements ServerPacket {
|
public class SculkVibrationSignal implements ServerPacket {
|
||||||
|
|
||||||
public BlockPosition position;
|
public Point position;
|
||||||
public String destinationIdentifier;
|
public String destinationIdentifier;
|
||||||
// TODO 'varies' destination
|
// TODO 'varies' destination
|
||||||
public int arrivalTicks;
|
public int arrivalTicks;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package net.minestom.server.utils.chunk;
|
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.Chunk;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
import net.minestom.server.utils.callback.OptionalCallback;
|
import net.minestom.server.utils.callback.OptionalCallback;
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -99,10 +100,6 @@ public final class ChunkUtils {
|
|||||||
return retrieve(instance, originChunk, position.x(), position.z());
|
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
|
* @param xz the instance coordinate to convert
|
||||||
* @return the chunk X or Z based on the argument
|
* @return the chunk X or Z based on the argument
|
||||||
@ -231,12 +228,11 @@ public final class ChunkUtils {
|
|||||||
* @param chunkZ the chunk Z
|
* @param chunkZ the chunk Z
|
||||||
* @return the instance position of the block located in {@code index}
|
* @return the instance position of the block located in {@code index}
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public static @NotNull Point getBlockPosition(int index, int chunkX, int chunkZ) {
|
||||||
public static BlockPosition getBlockPosition(int index, int chunkX, int chunkZ) {
|
|
||||||
final int x = blockIndexToPositionX(index, chunkX);
|
final int x = blockIndexToPositionX(index, chunkX);
|
||||||
final int y = blockIndexToPositionY(index);
|
final int y = blockIndexToPositionY(index);
|
||||||
final int z = blockIndexToPositionZ(index, chunkZ);
|
final int z = blockIndexToPositionZ(index, chunkZ);
|
||||||
return new BlockPosition(x, y, z);
|
return new Vec(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,8 @@ import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
|||||||
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.command.CommandSender;
|
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.Entity;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
@ -33,7 +35,7 @@ public class EntityFinder {
|
|||||||
private EntitySort entitySort = EntitySort.ARBITRARY;
|
private EntitySort entitySort = EntitySort.ARBITRARY;
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
private Position startPosition = new Position();
|
private Point startPosition = Vec.ZERO;
|
||||||
private Float dx, dy, dz;
|
private Float dx, dy, dz;
|
||||||
private IntRange distance;
|
private IntRange distance;
|
||||||
|
|
||||||
@ -159,17 +161,17 @@ public class EntityFinder {
|
|||||||
final var entityPosition = entity.getPosition();
|
final var entityPosition = entity.getPosition();
|
||||||
if (dx != null && !MathUtils.isBetweenUnordered(
|
if (dx != null && !MathUtils.isBetweenUnordered(
|
||||||
entityPosition.x(),
|
entityPosition.x(),
|
||||||
startPosition.getX(), dx))
|
startPosition.x(), dx))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (dy != null && !MathUtils.isBetweenUnordered(
|
if (dy != null && !MathUtils.isBetweenUnordered(
|
||||||
entityPosition.y(),
|
entityPosition.y(),
|
||||||
startPosition.getY(), dy))
|
startPosition.y(), dy))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (dz != null && !MathUtils.isBetweenUnordered(
|
if (dz != null && !MathUtils.isBetweenUnordered(
|
||||||
entityPosition.z(),
|
entityPosition.z(),
|
||||||
startPosition.getZ(), dz))
|
startPosition.z(), dz))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -337,7 +339,7 @@ public class EntityFinder {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<Entity> findTarget(@Nullable Instance instance, @NotNull TargetSelector targetSelector,
|
private static List<Entity> findTarget(@Nullable Instance instance, @NotNull TargetSelector targetSelector,
|
||||||
@NotNull Position startPosition, @Nullable Entity self) {
|
@NotNull Point startPosition, @Nullable Entity self) {
|
||||||
|
|
||||||
if (targetSelector == TargetSelector.NEAREST_PLAYER) {
|
if (targetSelector == TargetSelector.NEAREST_PLAYER) {
|
||||||
Entity entity = null;
|
Entity entity = null;
|
||||||
|
@ -3,12 +3,12 @@ package demo.generator;
|
|||||||
import de.articdive.jnoise.JNoise;
|
import de.articdive.jnoise.JNoise;
|
||||||
import de.articdive.jnoise.interpolation.InterpolationType;
|
import de.articdive.jnoise.interpolation.InterpolationType;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.instance.Chunk;
|
import net.minestom.server.instance.Chunk;
|
||||||
import net.minestom.server.instance.ChunkGenerator;
|
import net.minestom.server.instance.ChunkGenerator;
|
||||||
import net.minestom.server.instance.ChunkPopulator;
|
import net.minestom.server.instance.ChunkPopulator;
|
||||||
import net.minestom.server.instance.batch.ChunkBatch;
|
import net.minestom.server.instance.batch.ChunkBatch;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
import net.minestom.server.world.biomes.Biome;
|
import net.minestom.server.world.biomes.Biome;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ public class NoiseTestGenerator implements ChunkGenerator {
|
|||||||
for (int j = -2; j < 18; j++) {
|
for (int j = -2; j < 18; j++) {
|
||||||
if (jNoise2.getNoise(i + chunk.getChunkX() * 16, j + chunk.getChunkZ() * 16) > 0.75) {
|
if (jNoise2.getNoise(i + chunk.getChunkX() * 16, j + chunk.getChunkZ() * 16) > 0.75) {
|
||||||
int y = getHeight(i + chunk.getChunkX() * 16, j + chunk.getChunkZ() * 16);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,30 @@
|
|||||||
package demo.generator;
|
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.Chunk;
|
||||||
import net.minestom.server.instance.batch.ChunkBatch;
|
import net.minestom.server.instance.batch.ChunkBatch;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Structure {
|
public class Structure {
|
||||||
|
|
||||||
private final Map<BlockPosition, Block> blocks = new HashMap<>();
|
private final Map<Point, Block> blocks = new HashMap<>();
|
||||||
|
|
||||||
public void build(ChunkBatch batch, BlockPosition pos) {
|
public void build(ChunkBatch batch, Point pos) {
|
||||||
blocks.forEach((bPos, block) -> {
|
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;
|
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;
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package improveextensions.unloadcallbacks;
|
package improveextensions.unloadcallbacks;
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.EntityCreature;
|
import net.minestom.server.entity.EntityCreature;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.event.EventCallback;
|
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.extensions.Extension;
|
||||||
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
|
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.utils.Position;
|
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.opentest4j.AssertionFailedError;
|
import org.opentest4j.AssertionFailedError;
|
||||||
@ -50,7 +50,7 @@ public class UnloadCallbacksExtension extends Extension {
|
|||||||
zombie.addEventCallback(EntityTickEvent.class, e -> {
|
zombie.addEventCallback(EntityTickEvent.class, e -> {
|
||||||
zombieTicked = true;
|
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
|
// this callback will be cancelled
|
||||||
MinecraftServer.getSchedulerManager().buildTask(() -> {
|
MinecraftServer.getSchedulerManager().buildTask(() -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user