mirror of https://github.com/Minestom/Minestom.git
Merge branch 'master' into improved-pathfinding
This commit is contained in:
commit
9cade8766c
|
@ -1,4 +1,4 @@
|
|||
# Thanks paper: https://github.com/lynxplay/paper/blob/master/.github/workflows/close_invalid_prs.yml
|
||||
# Thanks paper: https://github.com/papermc/paper/blob/master/.github/workflows/close_invalid_prs.yml
|
||||
name: Close invalid PRs
|
||||
|
||||
on:
|
||||
|
|
|
@ -75,6 +75,7 @@ public class Main {
|
|||
commandManager.register(new SetEntityType());
|
||||
commandManager.register(new RelightCommand());
|
||||
commandManager.register(new KillCommand());
|
||||
commandManager.register(new WeatherCommand());
|
||||
|
||||
commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED)));
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ public class PlayerInit {
|
|||
});
|
||||
instanceContainer.setChunkSupplier(LightingChunk::new);
|
||||
instanceContainer.setTimeRate(0);
|
||||
instanceContainer.setTime(18000);
|
||||
instanceContainer.setTime(12000);
|
||||
|
||||
// var i2 = new InstanceContainer(UUID.randomUUID(), DimensionType.OVERWORLD, null, NamespaceID.from("minestom:demo"));
|
||||
// instanceManager.registerInstance(i2);
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package net.minestom.demo.commands;
|
||||
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandContext;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.Weather;
|
||||
|
||||
public class WeatherCommand extends Command {
|
||||
public WeatherCommand() {
|
||||
super("weather");
|
||||
|
||||
var isRaining = ArgumentType.Boolean("isRaining").setDefaultValue(false);
|
||||
var rainLevel = ArgumentType.Float("rainLevel").setDefaultValue(0.0f);
|
||||
var thunderLevel = ArgumentType.Float("thunderLevel").setDefaultValue(0.0f);
|
||||
var transitionTicks = ArgumentType.Integer("transition").setDefaultValue(0);
|
||||
addSyntax(this::handleWeather, isRaining, rainLevel, thunderLevel, transitionTicks);
|
||||
}
|
||||
|
||||
private void handleWeather(CommandSender source, CommandContext context) {
|
||||
Player player = (Player) source;
|
||||
boolean isRaining = context.get("isRaining");
|
||||
float rainLevel = context.get("rainLevel");
|
||||
float thunderLevel = context.get("thunderLevel");
|
||||
int transitionTicks = context.get("transition");
|
||||
player.getInstance().setWeather(new Weather(isRaining, rainLevel, thunderLevel), transitionTicks);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ metadata.format.version = "1.1"
|
|||
[versions]
|
||||
|
||||
# Important dependencies
|
||||
data = "1.20.4-rv3"
|
||||
data = "1.20.4-rv4"
|
||||
adventure = "4.15.0"
|
||||
kotlin = "1.7.22"
|
||||
dependencyGetter = "v1.0.1"
|
||||
|
|
Binary file not shown.
|
@ -1,5 +1,7 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
@ -80,13 +80,11 @@ do
|
|||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
@ -133,22 +131,29 @@ location of your Java installation."
|
|||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
|
@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
|||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
|
@ -205,6 +214,12 @@ set -- \
|
|||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
|
@ -25,7 +25,8 @@
|
|||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
|
@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
|
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
|
|
@ -15,6 +15,7 @@ public final class ServerFlag {
|
|||
public static final int SERVER_TICKS_PER_SECOND = Integer.getInteger("minestom.tps", 20);
|
||||
public static final int CHUNK_VIEW_DISTANCE = Integer.getInteger("minestom.chunk-view-distance", 8);
|
||||
public static final int ENTITY_VIEW_DISTANCE = Integer.getInteger("minestom.entity-view-distance", 5);
|
||||
public static final int ENTITY_SYNCHRONIZATION_TICKS = Integer.getInteger("minestom.entity-synchronization-ticks", 20);
|
||||
public static final int WORKER_COUNT = Integer.getInteger("minestom.workers", Runtime.getRuntime().availableProcessors());
|
||||
public static final int MAX_PACKET_SIZE = Integer.getInteger("minestom.max-packet-size", 2_097_151); // 3 bytes var-int
|
||||
public static final int SOCKET_SEND_BUFFER_SIZE = Integer.getInteger("minestom.send-buffer-size", 262_143);
|
||||
|
@ -22,6 +23,7 @@ public final class ServerFlag {
|
|||
public static final int POOLED_BUFFER_SIZE = Integer.getInteger("minestom.pooled-buffer-size", 262_143);
|
||||
public static final int PLAYER_PACKET_PER_TICK = Integer.getInteger("minestom.packet-per-tick", 20);
|
||||
public static final int PLAYER_PACKET_QUEUE_SIZE = Integer.getInteger("minestom.packet-queue-size", 1000);
|
||||
public static final int SEND_LIGHT_AFTER_BLOCK_PLACEMENT_DELAY = Integer.getInteger("minestom.send-light-after-block-placement-delay", 100);
|
||||
|
||||
// Packet sending optimizations
|
||||
public static final boolean GROUPED_PACKET = PropertyUtils.getBoolean("minestom.grouped-packet", true);
|
||||
|
|
|
@ -63,17 +63,6 @@ public final class BoundingBox implements Shape {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to know if this {@link BoundingBox} intersects with the bounding box of an entity.
|
||||
*
|
||||
* @param entity the entity to check the bounding box
|
||||
* @return true if this bounding box intersects with the entity, false otherwise
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public boolean intersectEntity(@NotNull Point src, @NotNull Entity entity) {
|
||||
return intersectBox(src.sub(entity.getPosition()), entity.getBoundingBox());
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public boolean boundingBoxRayIntersectionCheck(Vec start, Vec direction, Pos position) {
|
||||
return RayUtils.BoundingBoxRayIntersectionCheck(start, direction, this, position);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.minestom.server.collision;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -39,6 +40,18 @@ public interface Shape {
|
|||
boolean intersectBoxSwept(@NotNull Point rayStart, @NotNull Point rayDirection,
|
||||
@NotNull Point shapePos, @NotNull BoundingBox moving, @NotNull SweepResult finalResult);
|
||||
|
||||
|
||||
/**
|
||||
* Used to know if this {@link BoundingBox} intersects with the bounding box of an entity.
|
||||
*
|
||||
* @param entity the entity to check the bounding box
|
||||
* @return true if this bounding box intersects with the entity, false otherwise
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
default boolean intersectEntity(@NotNull Point src, @NotNull Entity entity) {
|
||||
return intersectBox(src.sub(entity.getPosition()), entity.getBoundingBox());
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative Start
|
||||
*
|
||||
|
|
|
@ -18,6 +18,7 @@ public final class ShapeImpl implements Shape {
|
|||
private static final Pattern PATTERN = Pattern.compile("\\d.\\d+", Pattern.MULTILINE);
|
||||
private final BoundingBox[] collisionBoundingBoxes;
|
||||
private final Point relativeStart, relativeEnd;
|
||||
private final byte fullFaces;
|
||||
|
||||
private final BoundingBox[] occlusionBoundingBoxes;
|
||||
private final byte blockOcclusion;
|
||||
|
@ -32,7 +33,7 @@ public final class ShapeImpl implements Shape {
|
|||
this.blockEntry = blockEntry;
|
||||
|
||||
// Find bounds of collision
|
||||
{
|
||||
if (collisionBoundingBoxes.length > 0) {
|
||||
double minX = 1, minY = 1, minZ = 1;
|
||||
double maxX = 0, maxY = 0, maxZ = 0;
|
||||
for (BoundingBox blockSection : collisionBoundingBoxes) {
|
||||
|
@ -47,12 +48,22 @@ public final class ShapeImpl implements Shape {
|
|||
}
|
||||
this.relativeStart = new Vec(minX, minY, minZ);
|
||||
this.relativeEnd = new Vec(maxX, maxY, maxZ);
|
||||
} else {
|
||||
this.relativeStart = Vec.ZERO;
|
||||
this.relativeEnd = Vec.ZERO;
|
||||
}
|
||||
|
||||
byte fullCollisionFaces = 0;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
final byte res = isFaceCovered(computeOcclusionSet(f, collisionBoundingBoxes));
|
||||
fullCollisionFaces |= ((res == 2) ? 0b1 : 0b0) << (byte) f.ordinal();
|
||||
}
|
||||
this.fullFaces = fullCollisionFaces;
|
||||
|
||||
byte airFaces = 0;
|
||||
byte fullFaces = 0;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
final byte res = isFaceCovered(computeOcclusionSet(f));
|
||||
final byte res = isFaceCovered(computeOcclusionSet(f, occlusionBoundingBoxes));
|
||||
airFaces |= ((res == 0) ? 0b1 : 0b0) << (byte) f.ordinal();
|
||||
fullFaces |= ((res == 2) ? 0b1 : 0b0) << (byte) f.ordinal();
|
||||
}
|
||||
|
@ -145,14 +156,14 @@ public final class ShapeImpl implements Shape {
|
|||
if (hasAirOcclusion || hasAirOcclusionOther) return false;
|
||||
|
||||
// Comparing two partial faces. Computation needed
|
||||
List<Rectangle> allRectangles = shapeImpl.computeOcclusionSet(face.getOppositeFace());
|
||||
allRectangles.addAll(computeOcclusionSet(face));
|
||||
List<Rectangle> allRectangles = computeOcclusionSet(face.getOppositeFace(), shapeImpl.occlusionBoundingBoxes);
|
||||
allRectangles.addAll(computeOcclusionSet(face, occlusionBoundingBoxes));
|
||||
return isFaceCovered(allRectangles) == 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFaceFull(@NotNull BlockFace face) {
|
||||
return (((blockOcclusion >> face.ordinal()) & 1) == 1);
|
||||
return (((fullFaces >> face.ordinal()) & 1) == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,9 +198,9 @@ public final class ShapeImpl implements Shape {
|
|||
return block;
|
||||
}
|
||||
|
||||
private List<Rectangle> computeOcclusionSet(BlockFace face) {
|
||||
private static @NotNull List<Rectangle> computeOcclusionSet(BlockFace face, BoundingBox[] boundingBoxes) {
|
||||
List<Rectangle> rSet = new ArrayList<>();
|
||||
for (BoundingBox boundingBox : this.occlusionBoundingBoxes) {
|
||||
for (BoundingBox boundingBox : boundingBoxes) {
|
||||
switch (face) {
|
||||
case NORTH -> // negative Z
|
||||
{
|
||||
|
|
|
@ -5,10 +5,7 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent.ShowEntity;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.ServerProcess;
|
||||
import net.minestom.server.Tickable;
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.*;
|
||||
import net.minestom.server.collision.*;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
|
@ -31,8 +28,6 @@ import net.minestom.server.instance.block.Block;
|
|||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import net.minestom.server.network.packet.server.CachedPacket;
|
||||
import net.minestom.server.network.packet.server.LazyPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.permission.Permission;
|
||||
import net.minestom.server.permission.PermissionHandler;
|
||||
|
@ -56,7 +51,6 @@ import net.minestom.server.utils.block.BlockIterator;
|
|||
import net.minestom.server.utils.chunk.ChunkCache;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.utils.player.PlayerUtils;
|
||||
import net.minestom.server.utils.time.Cooldown;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
@ -162,12 +156,15 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
protected boolean removed;
|
||||
|
||||
private final Set<Entity> passengers = new CopyOnWriteArraySet<>();
|
||||
|
||||
private final Set<Entity> leashedEntities = new CopyOnWriteArraySet<>();
|
||||
private Entity leashHolder;
|
||||
|
||||
protected EntityType entityType; // UNSAFE to change, modify at your own risk
|
||||
|
||||
// Network synchronization, send the absolute position of the entity each X milliseconds
|
||||
private static final Duration SYNCHRONIZATION_COOLDOWN = Duration.of(1, TimeUnit.MINUTE);
|
||||
private Duration customSynchronizationCooldown;
|
||||
private long lastAbsoluteSynchronizationTime;
|
||||
// Network synchronization, send the absolute position of the entity every n ticks
|
||||
private long synchronizationTicks = ServerFlag.ENTITY_SYNCHRONIZATION_TICKS;
|
||||
private long nextSynchronizationTick = synchronizationTicks;
|
||||
|
||||
protected Metadata metadata = new Metadata(this);
|
||||
protected EntityMeta entityMeta;
|
||||
|
@ -322,7 +319,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
this.position = position;
|
||||
refreshCoordinate(position);
|
||||
synchronizePosition(true);
|
||||
setView(position.yaw(), position.pitch());
|
||||
sendPacketToViewers(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
||||
};
|
||||
|
||||
if (chunks != null && chunks.length > 0) {
|
||||
|
@ -464,7 +461,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
public void updateNewViewer(@NotNull Player player) {
|
||||
player.sendPacket(getEntityType().registry().spawnType().getSpawnPacket(this));
|
||||
if (hasVelocity()) player.sendPacket(getVelocityPacket());
|
||||
player.sendPacket(new LazyPacket(this::getMetadataPacket));
|
||||
player.sendPacket(getMetadataPacket());
|
||||
// Passengers
|
||||
final Set<Entity> passengers = this.passengers;
|
||||
if (!passengers.isEmpty()) {
|
||||
|
@ -473,6 +470,15 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
}
|
||||
player.sendPacket(getPassengersPacket());
|
||||
}
|
||||
// Leashes
|
||||
if (leashHolder != null && (player.equals(leashHolder) || leashHolder.isViewer(player))) {
|
||||
player.sendPacket(getAttachEntityPacket());
|
||||
}
|
||||
for (Entity entity : leashedEntities) {
|
||||
if (entity.isViewer(player)) {
|
||||
player.sendPacket(entity.getAttachEntityPacket());
|
||||
}
|
||||
};
|
||||
// Head position
|
||||
player.sendPacket(new EntityHeadLookPacket(getEntityId(), position.yaw()));
|
||||
}
|
||||
|
@ -491,6 +497,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
if (passenger != player) passenger.updateOldViewer(player);
|
||||
}
|
||||
}
|
||||
leashedEntities.forEach(entity -> player.sendPacket(new AttachEntityPacket(entity, null)));
|
||||
player.sendPacket(destroyPacketCache);
|
||||
}
|
||||
|
||||
|
@ -567,7 +574,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
effectTick(time);
|
||||
}
|
||||
// Scheduled synchronization
|
||||
if (!Cooldown.hasCooldown(time, lastAbsoluteSynchronizationTime, getSynchronizationCooldown())) {
|
||||
if (ticks >= nextSynchronizationTick) {
|
||||
synchronizePosition(false);
|
||||
}
|
||||
}
|
||||
|
@ -890,6 +897,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
if (this instanceof Player player) {
|
||||
instance.getWorldBorder().init(player);
|
||||
player.sendPacket(instance.createTimePacket());
|
||||
player.sendPackets(instance.getWeather().createWeatherPackets());
|
||||
}
|
||||
instance.getEntityTracker().register(this, spawnPosition, trackingTarget, trackingUpdate);
|
||||
spawn();
|
||||
|
@ -1098,6 +1106,40 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
return new SetPassengersPacket(getEntityId(), passengers.stream().map(Entity::getEntityId).toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entities that this entity is leashing.
|
||||
*
|
||||
* @return an unmodifiable list containing all the leashed entities
|
||||
*/
|
||||
public @NotNull Set<Entity> getLeashedEntities() {
|
||||
return Collections.unmodifiableSet(leashedEntities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current leash holder.
|
||||
*
|
||||
* @return the entity leashing this entity, null if no leash holder
|
||||
*/
|
||||
public @Nullable Entity getLeashHolder() {
|
||||
return leashHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the leash holder to this entity.
|
||||
*
|
||||
* @param entity the new leash holder
|
||||
*/
|
||||
public void setLeashHolder(@Nullable Entity entity) {
|
||||
if (leashHolder != null) leashHolder.leashedEntities.remove(this);
|
||||
if (entity != null) entity.leashedEntities.add(this);
|
||||
this.leashHolder = entity;
|
||||
sendPacketToViewersAndSelf(getAttachEntityPacket());
|
||||
}
|
||||
|
||||
protected @NotNull AttachEntityPacket getAttachEntityPacket() {
|
||||
return new AttachEntityPacket(this, leashHolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity statuses can be found <a href="https://wiki.vg/Entity_statuses">here</a>.
|
||||
*
|
||||
|
@ -1321,6 +1363,11 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
this.position = position;
|
||||
this.previousPosition = previousPosition;
|
||||
if (!position.samePoint(previousPosition)) refreshCoordinate(position);
|
||||
if (nextSynchronizationTick <= ticks + 1) {
|
||||
// The entity will be synchronized at the end of its tick
|
||||
// not returning here will duplicate position packets
|
||||
return;
|
||||
}
|
||||
// Update viewers
|
||||
final boolean viewChange = !position.sameView(lastSyncedPosition);
|
||||
final double distanceX = Math.abs(position.x() - lastSyncedPosition.x());
|
||||
|
@ -1331,7 +1378,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
final Chunk chunk = getChunk();
|
||||
if (distanceX > 8 || distanceY > 8 || distanceZ > 8) {
|
||||
PacketUtils.prepareViewablePacket(chunk, new EntityTeleportPacket(getEntityId(), position, isOnGround()), this);
|
||||
this.lastAbsoluteSynchronizationTime = System.currentTimeMillis();
|
||||
nextSynchronizationTick = synchronizationTicks + 1;
|
||||
} else if (positionChange && viewChange) {
|
||||
PacketUtils.prepareViewablePacket(chunk, EntityPositionAndRotationPacket.getPacket(getEntityId(), position,
|
||||
lastSyncedPosition, isOnGround()), this);
|
||||
|
@ -1543,6 +1590,9 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
final Entity vehicle = this.vehicle;
|
||||
if (vehicle != null) vehicle.removePassenger(this);
|
||||
|
||||
Set<Entity> leashedEntities = getLeashedEntities();
|
||||
leashedEntities.forEach(entity -> entity.setLeashHolder(null));
|
||||
|
||||
MinecraftServer.process().dispatcher().removeElement(this);
|
||||
this.removed = true;
|
||||
if (permanent) {
|
||||
|
@ -1628,9 +1678,11 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
@ApiStatus.Internal
|
||||
protected void synchronizePosition(boolean includeSelf) {
|
||||
final Pos posCache = this.position;
|
||||
final ServerPacket packet = new EntityTeleportPacket(getEntityId(), posCache, isOnGround());
|
||||
PacketUtils.prepareViewablePacket(currentChunk, packet, this);
|
||||
this.lastAbsoluteSynchronizationTime = System.currentTimeMillis();
|
||||
PacketUtils.prepareViewablePacket(currentChunk, new EntityTeleportPacket(getEntityId(), posCache, isOnGround()), this);
|
||||
if (posCache.yaw() != lastSyncedPosition.yaw()) {
|
||||
PacketUtils.prepareViewablePacket(currentChunk, new EntityHeadLookPacket(getEntityId(), position.yaw()), this);
|
||||
}
|
||||
nextSynchronizationTick = ticks + synchronizationTicks;
|
||||
this.lastSyncedPosition = posCache;
|
||||
}
|
||||
|
||||
|
@ -1640,28 +1692,34 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
|||
}
|
||||
|
||||
/**
|
||||
* Asks for a synchronization (position) to happen during next entity tick.
|
||||
* Asks for a position synchronization to happen during next entity tick.
|
||||
*/
|
||||
public void askSynchronization() {
|
||||
this.lastAbsoluteSynchronizationTime = 0;
|
||||
public void synchronizeNextTick() {
|
||||
this.nextSynchronizationTick = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom cooldown for position synchronization.
|
||||
* Returns the current synchronization interval. The default value is {@link ServerFlag#ENTITY_SYNCHRONIZATION_TICKS}
|
||||
* but can be overridden per entity with {@link #setSynchronizationTicks(long)}.
|
||||
*
|
||||
* @param cooldown custom cooldown for position synchronization.
|
||||
* @return The current synchronization ticks
|
||||
*/
|
||||
public void setCustomSynchronizationCooldown(@Nullable Duration cooldown) {
|
||||
this.customSynchronizationCooldown = cooldown;
|
||||
public long getSynchronizationTicks() {
|
||||
return this.synchronizationTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tick period until this entity's position is synchronized.
|
||||
*
|
||||
* @param ticks the new synchronization tick period
|
||||
*/
|
||||
public void setSynchronizationTicks(long ticks) {
|
||||
this.synchronizationTicks = ticks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HoverEvent<ShowEntity> asHoverEvent(@NotNull UnaryOperator<ShowEntity> op) {
|
||||
return HoverEvent.showEntity(ShowEntity.of(this.entityType, this.uuid));
|
||||
}
|
||||
|
||||
private Duration getSynchronizationCooldown() {
|
||||
return Objects.requireNonNullElse(this.customSynchronizationCooldown, SYNCHRONIZATION_COOLDOWN);
|
||||
return HoverEvent.showEntity(ShowEntity.showEntity(this.entityType, this.uuid));
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.minestom.server.coordinate.Point;
|
|||
import net.minestom.server.entity.metadata.animal.FrogMeta;
|
||||
import net.minestom.server.entity.metadata.animal.SnifferMeta;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
|
||||
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.play.EntityMetaDataPacket;
|
||||
|
@ -115,6 +116,10 @@ public final class Metadata {
|
|||
return new MetadataImpl.EntryImpl<>(TYPE_FROG_VARIANT, value, NetworkBuffer.FROG_VARIANT);
|
||||
}
|
||||
|
||||
public static Entry<PaintingMeta.Variant> PaintingVariant(@NotNull PaintingMeta.Variant value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_PAINTINGVARIANT, value, NetworkBuffer.PAINTING_VARIANT);
|
||||
}
|
||||
|
||||
public static Entry<SnifferMeta.State> SnifferState(@NotNull SnifferMeta.State value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_SNIFFER_STATE, value, NetworkBuffer.SNIFFER_STATE);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.minestom.server.coordinate.Vec;
|
|||
import net.minestom.server.entity.metadata.animal.FrogMeta;
|
||||
import net.minestom.server.entity.metadata.animal.SnifferMeta;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
|
||||
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
|
@ -45,7 +46,7 @@ final class MetadataImpl {
|
|||
EMPTY_VALUES.set(TYPE_CAT_VARIANT, CatVariant(CatMeta.Variant.TABBY));
|
||||
EMPTY_VALUES.set(TYPE_FROG_VARIANT, FrogVariant(FrogMeta.Variant.TEMPERATE));
|
||||
// OptGlobalPos
|
||||
// PaintingVariant
|
||||
EMPTY_VALUES.set(TYPE_PAINTINGVARIANT, PaintingVariant(PaintingMeta.Variant.KEBAB));
|
||||
EMPTY_VALUES.set(TYPE_SNIFFER_STATE, SnifferState(SnifferMeta.State.IDLING));
|
||||
EMPTY_VALUES.set(TYPE_VECTOR3, Vector3(Vec.ZERO));
|
||||
EMPTY_VALUES.set(TYPE_QUATERNION, Quaternion(new float[]{0, 0, 0, 0}));
|
||||
|
|
|
@ -3,128 +3,159 @@ package net.minestom.server.entity.metadata.other;
|
|||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.entity.metadata.EntityMeta;
|
||||
import net.minestom.server.utils.Direction;
|
||||
import net.minestom.server.entity.metadata.ObjectDataProvider;
|
||||
import net.minestom.server.registry.StaticProtocolObject;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class PaintingMeta extends EntityMeta {
|
||||
public class PaintingMeta extends EntityMeta implements ObjectDataProvider {
|
||||
public static final byte OFFSET = EntityMeta.MAX_OFFSET;
|
||||
public static final byte MAX_OFFSET = OFFSET + 0;
|
||||
public static final byte MAX_OFFSET = OFFSET + 1;
|
||||
|
||||
private Motive motive = Motive.KEBAB;
|
||||
private Direction direction = Direction.SOUTH;
|
||||
private Orientation orientation = null;
|
||||
|
||||
public PaintingMeta(@NotNull Entity entity, @NotNull Metadata metadata) {
|
||||
super(entity, metadata);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Motive getMotive() {
|
||||
return motive;
|
||||
public @NotNull Variant getVariant() {
|
||||
return super.metadata.getIndex(OFFSET, Variant.KEBAB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets motive of a painting.
|
||||
* This is possible only before spawn packet is sent.
|
||||
*
|
||||
* @param motive motive of a painting.
|
||||
*/
|
||||
public void setMotive(@NotNull Motive motive) {
|
||||
this.motive = motive;
|
||||
public void setVariant(@NotNull Variant value) {
|
||||
super.metadata.setIndex(OFFSET, Metadata.PaintingVariant(value));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
public Orientation getOrientation() {
|
||||
return this.orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets direction of a painting.
|
||||
* Sets orientation of the painting.
|
||||
* This is possible only before spawn packet is sent.
|
||||
*
|
||||
* @param direction direction of a painting.
|
||||
* @param orientation the orientation of the painting.
|
||||
*/
|
||||
public void setDirection(@NotNull Direction direction) {
|
||||
Check.argCondition(direction == Direction.UP || direction == Direction.DOWN, "Painting can't look up or down!");
|
||||
this.direction = direction;
|
||||
public void setOrientation(@NotNull Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: write a parser?
|
||||
Currently none of existing ones support it.
|
||||
*/
|
||||
public enum Motive {
|
||||
KEBAB(0, 0, 16, 16),
|
||||
AZTEC(16, 0, 16, 16),
|
||||
ALBAN(32, 0, 16, 16),
|
||||
AZTEC2(48, 0, 16, 16),
|
||||
BOMB(64, 0, 16, 16),
|
||||
PLANT(80, 0, 16, 16),
|
||||
WASTELAND(96, 0, 16, 16),
|
||||
POOL(0, 32, 32, 16),
|
||||
COURBET(32, 32, 32, 16),
|
||||
SEA(64, 32, 32, 16),
|
||||
SUNSET(96, 32, 32, 16),
|
||||
CREEBET(128, 32, 32, 16),
|
||||
WANDERER(0, 64, 16, 32),
|
||||
GRAHAM(16, 64, 16, 32),
|
||||
MATCH(0, 128, 32, 32),
|
||||
BUST(32, 128, 32, 32),
|
||||
STAGE(64, 128, 32, 32),
|
||||
VOID(96, 128, 32, 32),
|
||||
SKULL_AND_ROSES("skull_and_roses", 128, 128, 32, 32),
|
||||
WITHER(160, 128, 32, 32),
|
||||
FIGHTERS(0, 96, 64, 32),
|
||||
POINTER(0, 192, 64, 64),
|
||||
PIGSCENE(64, 192, 64, 64),
|
||||
BURNING_SKULL(128, 192, 64, 64),
|
||||
SKELETON(192, 64, 64, 48),
|
||||
DONKEY_KONG(192, 112, 64, 48);
|
||||
@Override
|
||||
public int getObjectData() {
|
||||
Check.stateCondition(this.orientation == null, "Painting orientation must be set before spawn");
|
||||
return this.orientation.id();
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private final int x;
|
||||
private final int y;
|
||||
@Override
|
||||
public boolean requiresVelocityPacketAtSpawn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Orientation {
|
||||
NORTH(2),
|
||||
SOUTH(3),
|
||||
WEST(4),
|
||||
EAST(5);
|
||||
|
||||
private final int id;
|
||||
|
||||
Orientation(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Variant implements StaticProtocolObject {
|
||||
KEBAB(16, 16),
|
||||
AZTEC(16, 16),
|
||||
ALBAN(16, 16),
|
||||
AZTEC2(16, 16),
|
||||
BOMB(16, 16),
|
||||
PLANT(16, 16),
|
||||
WASTELAND(16, 16),
|
||||
POOL(32, 16),
|
||||
COURBET(32, 16),
|
||||
SEA(32, 16),
|
||||
SUNSET(32, 16),
|
||||
CREEBET(32, 16),
|
||||
WANDERER(16, 32),
|
||||
GRAHAM(16, 32),
|
||||
MATCH(32, 32),
|
||||
BUST(32, 32),
|
||||
STAGE(32, 32),
|
||||
VOID(32, 32),
|
||||
SKULL_AND_ROSES(32, 32),
|
||||
WITHER(32, 32),
|
||||
FIGHTERS(64, 32),
|
||||
POINTER(64, 64),
|
||||
PIGSCENE(64, 64),
|
||||
BURNING_SKULL(64, 64),
|
||||
SKELETON(64, 48),
|
||||
EARTH(32, 32),
|
||||
WIND(32, 32),
|
||||
WATER(32, 32),
|
||||
FIRE(32, 32),
|
||||
DONKEY_KONG(64, 48);
|
||||
|
||||
private static final Variant[] VALUES = values();
|
||||
|
||||
public static @Nullable Variant fromId(int id) {
|
||||
if (id < 0 || id >= VALUES.length) {
|
||||
return null;
|
||||
}
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
public static @Nullable Variant fromNamespaceId(@Nullable String namespaceId) {
|
||||
if (namespaceId == null) return null;
|
||||
return fromNamespaceId(NamespaceID.from(namespaceId));
|
||||
}
|
||||
|
||||
public static @Nullable Variant fromNamespaceId(@Nullable NamespaceID namespaceId) {
|
||||
if (namespaceId == null) return null;
|
||||
for (Variant value : VALUES) {
|
||||
if (value.namespace().equals(namespaceId)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final NamespaceID namespace;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
Motive(String name, int x, int y, int width, int height) {
|
||||
this.name = name;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
Variant(int width, int height) {
|
||||
this.namespace = NamespaceID.from("minecraft", name().toLowerCase(Locale.ROOT));
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
Motive(int x, int y, int width, int height) {
|
||||
this.name = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@Override
|
||||
public int id() {
|
||||
return ordinal();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
public int width() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
public int height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
@Override
|
||||
public @NotNull NamespaceID namespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -271,6 +271,11 @@ public abstract class Chunk implements Block.Getter, Block.Setter, Biome.Getter,
|
|||
*/
|
||||
protected void onLoad() {}
|
||||
|
||||
/**
|
||||
* Called when the chunk generator has finished generating the chunk.
|
||||
*/
|
||||
public void onGenerate() {}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "[" + chunkX + ":" + chunkZ + "]";
|
||||
|
|
|
@ -82,6 +82,11 @@ public abstract class Instance implements Block.Getter, Block.Setter,
|
|||
private Duration timeUpdate = Duration.of(1, TimeUnit.SECOND);
|
||||
private long lastTimeUpdate;
|
||||
|
||||
// Weather of the instance
|
||||
private Weather targetWeather = new Weather(false, 0, 0);
|
||||
private Weather currentWeather = new Weather(false, 0, 0);
|
||||
private int remainingWeatherTransitionTicks;
|
||||
|
||||
// Field for tick events
|
||||
private long lastTickAge = System.currentTimeMillis();
|
||||
|
||||
|
@ -664,6 +669,13 @@ public abstract class Instance implements Block.Getter, Block.Setter,
|
|||
}
|
||||
|
||||
}
|
||||
// Weather
|
||||
if (remainingWeatherTransitionTicks > 0) {
|
||||
Weather previousWeather = currentWeather;
|
||||
currentWeather = transitionWeather(remainingWeatherTransitionTicks);
|
||||
sendWeatherPackets(previousWeather);
|
||||
remainingWeatherTransitionTicks--;
|
||||
}
|
||||
// Tick event
|
||||
{
|
||||
// Process tick events
|
||||
|
@ -674,6 +686,45 @@ public abstract class Instance implements Block.Getter, Block.Setter,
|
|||
this.worldBorder.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current weather on this instance
|
||||
*
|
||||
* @return the current weather
|
||||
*/
|
||||
public @NotNull Weather getWeather() {
|
||||
return currentWeather;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the weather on this instance, transitions over time
|
||||
*
|
||||
* @param weather the new weather
|
||||
* @param transitionTicks the ticks to transition to new weather
|
||||
*/
|
||||
public void setWeather(@NotNull Weather weather, int transitionTicks) {
|
||||
Check.stateCondition(transitionTicks < 1, "Transition ticks cannot be lower than 1");
|
||||
targetWeather = weather;
|
||||
remainingWeatherTransitionTicks = transitionTicks;
|
||||
}
|
||||
|
||||
private void sendWeatherPackets(@NotNull Weather previousWeather) {
|
||||
if (currentWeather.isRaining() != previousWeather.isRaining()) sendGroupedPacket(currentWeather.createIsRainingPacket());
|
||||
if (currentWeather.rainLevel() != previousWeather.rainLevel()) sendGroupedPacket(currentWeather.createRainLevelPacket());
|
||||
if (currentWeather.thunderLevel() != previousWeather.thunderLevel()) sendGroupedPacket(currentWeather.createThunderLevelPacket());
|
||||
}
|
||||
|
||||
private @NotNull Weather transitionWeather(int remainingTicks) {
|
||||
Weather target = targetWeather;
|
||||
Weather current = currentWeather;
|
||||
if (remainingTicks <= 1) {
|
||||
return new Weather(target.isRaining(), target.isRaining() ? target.rainLevel() : 0,
|
||||
target.isRaining() ? target.thunderLevel() : 0);
|
||||
}
|
||||
float rainLevel = current.rainLevel() + (target.rainLevel() - current.rainLevel()) * (1 / (float)remainingTicks);
|
||||
float thunderLevel = current.thunderLevel() + (target.thunderLevel() - current.thunderLevel()) * (1 / (float)remainingTicks);
|
||||
return new Weather(rainLevel > 0, rainLevel, thunderLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull TagHandler tagHandler() {
|
||||
return tagHandler;
|
||||
|
|
|
@ -298,7 +298,7 @@ public class InstanceContainer extends Instance {
|
|||
return CompletableFuture.completedFuture(chunk);
|
||||
} else {
|
||||
// Loader couldn't load the chunk, generate it
|
||||
return createChunk(chunkX, chunkZ);
|
||||
return createChunk(chunkX, chunkZ).whenComplete((c, a) -> c.onGenerate());
|
||||
}
|
||||
})
|
||||
// cache the retrieved chunk
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.ServerFlag;
|
||||
import net.minestom.server.collision.Shape;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
|
@ -8,10 +9,7 @@ import net.minestom.server.instance.block.Block;
|
|||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import net.minestom.server.instance.light.Light;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.packet.server.CachedPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||
import net.minestom.server.network.packet.server.play.data.LightData;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
|
@ -26,6 +24,8 @@ import java.util.concurrent.CompletableFuture;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static net.minestom.server.instance.light.LightCompute.emptyContent;
|
||||
|
||||
|
@ -41,9 +41,16 @@ public class LightingChunk extends DynamicChunk {
|
|||
|
||||
private int[] heightmap;
|
||||
final CachedPacket lightCache = new CachedPacket(this::createLightPacket);
|
||||
private LightData lightData;
|
||||
|
||||
boolean chunkLoaded = false;
|
||||
private int highestBlock;
|
||||
private boolean initialLightingSent = false;
|
||||
|
||||
private final ReentrantLock packetGenerationLock = new ReentrantLock();
|
||||
private final AtomicInteger resendTimer = new AtomicInteger(-1);
|
||||
private final int resendDelay = ServerFlag.SEND_LIGHT_AFTER_BLOCK_PLACEMENT_DELAY;
|
||||
|
||||
private boolean doneInit = false;
|
||||
|
||||
enum LightType {
|
||||
SKY,
|
||||
|
@ -67,6 +74,7 @@ public class LightingChunk extends DynamicChunk {
|
|||
Block.DARK_OAK_LEAVES.namespace(),
|
||||
Block.FLOWERING_AZALEA_LEAVES.namespace(),
|
||||
Block.JUNGLE_LEAVES.namespace(),
|
||||
Block.CHERRY_LEAVES.namespace(),
|
||||
Block.OAK_LEAVES.namespace(),
|
||||
Block.SPRUCE_LEAVES.namespace(),
|
||||
Block.SPAWNER.namespace(),
|
||||
|
@ -83,6 +91,7 @@ public class LightingChunk extends DynamicChunk {
|
|||
public void invalidate() {
|
||||
this.lightCache.invalidate();
|
||||
this.chunkCache.invalidate();
|
||||
this.lightData = null;
|
||||
}
|
||||
|
||||
public LightingChunk(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
|
@ -107,8 +116,7 @@ public class LightingChunk extends DynamicChunk {
|
|||
if (neighborChunk == null) continue;
|
||||
|
||||
if (neighborChunk instanceof LightingChunk light) {
|
||||
light.lightCache.invalidate();
|
||||
light.chunkCache.invalidate();
|
||||
light.invalidate();
|
||||
}
|
||||
|
||||
for (int k = -1; k <= 1; k++) {
|
||||
|
@ -132,6 +140,19 @@ public class LightingChunk extends DynamicChunk {
|
|||
if (chunkLoaded) {
|
||||
invalidateSection(coordinate);
|
||||
this.lightCache.invalidate();
|
||||
|
||||
if (doneInit) {
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
Chunk neighborChunk = instance.getChunk(chunkX + i, chunkZ + j);
|
||||
if (neighborChunk == null) continue;
|
||||
|
||||
if (neighborChunk instanceof LightingChunk light) {
|
||||
light.resendTimer.set(resendDelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,10 +164,41 @@ public class LightingChunk extends DynamicChunk {
|
|||
@Override
|
||||
protected void onLoad() {
|
||||
chunkLoaded = true;
|
||||
doneInit = true;
|
||||
}
|
||||
|
||||
public boolean isLightingCalculated() {
|
||||
return initialLightingSent;
|
||||
@Override
|
||||
public void onGenerate() {
|
||||
super.onGenerate();
|
||||
|
||||
for (int section = minSection; section < maxSection; section++) {
|
||||
getSection(section).blockLight().invalidate();
|
||||
getSection(section).skyLight().invalidate();
|
||||
}
|
||||
|
||||
invalidate();
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
Chunk neighborChunk = instance.getChunk(chunkX + i, chunkZ + j);
|
||||
if (neighborChunk == null) continue;
|
||||
|
||||
if (neighborChunk instanceof LightingChunk light) {
|
||||
for (int section = light.minSection; section < light.maxSection; section++) {
|
||||
light.getSection(section).blockLight().invalidate();
|
||||
light.getSection(section).skyLight().invalidate();
|
||||
}
|
||||
|
||||
light.invalidate();
|
||||
|
||||
light.resendTimer.set(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
doneInit = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -175,11 +227,11 @@ public class LightingChunk extends DynamicChunk {
|
|||
int height = maxY;
|
||||
while (height > minY) {
|
||||
Block block = getBlock(x, height, z, Condition.TYPE);
|
||||
if (block != Block.AIR) highestBlock = Math.max(highestBlock, height);
|
||||
if (checkSkyOcclusion(block)) break;
|
||||
height--;
|
||||
}
|
||||
heightmap[z << 4 | x] = (height + 1);
|
||||
if (height > highestBlock) highestBlock = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,12 +242,12 @@ public class LightingChunk extends DynamicChunk {
|
|||
|
||||
@Override
|
||||
protected LightData createLightData() {
|
||||
if (lightCache.isValid()) {
|
||||
ServerPacket packet = lightCache.packet(ConnectionState.PLAY);
|
||||
return ((UpdateLightPacket) packet).lightData();
|
||||
packetGenerationLock.lock();
|
||||
if (lightData != null) {
|
||||
packetGenerationLock.unlock();
|
||||
return lightData;
|
||||
}
|
||||
|
||||
synchronized (lightCache) {
|
||||
BitSet skyMask = new BitSet();
|
||||
BitSet blockMask = new BitSet();
|
||||
BitSet emptySkyMask = new BitSet();
|
||||
|
@ -203,25 +255,35 @@ public class LightingChunk extends DynamicChunk {
|
|||
List<byte[]> skyLights = new ArrayList<>();
|
||||
List<byte[]> blockLights = new ArrayList<>();
|
||||
|
||||
Set<Chunk> combined = new HashSet<>();
|
||||
int chunkMin = instance.getDimensionType().getMinY();
|
||||
|
||||
int highestNeighborBlock = instance.getDimensionType().getMinY();
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
Chunk neighborChunk = instance.getChunk(chunkX + i, chunkZ + j);
|
||||
if (neighborChunk == null) continue;
|
||||
|
||||
if (neighborChunk instanceof LightingChunk light) {
|
||||
light.getHeightmap();
|
||||
highestNeighborBlock = Math.max(highestNeighborBlock, light.highestBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (Section section : sections) {
|
||||
boolean wasUpdatedBlock = false;
|
||||
boolean wasUpdatedSky = false;
|
||||
|
||||
if (section.blockLight().requiresUpdate()) {
|
||||
var needsSend = relightSection(instance, this.chunkX, index + minSection, chunkZ, LightType.BLOCK);
|
||||
combined.addAll(needsSend);
|
||||
relightSection(instance, this.chunkX, index + minSection, chunkZ, LightType.BLOCK);
|
||||
wasUpdatedBlock = true;
|
||||
} else if (section.blockLight().requiresSend()) {
|
||||
wasUpdatedBlock = true;
|
||||
}
|
||||
|
||||
if (section.skyLight().requiresUpdate()) {
|
||||
var needsSend = relightSection(instance, this.chunkX, index + minSection, chunkZ, LightType.SKY);
|
||||
combined.addAll(needsSend);
|
||||
relightSection(instance, this.chunkX, index + minSection, chunkZ, LightType.SKY);
|
||||
wasUpdatedSky = true;
|
||||
} else if (section.skyLight().requiresSend()) {
|
||||
wasUpdatedSky = true;
|
||||
|
@ -233,7 +295,7 @@ public class LightingChunk extends DynamicChunk {
|
|||
final byte[] blockLight = section.blockLight().array();
|
||||
final int sectionMaxY = index * 16 + chunkMin;
|
||||
|
||||
if ((wasUpdatedSky) && this.instance.getDimensionType().isSkylightEnabled() && sectionMaxY <= (highestBlock + 16)) {
|
||||
if ((wasUpdatedSky) && this.instance.getDimensionType().isSkylightEnabled() && sectionMaxY <= (highestNeighborBlock + 16)) {
|
||||
if (skyLight.length != 0 && skyLight != emptyContent) {
|
||||
skyLights.add(skyLight);
|
||||
skyMask.set(index);
|
||||
|
@ -252,31 +314,23 @@ public class LightingChunk extends DynamicChunk {
|
|||
}
|
||||
}
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {
|
||||
for (Chunk chunk : combined) {
|
||||
if (chunk instanceof LightingChunk light) {
|
||||
if (light.initialLightingSent) {
|
||||
light.lightCache.invalidate();
|
||||
light.chunkCache.invalidate();
|
||||
|
||||
// Compute Lighting. This will ensure lighting is computed even with no players
|
||||
lightCache.body(ConnectionState.PLAY);
|
||||
light.sendLighting();
|
||||
|
||||
light.sections.forEach(s -> {
|
||||
s.blockLight().setRequiresSend(true);
|
||||
s.skyLight().setRequiresSend(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.initialLightingSent = true;
|
||||
});
|
||||
|
||||
return new LightData(skyMask, blockMask,
|
||||
this.lightData = new LightData(skyMask, blockMask,
|
||||
emptySkyMask, emptyBlockMask,
|
||||
skyLights, blockLights);
|
||||
|
||||
packetGenerationLock.unlock();
|
||||
|
||||
return this.lightData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(long time) {
|
||||
super.tick(time);
|
||||
|
||||
if (doneInit && resendTimer.get() > 0) {
|
||||
if (resendTimer.decrementAndGet() == 0) {
|
||||
sendLighting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,8 +398,7 @@ public class LightingChunk extends DynamicChunk {
|
|||
sections.add(new Vec(chunk.getChunkX(), section, chunk.getChunkZ()));
|
||||
}
|
||||
|
||||
lighting.lightCache.invalidate();
|
||||
lighting.chunkCache.invalidate();
|
||||
lighting.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package net.minestom.server.instance;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.FloatUnaryOperator;
|
||||
import net.minestom.server.network.packet.server.SendablePacket;
|
||||
import net.minestom.server.network.packet.server.play.ChangeGameStatePacket;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the possible weather properties of an instance
|
||||
*
|
||||
* @param isRaining true if the instance is raining, otherwise false
|
||||
* @param rainLevel a percentage between 0 and 1
|
||||
* used to change how heavy the rain is
|
||||
* higher values darken the sky and increase rain opacity
|
||||
* @param thunderLevel a percentage between 0 and 1
|
||||
* used to change how heavy the thunder is
|
||||
* higher values further darken the sky
|
||||
*/
|
||||
public record Weather(boolean isRaining, float rainLevel, float thunderLevel) {
|
||||
/**
|
||||
* @throws IllegalArgumentException if {@code rainLevel} is not between 0 and 1
|
||||
* @throws IllegalArgumentException if {@code thunderLevel} is not between 0 and 1
|
||||
*/
|
||||
public Weather {
|
||||
Check.argCondition(!MathUtils.isBetween(rainLevel, 0, 1), "Rain level should be between 0 and 1");
|
||||
Check.argCondition(!MathUtils.isBetween(thunderLevel, 0, 1), "Thunder level should be between 0 and 1");
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public @NotNull Weather withRain(boolean isRaining) {
|
||||
return new Weather(isRaining, rainLevel, thunderLevel);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public @NotNull Weather withRainLevel(float rainLevel) {
|
||||
return new Weather(isRaining, rainLevel, thunderLevel);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public @NotNull Weather withRainLevel(@NotNull FloatUnaryOperator operator) {
|
||||
return withRainLevel(operator.apply(rainLevel));
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public @NotNull Weather withThunderLevel(float thunderLevel) {
|
||||
return new Weather(isRaining, rainLevel, thunderLevel);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public @NotNull Weather withThunderLevel(@NotNull FloatUnaryOperator operator) {
|
||||
return withRainLevel(operator.apply(thunderLevel));
|
||||
}
|
||||
|
||||
public ChangeGameStatePacket createIsRainingPacket() {
|
||||
return new ChangeGameStatePacket(isRaining ? ChangeGameStatePacket.Reason.BEGIN_RAINING : ChangeGameStatePacket.Reason.END_RAINING, 0);
|
||||
}
|
||||
|
||||
public ChangeGameStatePacket createRainLevelPacket() {
|
||||
return new ChangeGameStatePacket(ChangeGameStatePacket.Reason.RAIN_LEVEL_CHANGE, rainLevel);
|
||||
}
|
||||
|
||||
public ChangeGameStatePacket createThunderLevelPacket() {
|
||||
return new ChangeGameStatePacket(ChangeGameStatePacket.Reason.THUNDER_LEVEL_CHANGE, thunderLevel);
|
||||
}
|
||||
|
||||
public @NotNull Collection<SendablePacket> createWeatherPackets() {
|
||||
return List.of(createIsRainingPacket(), createRainLevelPacket(), createThunderLevelPacket());
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ final class BlockLight implements Light {
|
|||
private byte[] contentPropagation;
|
||||
private byte[] contentPropagationSwap;
|
||||
|
||||
private boolean isValidBorders = false;
|
||||
private boolean isValidBorders = true;
|
||||
private boolean needsSend = true;
|
||||
|
||||
private Set<Point> toUpdateSet = new HashSet<>();
|
||||
|
@ -34,27 +34,6 @@ final class BlockLight implements Light {
|
|||
this.blockPalette = blockPalette;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void setInternalLighting(byte[] content) {
|
||||
this.content = content;
|
||||
this.isValidBorders = true;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void setExternalLighting(byte[] content) {
|
||||
this.contentPropagation = content;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public byte[] getInternalLighting() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public byte[] getExternalLighting() {
|
||||
return contentPropagation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Point> flip() {
|
||||
if (this.contentPropagationSwap != null)
|
||||
|
@ -164,12 +143,6 @@ final class BlockLight implements Light {
|
|||
return lightSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyFrom(byte @NotNull [] array) {
|
||||
if (array.length == 0) this.content = null;
|
||||
else this.content = array.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Light calculateInternal(Instance instance, int chunkX, int sectionY, int chunkZ) {
|
||||
Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
||||
|
@ -223,7 +196,13 @@ final class BlockLight implements Light {
|
|||
|
||||
@Override
|
||||
public void set(byte[] copyArray) {
|
||||
if (copyArray.length == 0) {
|
||||
this.content = emptyContent;
|
||||
this.contentPropagation = emptyContent;
|
||||
} else {
|
||||
this.content = copyArray.clone();
|
||||
this.contentPropagation = this.content;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,11 +212,6 @@ final class BlockLight implements Light {
|
|||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequiresSend(boolean b) {
|
||||
this.needsSend = b;
|
||||
}
|
||||
|
||||
private void clearCache() {
|
||||
this.contentPropagation = null;
|
||||
isValidBorders = true;
|
||||
|
|
|
@ -27,15 +27,12 @@ public interface Light {
|
|||
}
|
||||
|
||||
boolean requiresSend();
|
||||
void setRequiresSend(boolean b);
|
||||
|
||||
@ApiStatus.Internal
|
||||
byte[] array();
|
||||
|
||||
Set<Point> flip();
|
||||
|
||||
void copyFrom(byte @NotNull [] array);
|
||||
|
||||
@ApiStatus.Internal
|
||||
Light calculateExternal(Instance instance, Chunk chunk, int sectionY);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ final class SkyLight implements Light {
|
|||
private byte[] contentPropagation;
|
||||
private byte[] contentPropagationSwap;
|
||||
|
||||
private boolean isValidBorders = false;
|
||||
private boolean isValidBorders = true;
|
||||
private boolean needsSend = true;
|
||||
|
||||
private Set<Point> toUpdateSet = new HashSet<>();
|
||||
|
@ -160,12 +160,6 @@ final class SkyLight implements Light {
|
|||
return lightSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyFrom(byte @NotNull [] array) {
|
||||
if (array.length == 0) this.content = null;
|
||||
else this.content = array.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Light calculateInternal(Instance instance, int chunkX, int sectionY, int chunkZ) {
|
||||
Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
||||
|
@ -228,7 +222,13 @@ final class SkyLight implements Light {
|
|||
|
||||
@Override
|
||||
public void set(byte[] copyArray) {
|
||||
if (copyArray.length == 0) {
|
||||
this.content = emptyContent;
|
||||
this.contentPropagation = emptyContent;
|
||||
} else {
|
||||
this.content = copyArray.clone();
|
||||
this.contentPropagation = this.content;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,11 +238,6 @@ final class SkyLight implements Light {
|
|||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequiresSend(boolean b) {
|
||||
this.needsSend = b;
|
||||
}
|
||||
|
||||
private void clearCache() {
|
||||
this.contentPropagation = null;
|
||||
isValidBorders = true;
|
||||
|
|
|
@ -18,6 +18,11 @@ public final class CreativeInventoryActionListener {
|
|||
player.dropItem(item);
|
||||
return;
|
||||
}
|
||||
// Bounds check
|
||||
// 0 is crafting result inventory slot, ignore attempts to place into it
|
||||
if (slot < 1 || slot > PlayerInventoryUtils.OFFHAND_SLOT) {
|
||||
return;
|
||||
}
|
||||
// Set item
|
||||
slot = (short) PlayerInventoryUtils.convertPlayerInventorySlot(slot, PlayerInventoryUtils.OFFSET);
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
package net.minestom.server.network;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.metadata.animal.FrogMeta;
|
||||
import net.minestom.server.entity.metadata.animal.SnifferMeta;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
|
||||
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.data.DeathLocation;
|
||||
import net.minestom.server.particle.Particle;
|
||||
|
@ -29,6 +22,7 @@ import org.jglrxavpok.hephaistos.nbt.NBTWriter;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
@ -73,6 +67,7 @@ public final class NetworkBuffer {
|
|||
public static final Type<DeathLocation> DEATH_LOCATION = NetworkBufferTypes.DEATH_LOCATION;
|
||||
public static final Type<CatMeta.Variant> CAT_VARIANT = NetworkBufferTypes.CAT_VARIANT;
|
||||
public static final Type<FrogMeta.Variant> FROG_VARIANT = NetworkBufferTypes.FROG_VARIANT;
|
||||
public static final Type<PaintingMeta.Variant> PAINTING_VARIANT = NetworkBufferTypes.PAINTING_VARIANT;
|
||||
public static final Type<SnifferMeta.State> SNIFFER_STATE = NetworkBufferTypes.SNIFFER_STATE;
|
||||
public static final Type<Point> VECTOR3 = NetworkBufferTypes.VECTOR3;
|
||||
public static final Type<Point> VECTOR3D = NetworkBufferTypes.VECTOR3D;
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.minestom.server.entity.Entity;
|
|||
import net.minestom.server.entity.metadata.animal.FrogMeta;
|
||||
import net.minestom.server.entity.metadata.animal.SnifferMeta;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
|
||||
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.packet.server.play.data.DeathLocation;
|
||||
|
@ -578,6 +579,15 @@ final class NetworkBufferTypes {
|
|||
final int ordinal = buffer.read(VAR_INT);
|
||||
return FrogMeta.Variant.values()[ordinal];
|
||||
});
|
||||
static final TypeImpl<PaintingMeta.Variant> PAINTING_VARIANT = new TypeImpl<>(PaintingMeta.Variant.class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.ordinal());
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int ordinal = buffer.read(VAR_INT);
|
||||
return PaintingMeta.Variant.values()[ordinal];
|
||||
});
|
||||
static final TypeImpl<SnifferMeta.State> SNIFFER_STATE = new TypeImpl<>(SnifferMeta.State.class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.ordinal());
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package net.minestom.server.network.packet.client;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a packet received from a client.
|
||||
|
@ -10,8 +8,4 @@ import org.jetbrains.annotations.Nullable;
|
|||
* Packets are value-based, and should therefore not be reliant on identity.
|
||||
*/
|
||||
public interface ClientPacket extends NetworkBuffer.Writer {
|
||||
|
||||
default @Nullable ConnectionState nextState() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ClientConfigurationAckPacket() implements ClientPacket {
|
||||
|
||||
public ClientConfigurationAckPacket(@NotNull NetworkBuffer buffer) {
|
||||
this();
|
||||
}
|
||||
|
@ -14,9 +12,4 @@ public record ClientConfigurationAckPacket() implements ClientPacket {
|
|||
@Override
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConnectionState nextState() {
|
||||
return ConnectionState.CONFIGURATION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package net.minestom.server.network.packet.server;
|
||||
|
||||
import net.minestom.server.adventure.ComponentHolder;
|
||||
|
||||
/**
|
||||
* A server packet that can hold components.
|
||||
*/
|
||||
public interface ComponentHoldingServerPacket extends ServerPacket, ComponentHolder<ServerPacket> { }
|
|
@ -1,17 +1,22 @@
|
|||
package net.minestom.server.network.packet.server;
|
||||
|
||||
import net.minestom.server.adventure.ComponentHolder;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a packet which can be sent to a player using {@link PlayerConnection#sendPacket(SendablePacket)}.
|
||||
* <p>
|
||||
* Packets are value-based, and should therefore not be reliant on identity.
|
||||
*/
|
||||
public non-sealed interface ServerPacket extends NetworkBuffer.Writer, SendablePacket {
|
||||
public sealed interface ServerPacket extends NetworkBuffer.Writer, SendablePacket permits
|
||||
ServerPacket.Configuration, ServerPacket.Status, ServerPacket.Login, ServerPacket.Play {
|
||||
|
||||
/**
|
||||
* Gets the id of this packet.
|
||||
|
@ -20,6 +25,40 @@ public non-sealed interface ServerPacket extends NetworkBuffer.Writer, SendableP
|
|||
*
|
||||
* @return the id of this packet
|
||||
*/
|
||||
int getId(@NotNull ConnectionState state);
|
||||
default int getId(@NotNull ConnectionState state) {
|
||||
final int id = switch (state) {
|
||||
case HANDSHAKE -> -1;
|
||||
case CONFIGURATION -> this instanceof Configuration configuration ? configuration.configurationId() : -1;
|
||||
case STATUS -> this instanceof Status status ? status.statusId() : -1;
|
||||
case LOGIN -> this instanceof Login login ? login.loginId() : -1;
|
||||
case PLAY -> this instanceof Play play ? play.playId() : -1;
|
||||
};
|
||||
if (id != -1) return id;
|
||||
// Invalid state, generate error
|
||||
List<ConnectionState> validStates = new ArrayList<>();
|
||||
if (this instanceof Configuration) validStates.add(ConnectionState.CONFIGURATION);
|
||||
if (this instanceof Status) validStates.add(ConnectionState.STATUS);
|
||||
if (this instanceof Login) validStates.add(ConnectionState.LOGIN);
|
||||
if (this instanceof Play) validStates.add(ConnectionState.PLAY);
|
||||
return PacketUtils.invalidPacketState(getClass(), state, validStates.toArray(ConnectionState[]::new));
|
||||
}
|
||||
|
||||
non-sealed interface Configuration extends ServerPacket {
|
||||
int configurationId();
|
||||
}
|
||||
|
||||
non-sealed interface Status extends ServerPacket {
|
||||
int statusId();
|
||||
}
|
||||
|
||||
non-sealed interface Login extends ServerPacket {
|
||||
int loginId();
|
||||
}
|
||||
|
||||
non-sealed interface Play extends ServerPacket {
|
||||
int playId();
|
||||
}
|
||||
|
||||
interface ComponentHolding extends ComponentHolder<ServerPacket> {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package net.minestom.server.network.packet.server.common;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -15,7 +12,8 @@ import java.util.function.UnaryOperator;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
|
||||
|
||||
public record DisconnectPacket(@NotNull Component message) implements ComponentHoldingServerPacket {
|
||||
public record DisconnectPacket(@NotNull Component message) implements ServerPacket.Configuration, ServerPacket.Play,
|
||||
ServerPacket.ComponentHolding {
|
||||
public DisconnectPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT));
|
||||
}
|
||||
|
@ -26,12 +24,13 @@ public record DisconnectPacket(@NotNull Component message) implements ComponentH
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_DISCONNECT;
|
||||
case PLAY -> ServerPacketIdentifier.DISCONNECT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_DISCONNECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DISCONNECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.common;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.LONG;
|
||||
|
||||
public record KeepAlivePacket(long id) implements ServerPacket {
|
||||
public record KeepAlivePacket(long id) implements ServerPacket.Configuration, ServerPacket.Play {
|
||||
public KeepAlivePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(LONG));
|
||||
}
|
||||
|
@ -20,11 +18,12 @@ public record KeepAlivePacket(long id) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_KEEP_ALIVE;
|
||||
case PLAY -> ServerPacketIdentifier.KEEP_ALIVE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_KEEP_ALIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.KEEP_ALIVE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.common;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record PingPacket(int id) implements ServerPacket {
|
||||
public record PingPacket(int id) implements ServerPacket.Configuration, ServerPacket.Play {
|
||||
public PingPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT));
|
||||
}
|
||||
|
@ -20,11 +18,12 @@ public record PingPacket(int id) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_PING;
|
||||
case PLAY -> ServerPacketIdentifier.PING;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_PING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.PING;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.common;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.LONG;
|
||||
|
||||
public record PingResponsePacket(long number) implements ServerPacket {
|
||||
public record PingResponsePacket(long number) implements ServerPacket.Status, ServerPacket.Play {
|
||||
public PingResponsePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(LONG));
|
||||
}
|
||||
|
@ -20,11 +18,12 @@ public record PingResponsePacket(long number) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case STATUS -> ServerPacketIdentifier.STATUS_PING_RESPONSE;
|
||||
case PLAY -> ServerPacketIdentifier.PING_RESPONSE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.STATUS);
|
||||
};
|
||||
public int statusId() {
|
||||
return ServerPacketIdentifier.STATUS_PING_RESPONSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.PING_RESPONSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package net.minestom.server.network.packet.server.common;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.RAW_BYTES;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record PluginMessagePacket(String channel, byte[] data) implements ServerPacket {
|
||||
public record PluginMessagePacket(String channel,
|
||||
byte[] data) implements ServerPacket.Configuration, ServerPacket.Play {
|
||||
public PluginMessagePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), reader.read(RAW_BYTES));
|
||||
}
|
||||
|
@ -23,12 +22,13 @@ public record PluginMessagePacket(String channel, byte[] data) implements Server
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_PLUGIN_MESSAGE;
|
||||
case PLAY -> ServerPacketIdentifier.PLUGIN_MESSAGE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_PLUGIN_MESSAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.PLUGIN_MESSAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.common;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ResourcePackPopPacket(@Nullable UUID id) implements ServerPacket {
|
||||
|
||||
public record ResourcePackPopPacket(@Nullable UUID id) implements ServerPacket.Configuration, ServerPacket.Play {
|
||||
public ResourcePackPopPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readOptional(NetworkBuffer.UUID));
|
||||
}
|
||||
|
@ -22,11 +19,12 @@ public record ResourcePackPopPacket(@Nullable UUID id) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_POP_PACKET;
|
||||
case PLAY -> ServerPacketIdentifier.RESOURCE_PACK_POP;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_POP_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.RESOURCE_PACK_POP;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,9 @@ package net.minestom.server.network.packet.server.common;
|
|||
|
||||
import net.kyori.adventure.resource.ResourcePackInfo;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -24,7 +21,7 @@ public record ResourcePackPushPacket(
|
|||
@NotNull String hash,
|
||||
boolean forced,
|
||||
@Nullable Component prompt
|
||||
) implements ComponentHoldingServerPacket {
|
||||
) implements ServerPacket.Configuration, ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public ResourcePackPushPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(UUID), reader.read(STRING), reader.read(STRING),
|
||||
reader.read(BOOLEAN), reader.readOptional(COMPONENT));
|
||||
|
@ -44,12 +41,13 @@ public record ResourcePackPushPacket(
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_PUSH_PACKET;
|
||||
case PLAY -> ServerPacketIdentifier.RESOURCE_PACK_PUSH;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_PUSH_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.RESOURCE_PACK_PUSH;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.common;
|
|||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.gamedata.tags.Tag;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.CachedPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -17,7 +15,8 @@ import java.util.Map;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record TagsPacket(@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) implements ServerPacket {
|
||||
public record TagsPacket(
|
||||
@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) implements ServerPacket.Configuration, ServerPacket.Play {
|
||||
@ApiStatus.Internal
|
||||
public static final CachedPacket DEFAULT_TAGS = new CachedPacket(new TagsPacket(MinecraftServer.getTagManager().getTagMap()));
|
||||
|
||||
|
@ -49,12 +48,13 @@ public record TagsPacket(@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_TAGS;
|
||||
case PLAY -> ServerPacketIdentifier.TAGS;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_TAGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.TAGS;
|
||||
}
|
||||
|
||||
private static Map<Tag.BasicType, List<Tag>> readTagsMap(@NotNull NetworkBuffer reader) {
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package net.minestom.server.network.packet.server.configuration;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record FinishConfigurationPacket() implements ServerPacket {
|
||||
|
||||
public record FinishConfigurationPacket() implements ServerPacket.Configuration {
|
||||
public FinishConfigurationPacket(@NotNull NetworkBuffer buffer) {
|
||||
this();
|
||||
}
|
||||
|
@ -18,10 +15,7 @@ public record FinishConfigurationPacket() implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_FINISH_CONFIGURATION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_FINISH_CONFIGURATION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.configuration;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.NBT;
|
||||
|
||||
public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPacket {
|
||||
|
||||
public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPacket.Configuration {
|
||||
public RegistryDataPacket(@NotNull NetworkBuffer buffer) {
|
||||
this((NBTCompound) buffer.read(NBT));
|
||||
}
|
||||
|
@ -22,10 +19,7 @@ public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPac
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_REGISTRY_DATA;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_REGISTRY_DATA;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
package net.minestom.server.network.packet.server.configuration;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record UpdateEnabledFeaturesPacket(@NotNull Set<NamespaceID> features) implements ServerPacket {
|
||||
public record UpdateEnabledFeaturesPacket(@NotNull Set<NamespaceID> features) implements ServerPacket.Configuration {
|
||||
public static final int MAX_FEATURES = 1024;
|
||||
|
||||
public UpdateEnabledFeaturesPacket(@NotNull NetworkBuffer buffer) {
|
||||
|
@ -25,11 +23,7 @@ public record UpdateEnabledFeaturesPacket(@NotNull Set<NamespaceID> features) im
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_UPDATE_ENABLED_FEATURES;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION);
|
||||
};
|
||||
public int configurationId() {
|
||||
return ServerPacketIdentifier.CONFIGURATION_UPDATE_ENABLED_FEATURES;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE_ARRAY;
|
||||
|
@ -12,7 +10,7 @@ import static net.minestom.server.network.NetworkBuffer.STRING;
|
|||
|
||||
public record EncryptionRequestPacket(@NotNull String serverId,
|
||||
byte @NotNull [] publicKey,
|
||||
byte @NotNull [] verifyToken) implements ServerPacket {
|
||||
byte @NotNull [] verifyToken) implements ServerPacket.Login {
|
||||
public EncryptionRequestPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING),
|
||||
reader.read(BYTE_ARRAY),
|
||||
|
@ -27,10 +25,7 @@ public record EncryptionRequestPacket(@NotNull String serverId,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case LOGIN -> ServerPacketIdentifier.LOGIN_ENCRYPTION_REQUEST;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
|
||||
};
|
||||
public int loginId() {
|
||||
return ServerPacketIdentifier.LOGIN_ENCRYPTION_REQUEST;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -14,7 +12,8 @@ import java.util.function.UnaryOperator;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.JSON_COMPONENT;
|
||||
|
||||
public record LoginDisconnectPacket(@NotNull Component kickMessage) implements ComponentHoldingServerPacket {
|
||||
public record LoginDisconnectPacket(@NotNull Component kickMessage) implements ServerPacket.Login,
|
||||
ServerPacket.ComponentHolding {
|
||||
public LoginDisconnectPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(JSON_COMPONENT));
|
||||
}
|
||||
|
@ -25,11 +24,8 @@ public record LoginDisconnectPacket(@NotNull Component kickMessage) implements C
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case LOGIN -> ServerPacketIdentifier.LOGIN_DISCONNECT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
|
||||
};
|
||||
public int loginId() {
|
||||
return ServerPacketIdentifier.LOGIN_DISCONNECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record LoginPluginRequestPacket(int messageId, @NotNull String channel,
|
||||
byte @Nullable [] data) implements ServerPacket {
|
||||
byte @Nullable [] data) implements ServerPacket.Login {
|
||||
public LoginPluginRequestPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(STRING),
|
||||
reader.read(RAW_BYTES));
|
||||
|
@ -27,10 +25,7 @@ public record LoginPluginRequestPacket(int messageId, @NotNull String channel,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case LOGIN -> ServerPacketIdentifier.LOGIN_PLUGIN_REQUEST;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
|
||||
};
|
||||
public int loginId() {
|
||||
return ServerPacketIdentifier.LOGIN_PLUGIN_REQUEST;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -12,7 +10,8 @@ import java.util.UUID;
|
|||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username, int properties) implements ServerPacket {
|
||||
public record LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username,
|
||||
int properties) implements ServerPacket.Login {
|
||||
public LoginSuccessPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), reader.read(STRING), reader.read(VAR_INT));
|
||||
}
|
||||
|
@ -25,10 +24,7 @@ public record LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username, i
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case LOGIN -> ServerPacketIdentifier.LOGIN_SUCCESS;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
|
||||
};
|
||||
public int loginId() {
|
||||
return ServerPacketIdentifier.LOGIN_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record SetCompressionPacket(int threshold) implements ServerPacket {
|
||||
public record SetCompressionPacket(int threshold) implements ServerPacket.Login {
|
||||
public SetCompressionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
@ -20,10 +18,7 @@ public record SetCompressionPacket(int threshold) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case LOGIN -> ServerPacketIdentifier.LOGIN_SET_COMPRESSION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
|
||||
};
|
||||
public int loginId() {
|
||||
return ServerPacketIdentifier.LOGIN_SET_COMPRESSION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket {
|
||||
public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket.Play {
|
||||
public AcknowledgeBlockChangePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
@ -20,10 +18,7 @@ public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ACKNOWLEDGE_BLOCK_CHANGE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ACKNOWLEDGE_BLOCK_CHANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -15,7 +12,7 @@ import java.util.function.UnaryOperator;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
|
||||
|
||||
public record ActionBarPacket(@NotNull Component text) implements ComponentHoldingServerPacket {
|
||||
public record ActionBarPacket(@NotNull Component text) implements ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public ActionBarPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT));
|
||||
}
|
||||
|
@ -26,11 +23,8 @@ public record ActionBarPacket(@NotNull Component text) implements ComponentHoldi
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ACTION_BAR;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ACTION_BAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,12 +4,10 @@ import net.kyori.adventure.text.Component;
|
|||
import net.minestom.server.advancements.FrameType;
|
||||
import net.minestom.server.adventure.ComponentHolder;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -23,7 +21,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
|
|||
|
||||
public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping> advancementMappings,
|
||||
@NotNull List<String> identifiersToRemove,
|
||||
@NotNull List<ProgressMapping> progressMappings) implements ComponentHoldingServerPacket {
|
||||
@NotNull List<ProgressMapping> progressMappings) implements ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public static final int MAX_ADVANCEMENTS = Short.MAX_VALUE;
|
||||
|
||||
public AdvancementsPacket {
|
||||
|
@ -47,11 +45,8 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ADVANCEMENTS;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ADVANCEMENTS;
|
||||
}
|
||||
|
||||
// TODO is the display-item needed to be updated?
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record AttachEntityPacket(int attachedEntityId, int holdingEntityId) implements ServerPacket {
|
||||
public record AttachEntityPacket(int attachedEntityId, int holdingEntityId) implements ServerPacket.Play {
|
||||
public AttachEntityPacket(@NotNull Entity attachedEntity, @Nullable Entity holdingEntity) {
|
||||
this(attachedEntity.getEntityId(), holdingEntity != null ? holdingEntity.getEntityId() : -1);
|
||||
}
|
||||
|
@ -27,10 +25,7 @@ public record AttachEntityPacket(int attachedEntityId, int holdingEntityId) impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ATTACH_ENTITY;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ATTACH_ENTITY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,15 @@ package net.minestom.server.network.packet.server.play;
|
|||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BlockActionPacket(@NotNull Point blockPosition, byte actionId,
|
||||
byte actionParam, int blockId) implements ServerPacket {
|
||||
byte actionParam, int blockId) implements ServerPacket.Play {
|
||||
public BlockActionPacket(Point blockPosition, byte actionId, byte actionParam, Block block) {
|
||||
this(blockPosition, actionId, actionParam, block.id());
|
||||
}
|
||||
|
@ -31,10 +29,7 @@ public record BlockActionPacket(@NotNull Point blockPosition, byte actionId,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.BLOCK_ACTION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.BLOCK_ACTION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BlockBreakAnimationPacket(int entityId, @NotNull Point blockPosition,
|
||||
byte destroyStage) implements ServerPacket {
|
||||
byte destroyStage) implements ServerPacket.Play {
|
||||
public BlockBreakAnimationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(BLOCK_POSITION), reader.read(BYTE));
|
||||
}
|
||||
|
@ -24,10 +22,7 @@ public record BlockBreakAnimationPacket(int entityId, @NotNull Point blockPositi
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.BLOCK_BREAK_ANIMATION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.BLOCK_BREAK_ANIMATION;
|
||||
}
|
||||
}
|
|
@ -2,17 +2,15 @@ package net.minestom.server.network.packet.server.play;
|
|||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BLOCK_POSITION;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record BlockChangePacket(@NotNull Point blockPosition, int blockStateId) implements ServerPacket {
|
||||
public record BlockChangePacket(@NotNull Point blockPosition, int blockStateId) implements ServerPacket.Play {
|
||||
public BlockChangePacket(@NotNull Point blockPosition, @NotNull Block block) {
|
||||
this(blockPosition, block.stateId());
|
||||
}
|
||||
|
@ -28,10 +26,7 @@ public record BlockChangePacket(@NotNull Point blockPosition, int blockStateId)
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.BLOCK_CHANGE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.BLOCK_CHANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
@ -13,7 +11,7 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
|||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BlockEntityDataPacket(@NotNull Point blockPosition, int action,
|
||||
@Nullable NBTCompound data) implements ServerPacket {
|
||||
@Nullable NBTCompound data) implements ServerPacket.Play {
|
||||
public BlockEntityDataPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.read(VAR_INT), (NBTCompound) reader.read(NBT));
|
||||
}
|
||||
|
@ -31,10 +29,7 @@ public record BlockEntityDataPacket(@NotNull Point blockPosition, int action,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.BLOCK_ENTITY_DATA;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.BLOCK_ENTITY_DATA;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,10 @@ import net.kyori.adventure.bossbar.BossBar;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.adventure.AdventurePacketConvertor;
|
||||
import net.minestom.server.adventure.ComponentHolder;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -19,7 +17,7 @@ import java.util.function.UnaryOperator;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implements ComponentHoldingServerPacket {
|
||||
public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implements ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public BossBarPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), switch (reader.read(VAR_INT)) {
|
||||
case 0 -> new AddAction(reader);
|
||||
|
@ -201,10 +199,7 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.BOSS_BAR;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.BOSS_BAR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record BundlePacket() implements ServerPacket {
|
||||
public record BundlePacket() implements ServerPacket.Play {
|
||||
public BundlePacket(@NotNull NetworkBuffer reader) {
|
||||
this();
|
||||
}
|
||||
|
@ -17,10 +15,7 @@ public record BundlePacket() implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.BUNDLE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.BUNDLE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record CameraPacket(int cameraId) implements ServerPacket {
|
||||
public record CameraPacket(int cameraId) implements ServerPacket.Play {
|
||||
public CameraPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
@ -25,10 +23,7 @@ public record CameraPacket(int cameraId) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CAMERA;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CAMERA;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.FLOAT;
|
||||
|
||||
public record ChangeGameStatePacket(@NotNull Reason reason, float value) implements ServerPacket {
|
||||
public record ChangeGameStatePacket(@NotNull Reason reason, float value) implements ServerPacket.Play {
|
||||
public ChangeGameStatePacket(@NotNull NetworkBuffer reader) {
|
||||
this(Reason.values()[reader.read(BYTE)], reader.read(FLOAT));
|
||||
}
|
||||
|
@ -22,11 +20,8 @@ public record ChangeGameStatePacket(@NotNull Reason reason, float value) impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CHANGE_GAME_STATE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CHANGE_GAME_STATE;
|
||||
}
|
||||
|
||||
public enum Reason {
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket {
|
||||
|
||||
public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket.Play {
|
||||
public ChunkBatchFinishedPacket(@NotNull NetworkBuffer buffer) {
|
||||
this(buffer.read(VAR_INT));
|
||||
}
|
||||
|
@ -21,10 +18,7 @@ public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CHUNK_BATCH_FINISHED;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CHUNK_BATCH_FINISHED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ChunkBatchStartPacket() implements ServerPacket {
|
||||
|
||||
public record ChunkBatchStartPacket() implements ServerPacket.Play {
|
||||
public ChunkBatchStartPacket(@NotNull NetworkBuffer buffer) {
|
||||
this();
|
||||
}
|
||||
|
@ -18,10 +15,7 @@ public record ChunkBatchStartPacket() implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CHUNK_BATCH_START;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CHUNK_BATCH_START;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.network.packet.server.play.data.ChunkData;
|
||||
import net.minestom.server.network.packet.server.play.data.LightData;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record ChunkDataPacket(int chunkX, int chunkZ,
|
||||
@NotNull ChunkData chunkData,
|
||||
@NotNull LightData lightData) implements ServerPacket {
|
||||
@NotNull LightData lightData) implements ServerPacket.Play {
|
||||
public ChunkDataPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.read(INT),
|
||||
new ChunkData(reader),
|
||||
|
@ -29,10 +27,7 @@ public record ChunkDataPacket(int chunkX, int chunkZ,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CHUNK_DATA;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CHUNK_DATA;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
|
||||
public record ClearTitlesPacket(boolean reset) implements ServerPacket {
|
||||
public record ClearTitlesPacket(boolean reset) implements ServerPacket.Play {
|
||||
public ClearTitlesPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN));
|
||||
}
|
||||
|
@ -20,10 +18,7 @@ public record ClearTitlesPacket(boolean reset) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CLEAR_TITLES;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CLEAR_TITLES;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
|
||||
public record CloseWindowPacket(byte windowId) implements ServerPacket {
|
||||
public record CloseWindowPacket(byte windowId) implements ServerPacket.Play {
|
||||
public CloseWindowPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE));
|
||||
}
|
||||
|
@ -20,10 +18,7 @@ public record CloseWindowPacket(byte windowId) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CLOSE_WINDOW;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CLOSE_WINDOW;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record CollectItemPacket(int collectedEntityId, int collectorEntityId, int pickupItemCount)
|
||||
implements ServerPacket {
|
||||
implements ServerPacket.Play {
|
||||
public CollectItemPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT));
|
||||
}
|
||||
|
@ -23,10 +21,7 @@ public record CollectItemPacket(int collectedEntityId, int collectorEntityId, in
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.COLLECT_ITEM;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.COLLECT_ITEM;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record CraftRecipeResponse(byte windowId, String recipe) implements ServerPacket {
|
||||
public record CraftRecipeResponse(byte windowId, String recipe) implements ServerPacket.Play {
|
||||
public CraftRecipeResponse(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE), reader.read(STRING));
|
||||
}
|
||||
|
@ -22,10 +20,7 @@ public record CraftRecipeResponse(byte windowId, String recipe) implements Serve
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CRAFT_RECIPE_RESPONSE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CRAFT_RECIPE_RESPONSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -12,7 +10,7 @@ import java.util.List;
|
|||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record CustomChatCompletionPacket(@NotNull Action action,
|
||||
@NotNull List<@NotNull String> entries) implements ServerPacket {
|
||||
@NotNull List<@NotNull String> entries) implements ServerPacket.Play {
|
||||
public static final int MAX_ENTRIES = Short.MAX_VALUE;
|
||||
|
||||
public CustomChatCompletionPacket {
|
||||
|
@ -30,11 +28,8 @@ public record CustomChatCompletionPacket(@NotNull Action action,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.CUSTOM_CHAT_COMPLETIONS;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.CUSTOM_CHAT_COMPLETIONS;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
import static net.minestom.server.network.NetworkBuffer.VECTOR3D;
|
||||
|
||||
/**
|
||||
* See <a href="https://wiki.vg/Protocol#Damage_Event">https://wiki.vg/Protocol#Damage_Event</a> for more info.
|
||||
|
@ -20,18 +19,16 @@ import static net.minestom.server.network.NetworkBuffer.*;
|
|||
* @param sourceDirectId 0 if there is no direct source. For direct attacks (e.g. melee), this is the same as sourceEntityId. For indirect attacks (e.g. projectiles), this is the projectile entity id + 1
|
||||
* @param sourcePos null if there is no source position, otherwise the position of the source
|
||||
*/
|
||||
public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId, @Nullable Point sourcePos) implements ServerPacket {
|
||||
public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId,
|
||||
@Nullable Point sourcePos) implements ServerPacket.Play {
|
||||
|
||||
public DamageEventPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.readOptional(VECTOR3D));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DAMAGE_EVENT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DAMAGE_EVENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -15,7 +13,7 @@ import java.util.function.UnaryOperator;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record DeathCombatEventPacket(int playerId, @NotNull Component message) implements ComponentHoldingServerPacket {
|
||||
public record DeathCombatEventPacket(int playerId, @NotNull Component message) implements ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public DeathCombatEventPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(COMPONENT));
|
||||
}
|
||||
|
@ -27,11 +25,8 @@ public record DeathCombatEventPacket(int playerId, @NotNull Component message) i
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DEATH_COMBAT_EVENT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DEATH_COMBAT_EVENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.registry.StaticProtocolObject;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,7 +13,7 @@ import java.util.function.Function;
|
|||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record DeclareCommandsPacket(@NotNull List<Node> nodes,
|
||||
int rootIndex) implements ServerPacket {
|
||||
int rootIndex) implements ServerPacket.Play {
|
||||
public static final int MAX_NODES = Short.MAX_VALUE;
|
||||
|
||||
public DeclareCommandsPacket {
|
||||
|
@ -37,11 +35,8 @@ public record DeclareCommandsPacket(@NotNull List<Node> nodes,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DECLARE_COMMANDS;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DECLARE_COMMANDS;
|
||||
}
|
||||
|
||||
public static final class Node implements NetworkBuffer.Writer {
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.recipe.RecipeCategory;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -15,7 +13,7 @@ import java.util.List;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implements ServerPacket {
|
||||
public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implements ServerPacket.Play {
|
||||
public static final int MAX_RECIPES = Short.MAX_VALUE;
|
||||
public static final int MAX_INGREDIENTS = 128;
|
||||
|
||||
|
@ -51,11 +49,8 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DECLARE_RECIPES;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DECLARE_RECIPES;
|
||||
}
|
||||
|
||||
public sealed interface DeclaredRecipe extends NetworkBuffer.Writer
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.crypto.MessageSignature;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record DeleteChatPacket(@NotNull MessageSignature signature) implements ServerPacket {
|
||||
public record DeleteChatPacket(@NotNull MessageSignature signature) implements ServerPacket.Play {
|
||||
public DeleteChatPacket(@NotNull NetworkBuffer reader) {
|
||||
this(new MessageSignature(reader));
|
||||
}
|
||||
|
@ -19,10 +17,7 @@ public record DeleteChatPacket(@NotNull MessageSignature signature) implements S
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DELETE_CHAT_MESSAGE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DELETE_CHAT_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record DestroyEntitiesPacket(@NotNull List<Integer> entityIds) implements ServerPacket {
|
||||
public record DestroyEntitiesPacket(@NotNull List<Integer> entityIds) implements ServerPacket.Play {
|
||||
public static final int MAX_ENTRIES = Short.MAX_VALUE;
|
||||
|
||||
public DestroyEntitiesPacket {
|
||||
|
@ -32,10 +30,7 @@ public record DestroyEntitiesPacket(@NotNull List<Integer> entityIds) implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DESTROY_ENTITIES;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DESTROY_ENTITIES;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record DisplayScoreboardPacket(byte position, String scoreName) implements ServerPacket {
|
||||
public record DisplayScoreboardPacket(byte position, String scoreName) implements ServerPacket.Play {
|
||||
public DisplayScoreboardPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE), reader.read(STRING));
|
||||
}
|
||||
|
@ -22,10 +20,7 @@ public record DisplayScoreboardPacket(byte position, String scoreName) implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.DISPLAY_SCOREBOARD;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.DISPLAY_SCOREBOARD;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EffectPacket(int effectId, Point position, int data,
|
||||
boolean disableRelativeVolume) implements ServerPacket {
|
||||
boolean disableRelativeVolume) implements ServerPacket.Play {
|
||||
public EffectPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.read(BLOCK_POSITION), reader.read(INT), reader.read(BOOLEAN));
|
||||
}
|
||||
|
@ -25,10 +23,7 @@ public record EffectPacket(int effectId, Point position, int data,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.EFFECT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.EFFECT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record EndCombatEventPacket(int duration) implements ServerPacket {
|
||||
public record EndCombatEventPacket(int duration) implements ServerPacket.Play {
|
||||
public EndCombatEventPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
@ -20,10 +18,7 @@ public record EndCombatEventPacket(int duration) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.END_COMBAT_EVENT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.END_COMBAT_EVENT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record EnterCombatEventPacket() implements ServerPacket {
|
||||
public record EnterCombatEventPacket() implements ServerPacket.Play {
|
||||
public EnterCombatEventPacket(@NotNull NetworkBuffer reader) {
|
||||
this();
|
||||
}
|
||||
|
@ -18,10 +16,7 @@ public record EnterCombatEventPacket() implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTER_COMBAT_EVENT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTER_COMBAT_EVENT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record EntityAnimationPacket(int entityId, @NotNull Animation animation) implements ServerPacket {
|
||||
public record EntityAnimationPacket(int entityId, @NotNull Animation animation) implements ServerPacket.Play {
|
||||
public EntityAnimationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), Animation.values()[reader.read(BYTE)]);
|
||||
}
|
||||
|
@ -22,11 +20,8 @@ public record EntityAnimationPacket(int entityId, @NotNull Animation animation)
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_ANIMATION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_ANIMATION;
|
||||
}
|
||||
|
||||
public enum Animation {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.potion.Potion;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
@ -13,7 +11,7 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
|||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityEffectPacket(int entityId, @NotNull Potion potion,
|
||||
@Nullable NBTCompound factorCodec) implements ServerPacket {
|
||||
@Nullable NBTCompound factorCodec) implements ServerPacket.Play {
|
||||
public EntityEffectPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), new Potion(reader),
|
||||
reader.read(BOOLEAN) ? (NBTCompound) reader.read(NBT) : null);
|
||||
|
@ -27,10 +25,7 @@ public record EntityEffectPacket(int entityId, @NotNull Potion potion,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_EFFECT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_EFFECT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package net.minestom.server.network.packet.server.play;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.entity.EquipmentSlot;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -21,7 +19,7 @@ import java.util.stream.Collectors;
|
|||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityEquipmentPacket(int entityId,
|
||||
@NotNull Map<EquipmentSlot, ItemStack> equipments) implements ComponentHoldingServerPacket {
|
||||
@NotNull Map<EquipmentSlot, ItemStack> equipments) implements ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public EntityEquipmentPacket {
|
||||
equipments = Map.copyOf(equipments);
|
||||
if (equipments.isEmpty())
|
||||
|
@ -46,11 +44,8 @@ public record EntityEquipmentPacket(int entityId,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_EQUIPMENT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_EQUIPMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record EntityHeadLookPacket(int entityId, float yaw) implements ServerPacket {
|
||||
public record EntityHeadLookPacket(int entityId, float yaw) implements ServerPacket.Play {
|
||||
public EntityHeadLookPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), (reader.read(BYTE) * 360f) / 256f);
|
||||
}
|
||||
|
@ -22,10 +20,7 @@ public record EntityHeadLookPacket(int entityId, float yaw) implements ServerPac
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_HEAD_LOOK;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_HEAD_LOOK;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.play;
|
|||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -18,7 +16,7 @@ import java.util.function.UnaryOperator;
|
|||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityMetaDataPacket(int entityId,
|
||||
@NotNull Map<Integer, Metadata.Entry<?>> entries) implements ComponentHoldingServerPacket {
|
||||
@NotNull Map<Integer, Metadata.Entry<?>> entries) implements ServerPacket.Play, ServerPacket.ComponentHolding {
|
||||
public EntityMetaDataPacket {
|
||||
entries = Map.copyOf(entries);
|
||||
}
|
||||
|
@ -51,11 +49,8 @@ public record EntityMetaDataPacket(int entityId,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_METADATA;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_METADATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityPositionAndRotationPacket(int entityId, short deltaX, short deltaY, short deltaZ,
|
||||
float yaw, float pitch, boolean onGround) implements ServerPacket {
|
||||
float yaw, float pitch, boolean onGround) implements ServerPacket.Play {
|
||||
public EntityPositionAndRotationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(SHORT), reader.read(SHORT), reader.read(SHORT),
|
||||
reader.read(BYTE) * 360f / 256f, reader.read(BYTE) * 360f / 256f, reader.read(BOOLEAN));
|
||||
|
@ -29,11 +27,8 @@ public record EntityPositionAndRotationPacket(int entityId, short deltaX, short
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_POSITION_AND_ROTATION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_POSITION_AND_ROTATION;
|
||||
}
|
||||
|
||||
public static EntityPositionAndRotationPacket getPacket(int entityId,
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityPositionPacket(int entityId, short deltaX, short deltaY, short deltaZ, boolean onGround)
|
||||
implements ServerPacket {
|
||||
implements ServerPacket.Play {
|
||||
|
||||
public EntityPositionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(SHORT), reader.read(SHORT), reader.read(SHORT), reader.read(BOOLEAN));
|
||||
|
@ -27,11 +25,8 @@ public record EntityPositionPacket(int entityId, short deltaX, short deltaY, sho
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_POSITION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_POSITION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -4,11 +4,9 @@ import net.minestom.server.attribute.Attribute;
|
|||
import net.minestom.server.attribute.AttributeInstance;
|
||||
import net.minestom.server.attribute.AttributeModifier;
|
||||
import net.minestom.server.attribute.AttributeOperation;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -16,7 +14,7 @@ import java.util.List;
|
|||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityPropertiesPacket(int entityId, List<AttributeInstance> properties) implements ServerPacket {
|
||||
public record EntityPropertiesPacket(int entityId, List<AttributeInstance> properties) implements ServerPacket.Play {
|
||||
public static final int MAX_ENTRIES = 1024;
|
||||
|
||||
public EntityPropertiesPacket {
|
||||
|
@ -61,10 +59,7 @@ public record EntityPropertiesPacket(int entityId, List<AttributeInstance> prope
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_PROPERTIES;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityRotationPacket(int entityId, float yaw, float pitch, boolean onGround) implements ServerPacket {
|
||||
public record EntityRotationPacket(int entityId, float yaw, float pitch, boolean onGround) implements ServerPacket.Play {
|
||||
public EntityRotationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(BYTE) * 360f / 256f, reader.read(BYTE) * 360f / 256f, reader.read(BOOLEAN));
|
||||
}
|
||||
|
@ -23,10 +21,7 @@ public record EntityRotationPacket(int entityId, float yaw, float pitch, boolean
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_ROTATION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_ROTATION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.play;
|
|||
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minestom.server.adventure.AdventurePacketConvertor;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -24,7 +22,7 @@ public record EntitySoundEffectPacket(
|
|||
float volume,
|
||||
float pitch,
|
||||
long seed
|
||||
) implements ServerPacket {
|
||||
) implements ServerPacket.Play {
|
||||
|
||||
public EntitySoundEffectPacket {
|
||||
Check.argCondition(soundEvent == null && soundName == null, "soundEvent and soundName cannot both be null");
|
||||
|
@ -92,10 +90,7 @@ public record EntitySoundEffectPacket(
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_SOUND_EFFECT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_SOUND_EFFECT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record EntityStatusPacket(int entityId, byte status) implements ServerPacket {
|
||||
public record EntityStatusPacket(int entityId, byte status) implements ServerPacket.Play {
|
||||
public EntityStatusPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.read(BYTE));
|
||||
}
|
||||
|
@ -22,10 +20,7 @@ public record EntityStatusPacket(int entityId, byte status) implements ServerPac
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_STATUS;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_STATUS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityTeleportPacket(int entityId, Pos position, boolean onGround) implements ServerPacket {
|
||||
public record EntityTeleportPacket(int entityId, Pos position, boolean onGround) implements ServerPacket.Play {
|
||||
public EntityTeleportPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), new Pos(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE),
|
||||
reader.read(BYTE) * 360f / 256f, reader.read(BYTE) * 360f / 256f),
|
||||
|
@ -29,10 +27,7 @@ public record EntityTeleportPacket(int entityId, Pos position, boolean onGround)
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_TELEPORT;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_TELEPORT;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.SHORT;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record EntityVelocityPacket(int entityId, short velocityX, short velocityY,
|
||||
short velocityZ) implements ServerPacket {
|
||||
short velocityZ) implements ServerPacket.Play {
|
||||
public EntityVelocityPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(SHORT), reader.read(SHORT), reader.read(SHORT));
|
||||
}
|
||||
|
@ -36,10 +34,7 @@ public record EntityVelocityPacket(int entityId, short velocityX, short velocity
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.ENTITY_VELOCITY;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.ENTITY_VELOCITY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -18,7 +16,7 @@ public record ExplosionPacket(double x, double y, double z, float radius,
|
|||
@NotNull BlockInteraction blockInteraction,
|
||||
int smallParticleId, byte @NotNull [] smallParticleData,
|
||||
int largeParticleId, byte @NotNull [] largeParticleData,
|
||||
@NotNull String soundName, boolean hasFixedSoundRange, float soundRange) implements ServerPacket {
|
||||
@NotNull String soundName, boolean hasFixedSoundRange, float soundRange) implements ServerPacket.Play {
|
||||
private static @NotNull ExplosionPacket fromReader(@NotNull NetworkBuffer reader) {
|
||||
double x = reader.read(DOUBLE), y = reader.read(DOUBLE), z = reader.read(DOUBLE);
|
||||
float radius = reader.read(FLOAT);
|
||||
|
@ -107,11 +105,8 @@ public record ExplosionPacket(double x, double y, double z, float radius,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.EXPLOSION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.EXPLOSION;
|
||||
}
|
||||
|
||||
public enum BlockInteraction {
|
||||
|
|
|
@ -2,17 +2,15 @@ package net.minestom.server.network.packet.server.play;
|
|||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record FacePlayerPacket(FacePosition facePosition,
|
||||
Point target, int entityId, FacePosition entityFacePosition) implements ServerPacket {
|
||||
Point target, int entityId, FacePosition entityFacePosition) implements ServerPacket.Play {
|
||||
public FacePlayerPacket(@NotNull NetworkBuffer reader) {
|
||||
this(FacePosition.values()[reader.read(VAR_INT)],
|
||||
new Vec(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE)),
|
||||
|
@ -35,11 +33,8 @@ public record FacePlayerPacket(FacePosition facePosition,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.FACE_PLAYER;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.FACE_PLAYER;
|
||||
}
|
||||
|
||||
public enum FacePosition {
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
|
||||
public record HeldItemChangePacket(byte slot) implements ServerPacket {
|
||||
public record HeldItemChangePacket(byte slot) implements ServerPacket.Play {
|
||||
public HeldItemChangePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE));
|
||||
}
|
||||
|
@ -20,10 +18,7 @@ public record HeldItemChangePacket(byte slot) implements ServerPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.HELD_ITEM_CHANGE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.HELD_ITEM_CHANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.FLOAT;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record HitAnimationPacket(int entityId, float yaw) implements ServerPacket {
|
||||
public record HitAnimationPacket(int entityId, float yaw) implements ServerPacket.Play {
|
||||
|
||||
public HitAnimationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(FLOAT));
|
||||
|
@ -23,10 +21,7 @@ public record HitAnimationPacket(int entityId, float yaw) implements ServerPacke
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.HIT_ANIMATION;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.HIT_ANIMATION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
@ -12,7 +10,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
|
|||
public record InitializeWorldBorderPacket(double x, double z,
|
||||
double oldDiameter, double newDiameter, long speed,
|
||||
int portalTeleportBoundary, int warningTime,
|
||||
int warningBlocks) implements ServerPacket {
|
||||
int warningBlocks) implements ServerPacket.Play {
|
||||
public InitializeWorldBorderPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(DOUBLE), reader.read(DOUBLE),
|
||||
reader.read(DOUBLE), reader.read(DOUBLE),
|
||||
|
@ -32,10 +30,7 @@ public record InitializeWorldBorderPacket(double x, double z,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.INITIALIZE_WORLD_BORDER;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.INITIALIZE_WORLD_BORDER;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.network.packet.server.play.data.DeathLocation;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -20,7 +18,7 @@ public record JoinGamePacket(
|
|||
boolean doLimitedCrafting,
|
||||
String dimensionType, String world, long hashedSeed, GameMode gameMode, GameMode previousGameMode,
|
||||
boolean isDebug, boolean isFlat, DeathLocation deathLocation, int portalCooldown
|
||||
) implements ServerPacket {
|
||||
) implements ServerPacket.Play {
|
||||
public static final int MAX_WORLDS = Short.MAX_VALUE;
|
||||
|
||||
public JoinGamePacket {
|
||||
|
@ -79,11 +77,8 @@ public record JoinGamePacket(
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.JOIN_GAME;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.JOIN_GAME;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -15,7 +13,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
|
|||
|
||||
public record MapDataPacket(int mapId, byte scale, boolean locked,
|
||||
boolean trackingPosition, @NotNull List<Icon> icons,
|
||||
@Nullable MapDataPacket.ColorContent colorContent) implements ServerPacket {
|
||||
@Nullable MapDataPacket.ColorContent colorContent) implements ServerPacket.Play {
|
||||
public static final int MAX_ICONS = 1024;
|
||||
|
||||
public MapDataPacket {
|
||||
|
@ -65,11 +63,8 @@ public record MapDataPacket(int mapId, byte scale, boolean locked,
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.MAP_DATA;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.MAP_DATA;
|
||||
}
|
||||
|
||||
public record Icon(int type, byte x, byte z, byte direction,
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record MultiBlockChangePacket(long chunkSectionPosition, long[] blocks) implements ServerPacket {
|
||||
public record MultiBlockChangePacket(long chunkSectionPosition, long[] blocks) implements ServerPacket.Play {
|
||||
public MultiBlockChangePacket(int chunkX, int section, int chunkZ,
|
||||
long[] blocks) {
|
||||
this(((long) (chunkX & 0x3FFFFF) << 42) | (section & 0xFFFFF) | ((long) (chunkZ & 0x3FFFFF) << 20), blocks);
|
||||
|
@ -26,10 +24,7 @@ public record MultiBlockChangePacket(long chunkSectionPosition, long[] blocks) i
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.MULTI_BLOCK_CHANGE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.MULTI_BLOCK_CHANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record NbtQueryResponsePacket(int transactionId, NBTCompound data) implements ServerPacket {
|
||||
public record NbtQueryResponsePacket(int transactionId, NBTCompound data) implements ServerPacket.Play {
|
||||
public NbtQueryResponsePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), (NBTCompound) reader.read(NBT));
|
||||
}
|
||||
|
@ -27,10 +25,7 @@ public record NbtQueryResponsePacket(int transactionId, NBTCompound data) implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getId(@NotNull ConnectionState state) {
|
||||
return switch (state) {
|
||||
case PLAY -> ServerPacketIdentifier.NBT_QUERY_RESPONSE;
|
||||
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
|
||||
};
|
||||
public int playId() {
|
||||
return ServerPacketIdentifier.NBT_QUERY_RESPONSE;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue