From 266040cfa75aced327c659e5ba04d5804716fab5 Mon Sep 17 00:00:00 2001 From: mworzala Date: Wed, 1 Nov 2023 22:51:37 -0400 Subject: [PATCH] chore: other melonhell pr changes --- .../net/minestom/server/entity/Player.java | 8 +++---- .../packet/server/play/DamageEventPacket.java | 12 +++++++--- .../packet/server/play/RespawnPacket.java | 24 ++++++++++--------- .../minestom/server/world/biomes/Biome.java | 2 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 7d55692a6..3095761e5 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -466,8 +466,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, refreshHealth(); sendPacket(new RespawnPacket(getDimensionType().toString(), instance.getDimensionName(), - 0, gameMode, gameMode, false, levelFlat, RespawnPacket.COPY_ALL, - deathLocation, portalCooldown)); + 0, gameMode, gameMode, false, levelFlat, deathLocation, portalCooldown, RespawnPacket.COPY_ALL)); PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this); EventDispatcher.call(respawnEvent); @@ -1081,8 +1080,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, final PlayerInfoUpdatePacket addPlayerPacket = getAddPlayerToList(); RespawnPacket respawnPacket = new RespawnPacket(getDimensionType().toString(), instance.getDimensionName(), - 0, gameMode, gameMode, false, levelFlat, RespawnPacket.COPY_ALL, - deathLocation, portalCooldown); + 0, gameMode, gameMode, false, levelFlat, deathLocation, portalCooldown, RespawnPacket.COPY_ALL); sendPacket(removePlayerPacket); sendPacket(destroyEntitiesPacket); @@ -1483,7 +1481,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, this.dimensionType = dimensionType; sendPacket(new RespawnPacket(dimensionType.toString(), dimensionName, 0, gameMode, gameMode, false, levelFlat, - RespawnPacket.COPY_ALL, deathLocation, portalCooldown)); + deathLocation, portalCooldown, RespawnPacket.COPY_ALL)); refreshClientStateAfterRespawn(); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java index 51b439312..2e667e2f2 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DamageEventPacket.java @@ -10,9 +10,15 @@ import org.jetbrains.annotations.Nullable; import static net.minestom.server.network.NetworkBuffer.*; -// Notes -// sourceEntityId - 0 indicates no source entity, otherwise it is entityId + 1 -// sourceDirectId - 0 indicates no direct source. Direct attacks (e.g. melee) will have this number me the same as sourceEntityId, indirect attacks (e.g. projectiles) will have this be be the projectile entity id + 1 +/** + * See https://wiki.vg/Protocol#Damage_Event for more info. + * + * @param targetEntityId ID of the entity being damaged + * @param damageTypeId ID of damage type + * @param sourceEntityId 0 if there is no source entity, otherwise it is entityId + 1 + * @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 DamageEventPacket(@NotNull NetworkBuffer reader) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java index 6a33ab89a..9a428a1a1 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/RespawnPacket.java @@ -10,22 +10,24 @@ import org.jetbrains.annotations.NotNull; import static net.minestom.server.network.NetworkBuffer.*; -public record RespawnPacket(String dimensionType, String worldName, - long hashedSeed, GameMode gameMode, GameMode previousGameMode, - boolean isDebug, boolean isFlat, byte dataToCopy, - DeathLocation deathLocation, int portalCooldown) implements ServerPacket { - - public static final byte COPY_ATTRIBUTES = 0x1; - public static final byte COPY_METADATA = 0x2; - public static final byte COPY_ALL = COPY_ATTRIBUTES | COPY_METADATA; +public record RespawnPacket( + String dimensionType, String worldName, + long hashedSeed, GameMode gameMode, GameMode previousGameMode, + boolean isDebug, boolean isFlat, DeathLocation deathLocation, + int portalCooldown, int copyData +) implements ServerPacket { + public static final int COPY_NONE = 0x0; + public static final int COPY_ATTRIBUTES = 0x1; + public static final int COPY_METADATA = 0x2; + public static final int COPY_ALL = COPY_ATTRIBUTES | COPY_METADATA; public RespawnPacket(@NotNull NetworkBuffer reader) { this(reader.read(STRING), reader.read(STRING), reader.read(LONG), GameMode.fromId(reader.read(BYTE)), GameMode.fromId(reader.read(BYTE)), reader.read(BOOLEAN), reader.read(BOOLEAN), - reader.read(BYTE), reader.read(DEATH_LOCATION), - reader.read(VAR_INT)); + reader.read(DEATH_LOCATION), + reader.read(VAR_INT), reader.read(BYTE)); } @Override @@ -37,9 +39,9 @@ public record RespawnPacket(String dimensionType, String worldName, writer.write(BYTE, previousGameMode.id()); writer.write(BOOLEAN, isDebug); writer.write(BOOLEAN, isFlat); - writer.write(BYTE, dataToCopy); writer.write(DEATH_LOCATION, deathLocation); writer.write(VAR_INT, portalCooldown); + writer.write(BYTE, (byte) copyData); } @Override diff --git a/src/main/java/net/minestom/server/world/biomes/Biome.java b/src/main/java/net/minestom/server/world/biomes/Biome.java index bacc0e2d9..c8142703f 100644 --- a/src/main/java/net/minestom/server/world/biomes/Biome.java +++ b/src/main/java/net/minestom/server/world/biomes/Biome.java @@ -72,7 +72,7 @@ public final class Biome { element.setFloat("scale", scale); element.setFloat("downfall", downfall); element.setString("category", category.name().toLowerCase(Locale.ROOT)); - element.setByte("has_precipitation", (byte) 1); //todo bad fix + element.setByte("has_precipitation", (byte) (precipitation == Precipitation.NONE ? 0 : 1)); element.setString("precipitation", precipitation.name().toLowerCase(Locale.ROOT)); if (temperatureModifier != TemperatureModifier.NONE) element.setString("temperature_modifier", temperatureModifier.name().toLowerCase(Locale.ROOT));