mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Merge remote-tracking branch 'origin/master' into feature/1.21
This commit is contained in:
commit
937a571600
31 changed files with 323 additions and 403 deletions
14
.editorconfig
Normal file
14
.editorconfig
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
tab_width = 4
|
||||||
|
max_line_length = off
|
||||||
|
|
||||||
|
[*.java]
|
||||||
|
ij_java_class_count_to_use_import_on_demand = 9999
|
||||||
|
ij_java_doc_align_exception_comments = false
|
||||||
|
ij_java_doc_align_param_comments = false
|
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
|
@ -20,7 +20,7 @@ pipeline {
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
sh './gradlew javadoc'
|
sh './gradlew javadoc'
|
||||||
step([$class: 'JavadocArchiver', javadocDir: 'build/docs/javadoc', keepAll: false])
|
step([$class: 'JavadocArchiver', javadocDir: 'protocol/build/docs/javadoc', keepAll: false])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ You can find the Javadocs for MCProtocolLib [on opencollab](https://ci.opencolla
|
||||||
|
|
||||||
## Building the Source
|
## Building the Source
|
||||||
|
|
||||||
MCProtocolLib uses Maven to manage dependencies. To build the source code, run `mvn clean install` in the project root directory.
|
MCProtocolLib uses Gradle to manage dependencies. To build the source code, run `./gradlew clean build` in the project root directory.
|
||||||
|
|
||||||
## Support and Development
|
## Support and Development
|
||||||
|
|
||||||
|
@ -93,4 +93,4 @@ Please join [the GeyserMC Discord server](https://discord.gg/geysermc) and visit
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MCProtocolLib is licensed under the **[MIT license](https://opensource.org/license/mit/)**.
|
MCProtocolLib is licensed under the **[MIT license](https://opensource.org/license/mit)**.
|
||||||
|
|
|
@ -4,7 +4,7 @@ metadata.format.version = "1.1"
|
||||||
|
|
||||||
adventure = "4.15.0"
|
adventure = "4.15.0"
|
||||||
cloudburstnbt = "3.0.0.Final"
|
cloudburstnbt = "3.0.0.Final"
|
||||||
mcauthlib = "6621fd0"
|
mcauthlib = "e5b0bcc"
|
||||||
math = "2.0"
|
math = "2.0"
|
||||||
fastutil-maps = "8.5.3"
|
fastutil-maps = "8.5.3"
|
||||||
netty = "4.1.103.Final"
|
netty = "4.1.103.Final"
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.Serverbound
|
||||||
import javax.crypto.KeyGenerator;
|
import javax.crypto.KeyGenerator;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles making initial login and status requests for clients.
|
* Handles making initial login and status requests for clients.
|
||||||
|
@ -127,17 +127,22 @@ public class ClientListener extends SessionAdapter {
|
||||||
} else if (packet instanceof ClientboundStartConfigurationPacket) {
|
} else if (packet instanceof ClientboundStartConfigurationPacket) {
|
||||||
session.send(new ServerboundConfigurationAcknowledgedPacket());
|
session.send(new ServerboundConfigurationAcknowledgedPacket());
|
||||||
} else if (packet instanceof ClientboundTransferPacket transferPacket) {
|
} else if (packet instanceof ClientboundTransferPacket transferPacket) {
|
||||||
|
if (session.getFlag(MinecraftConstants.FOLLOW_TRANSFERS, true)) {
|
||||||
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(), session.getPacketProtocol());
|
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(), session.getPacketProtocol());
|
||||||
newSession.setFlags(session.getFlags());
|
newSession.setFlags(session.getFlags());
|
||||||
session.disconnect("Transferring");
|
session.disconnect("Transferring");
|
||||||
newSession.connect(true, true);
|
newSession.connect(true, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (protocol.getState() == ProtocolState.CONFIGURATION) {
|
} else if (protocol.getState() == ProtocolState.CONFIGURATION) {
|
||||||
if (packet instanceof ClientboundFinishConfigurationPacket) {
|
if (packet instanceof ClientboundFinishConfigurationPacket) {
|
||||||
session.send(new ServerboundFinishConfigurationPacket());
|
session.send(new ServerboundFinishConfigurationPacket());
|
||||||
} else if (packet instanceof ClientboundSelectKnownPacks) {
|
} else if (packet instanceof ClientboundSelectKnownPacks) {
|
||||||
session.send(new ServerboundSelectKnownPacks(new ArrayList<>()));
|
if (session.getFlag(MinecraftConstants.SEND_BLANK_KNOWN_PACKS_RESPONSE, true)) {
|
||||||
|
session.send(new ServerboundSelectKnownPacks(Collections.emptyList()));
|
||||||
|
}
|
||||||
} else if (packet instanceof ClientboundTransferPacket transferPacket) {
|
} else if (packet instanceof ClientboundTransferPacket transferPacket) {
|
||||||
|
if (session.getFlag(MinecraftConstants.FOLLOW_TRANSFERS, true)) {
|
||||||
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(), session.getPacketProtocol());
|
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(), session.getPacketProtocol());
|
||||||
newSession.setFlags(session.getFlags());
|
newSession.setFlags(session.getFlags());
|
||||||
session.disconnect("Transferring");
|
session.disconnect("Transferring");
|
||||||
|
@ -145,6 +150,7 @@ public class ClientListener extends SessionAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetSent(Session session, Packet packet) {
|
public void packetSent(Session session, Packet packet) {
|
||||||
|
|
|
@ -50,6 +50,16 @@ public final class MinecraftConstants {
|
||||||
*/
|
*/
|
||||||
public static final Flag<ServerPingTimeHandler> SERVER_PING_TIME_HANDLER_KEY = new Flag<>("server-ping-time-handler", ServerPingTimeHandler.class);
|
public static final Flag<ServerPingTimeHandler> SERVER_PING_TIME_HANDLER_KEY = new Flag<>("server-ping-time-handler", ServerPingTimeHandler.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Session flag for determining if an automatic response should be sent to the ClientboundSelectKnownPacks.
|
||||||
|
*/
|
||||||
|
public static final Flag<Boolean> SEND_BLANK_KNOWN_PACKS_RESPONSE = new Flag<>("send-blank-known-packs-response", Boolean.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Session flag for determining whether to create a new TcpClientSession when the Java server sends a ClientboundTransferPacket.
|
||||||
|
*/
|
||||||
|
public static final Flag<Boolean> FOLLOW_TRANSFERS = new Flag<>("follow-transfers", Boolean.class);
|
||||||
|
|
||||||
// Server Key Constants
|
// Server Key Constants
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -130,6 +130,23 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> readList(ByteBuf buf, Function<ByteBuf, T> reader) {
|
||||||
|
int size = this.readVarInt(buf);
|
||||||
|
List<T> list = new ArrayList<>(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
list.add(reader.apply(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void writeList(ByteBuf buf, List<T> value, BiConsumer<ByteBuf, T> writer) {
|
||||||
|
this.writeVarInt(buf, value.size());
|
||||||
|
for (T t : value) {
|
||||||
|
writer.accept(buf, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public <T> Holder<T> readHolder(ByteBuf buf, Function<ByteBuf, T> readCustom) {
|
public <T> Holder<T> readHolder(ByteBuf buf, Function<ByteBuf, T> readCustom) {
|
||||||
int registryId = this.readVarInt(buf);
|
int registryId = this.readVarInt(buf);
|
||||||
return registryId == 0 ? Holder.ofCustom(readCustom.apply(buf)) : Holder.ofId(registryId - 1);
|
return registryId == 0 ? Holder.ofCustom(readCustom.apply(buf)) : Holder.ofId(registryId - 1);
|
||||||
|
@ -252,7 +269,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
|
|
||||||
NbtType<?> type = NbtType.byId(typeId);
|
NbtType<?> type = NbtType.byId(typeId);
|
||||||
|
|
||||||
return new NBTInputStream(input).readValue(type);
|
return new NBTInputStream(input).readValue(type, 512);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
|
@ -270,7 +287,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
NbtType<?> type = NbtType.byClass(tag.getClass());
|
NbtType<?> type = NbtType.byClass(tag.getClass());
|
||||||
output.writeByte(type.getId());
|
output.writeByte(type.getId());
|
||||||
|
|
||||||
new NBTOutputStream(output).writeValue(tag);
|
new NBTOutputStream(output).writeValue(tag, 512);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,13 @@ public enum Effect {
|
||||||
DOLPHINS_GRACE,
|
DOLPHINS_GRACE,
|
||||||
BAD_OMEN,
|
BAD_OMEN,
|
||||||
HERO_OF_THE_VILLAGE,
|
HERO_OF_THE_VILLAGE,
|
||||||
DARKNESS;
|
DARKNESS,
|
||||||
|
TRIAL_OMEN,
|
||||||
|
RAID_OMEN,
|
||||||
|
WIND_CHARGED,
|
||||||
|
WEAVING,
|
||||||
|
OOZING,
|
||||||
|
INFESTED;
|
||||||
|
|
||||||
public static final Effect[] VALUES = values();
|
public static final Effect[] VALUES = values();
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ public class AdventureModePredicate {
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class BlockPredicate {
|
public static class BlockPredicate {
|
||||||
private final @Nullable String location;
|
private final @Nullable HolderSet blocks;
|
||||||
private final int @Nullable [] holders;
|
|
||||||
private final @Nullable List<PropertyMatcher> properties;
|
private final @Nullable List<PropertyMatcher> properties;
|
||||||
private final @Nullable NbtMap nbt;
|
private final @Nullable NbtMap nbt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class FoodProperties {
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class PossibleEffect {
|
public static class PossibleEffect {
|
||||||
private final MobEffectDetails effect;
|
private final MobEffectInstance effect;
|
||||||
private final float probability;
|
private final float probability;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a set of holders that could either be explicit, or resolved from a tag location.
|
||||||
|
* The client has to know how to resolve the tag location to get the holders.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public final class HolderSet {
|
||||||
|
private final @Nullable String location;
|
||||||
|
private final int @Nullable [] holders;
|
||||||
|
|
||||||
|
public HolderSet(int @NonNull [] holders) {
|
||||||
|
this.location = null;
|
||||||
|
this.holders = holders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HolderSet(@NonNull String location) {
|
||||||
|
this.location = location;
|
||||||
|
this.holders = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return either the explicit holders, or resolve the tag location to get the holders.
|
||||||
|
*
|
||||||
|
* @param tagResolver The function to resolve the tag location to get the holders.
|
||||||
|
* @return The holders.
|
||||||
|
*/
|
||||||
|
public int[] resolve(Function<String, int[]> tagResolver) {
|
||||||
|
if (holders != null) {
|
||||||
|
return holders;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagResolver.apply(location);
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import org.cloudburstmc.nbt.NbtList;
|
||||||
import org.cloudburstmc.nbt.NbtType;
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
|
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.CustomSound;
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.CustomSound;
|
||||||
|
@ -34,21 +35,13 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
|
|
||||||
public <T> Filterable<T> readFilterable(ByteBuf buf, Function<ByteBuf, T> reader) {
|
public <T> Filterable<T> readFilterable(ByteBuf buf, Function<ByteBuf, T> reader) {
|
||||||
T raw = reader.apply(buf);
|
T raw = reader.apply(buf);
|
||||||
T filtered = null;
|
T filtered = this.readNullable(buf, reader);
|
||||||
if (buf.readBoolean()) {
|
|
||||||
filtered = reader.apply(buf);
|
|
||||||
}
|
|
||||||
return new Filterable<>(raw, filtered);
|
return new Filterable<>(raw, filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void writeFilterable(ByteBuf buf, Filterable<T> filterable, BiConsumer<ByteBuf, T> writer) {
|
public <T> void writeFilterable(ByteBuf buf, Filterable<T> filterable, BiConsumer<ByteBuf, T> writer) {
|
||||||
writer.accept(buf, filterable.getRaw());
|
writer.accept(buf, filterable.getRaw());
|
||||||
if (filterable.getOptional() != null) {
|
this.writeNullable(buf, filterable.getOptional(), writer);
|
||||||
buf.writeBoolean(true);
|
|
||||||
writer.accept(buf, filterable.getOptional());
|
|
||||||
} else {
|
|
||||||
buf.writeBoolean(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemEnchantments readItemEnchantments(ByteBuf buf) {
|
public ItemEnchantments readItemEnchantments(ByteBuf buf) {
|
||||||
|
@ -72,12 +65,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdventureModePredicate readAdventureModePredicate(ByteBuf buf) {
|
public AdventureModePredicate readAdventureModePredicate(ByteBuf buf) {
|
||||||
List<AdventureModePredicate.BlockPredicate> predicates = new ArrayList<>();
|
List<AdventureModePredicate.BlockPredicate> predicates = this.readList(buf, this::readBlockPredicate);
|
||||||
int predicateCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < predicateCount; i++) {
|
|
||||||
predicates.add(this.readBlockPredicate(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AdventureModePredicate(predicates, buf.readBoolean());
|
return new AdventureModePredicate(predicates, buf.readBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,59 +79,29 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdventureModePredicate.BlockPredicate readBlockPredicate(ByteBuf buf) {
|
public AdventureModePredicate.BlockPredicate readBlockPredicate(ByteBuf buf) {
|
||||||
String location = null;
|
HolderSet holderSet = this.readNullable(buf, this::readHolderSet);
|
||||||
int[] holders = null;
|
List<AdventureModePredicate.PropertyMatcher> propertyMatchers = this.readNullable(buf, (input) -> {
|
||||||
List<AdventureModePredicate.PropertyMatcher> propertyMatchers = null;
|
List<AdventureModePredicate.PropertyMatcher> matchers = new ArrayList<>();
|
||||||
|
int matcherCount = this.readVarInt(input);
|
||||||
if (buf.readBoolean()) {
|
|
||||||
int length = this.readVarInt(buf) - 1;
|
|
||||||
if (length == -1) {
|
|
||||||
location = this.readResourceLocation(buf);
|
|
||||||
} else {
|
|
||||||
holders = new int[length];
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
holders[i] = this.readVarInt(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buf.readBoolean()) {
|
|
||||||
propertyMatchers = new ArrayList<>();
|
|
||||||
int matcherCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < matcherCount; i++) {
|
for (int i = 0; i < matcherCount; i++) {
|
||||||
String name = this.readString(buf);
|
String name = this.readString(input);
|
||||||
if (buf.readBoolean()) {
|
if (input.readBoolean()) {
|
||||||
propertyMatchers.add(new AdventureModePredicate.PropertyMatcher(name, this.readString(buf), null, null));
|
matchers.add(new AdventureModePredicate.PropertyMatcher(name, this.readString(input), null, null));
|
||||||
} else {
|
} else {
|
||||||
propertyMatchers.add(new AdventureModePredicate.PropertyMatcher(name, null, this.readString(buf), this.readString(buf)));
|
matchers.add(new AdventureModePredicate.PropertyMatcher(name, null, this.readString(input), this.readString(input)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return matchers;
|
||||||
|
});
|
||||||
|
|
||||||
return new AdventureModePredicate.BlockPredicate(location, holders, propertyMatchers, this.readNullable(buf, this::readCompoundTag));
|
return new AdventureModePredicate.BlockPredicate(holderSet, propertyMatchers, this.readNullable(buf, this::readCompoundTag));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBlockPredicate(ByteBuf buf, AdventureModePredicate.BlockPredicate blockPredicate) {
|
public void writeBlockPredicate(ByteBuf buf, AdventureModePredicate.BlockPredicate blockPredicate) {
|
||||||
if (blockPredicate.getLocation() == null && blockPredicate.getHolders() == null) {
|
this.writeNullable(buf, blockPredicate.getBlocks(), this::writeHolderSet);
|
||||||
buf.writeBoolean(false);
|
this.writeNullable(buf, blockPredicate.getProperties(), (output, properties) -> {
|
||||||
} else {
|
|
||||||
buf.writeBoolean(true);
|
buf.writeBoolean(true);
|
||||||
if (blockPredicate.getLocation() != null) {
|
for (AdventureModePredicate.PropertyMatcher matcher : properties) {
|
||||||
this.writeVarInt(buf, 0);
|
|
||||||
this.writeResourceLocation(buf, blockPredicate.getLocation());
|
|
||||||
} else {
|
|
||||||
this.writeVarInt(buf, blockPredicate.getHolders().length + 1);
|
|
||||||
for (int holder : blockPredicate.getHolders()) {
|
|
||||||
this.writeVarInt(buf, holder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockPredicate.getProperties() == null) {
|
|
||||||
buf.writeBoolean(false);
|
|
||||||
} else {
|
|
||||||
buf.writeBoolean(true);
|
|
||||||
for (AdventureModePredicate.PropertyMatcher matcher : blockPredicate.getProperties()) {
|
|
||||||
this.writeString(buf, matcher.getName());
|
this.writeString(buf, matcher.getName());
|
||||||
if (matcher.getValue() != null) {
|
if (matcher.getValue() != null) {
|
||||||
buf.writeBoolean(true);
|
buf.writeBoolean(true);
|
||||||
|
@ -154,32 +112,46 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
this.writeString(buf, matcher.getMaxValue());
|
this.writeString(buf, matcher.getMaxValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
this.writeNullable(buf, blockPredicate.getNbt(), this::writeAnyTag);
|
this.writeNullable(buf, blockPredicate.getNbt(), this::writeAnyTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolData readToolData(ByteBuf buf) {
|
public HolderSet readHolderSet(ByteBuf buf) {
|
||||||
List<ToolData.Rule> rules = new ArrayList<>();
|
|
||||||
int ruleCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < ruleCount; i++) {
|
|
||||||
String location = null;
|
|
||||||
int[] holders = null;
|
|
||||||
|
|
||||||
int length = this.readVarInt(buf) - 1;
|
int length = this.readVarInt(buf) - 1;
|
||||||
if (length == -1) {
|
if (length == -1) {
|
||||||
location = this.readResourceLocation(buf);
|
return new HolderSet(this.readResourceLocation(buf));
|
||||||
} else {
|
} else {
|
||||||
holders = new int[length];
|
int[] holders = new int[length];
|
||||||
for (int j = 0; j < length; j++) {
|
for (int i = 0; i < length; i++) {
|
||||||
holders[j] = this.readVarInt(buf);
|
holders[i] = this.readVarInt(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HolderSet(holders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Float speed = this.readNullable(buf, ByteBuf::readFloat);
|
public void writeHolderSet(ByteBuf buf, HolderSet holderSet) {
|
||||||
Boolean correctForDrops = this.readNullable(buf, ByteBuf::readBoolean);
|
if (holderSet.getLocation() != null) {
|
||||||
rules.add(new ToolData.Rule(location, holders, speed, correctForDrops));
|
this.writeVarInt(buf, 0);
|
||||||
|
this.writeResourceLocation(buf, holderSet.getLocation());
|
||||||
|
} else {
|
||||||
|
assert holderSet.getHolders() != null;
|
||||||
|
this.writeVarInt(buf, holderSet.getHolders().length + 1);
|
||||||
|
for (int holder : holderSet.getHolders()) {
|
||||||
|
this.writeVarInt(buf, holder);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToolData readToolData(ByteBuf buf) {
|
||||||
|
List<ToolData.Rule> rules = this.readList(buf, (input) -> {
|
||||||
|
HolderSet holderSet = this.readHolderSet(input);
|
||||||
|
|
||||||
|
Float speed = this.readNullable(input, ByteBuf::readFloat);
|
||||||
|
Boolean correctForDrops = this.readNullable(input, ByteBuf::readBoolean);
|
||||||
|
return new ToolData.Rule(holderSet, speed, correctForDrops);
|
||||||
|
});
|
||||||
|
|
||||||
float defaultMiningSpeed = buf.readFloat();
|
float defaultMiningSpeed = buf.readFloat();
|
||||||
int damagePerBlock = this.readVarInt(buf);
|
int damagePerBlock = this.readVarInt(buf);
|
||||||
|
@ -187,57 +159,42 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToolData(ByteBuf buf, ToolData data) {
|
public void writeToolData(ByteBuf buf, ToolData data) {
|
||||||
this.writeVarInt(buf, data.getRules().size());
|
this.writeList(buf, data.getRules(), (output, rule) -> {
|
||||||
for (ToolData.Rule rule : data.getRules()) {
|
this.writeHolderSet(output, rule.getBlocks());
|
||||||
if (rule.getLocation() != null) {
|
this.writeNullable(output, rule.getSpeed(), ByteBuf::writeFloat);
|
||||||
this.writeVarInt(buf, 0);
|
this.writeNullable(output, rule.getCorrectForDrops(), ByteBuf::writeBoolean);
|
||||||
this.writeResourceLocation(buf, rule.getLocation());
|
});
|
||||||
} else {
|
|
||||||
this.writeVarInt(buf, rule.getHolders().length + 1);
|
|
||||||
for (int holder : rule.getHolders()) {
|
|
||||||
this.writeVarInt(buf, holder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.writeNullable(buf, rule.getSpeed(), ByteBuf::writeFloat);
|
|
||||||
this.writeNullable(buf, rule.getCorrectForDrops(), ByteBuf::writeBoolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.writeFloat(data.getDefaultMiningSpeed());
|
buf.writeFloat(data.getDefaultMiningSpeed());
|
||||||
this.writeVarInt(buf, data.getDamagePerBlock());
|
this.writeVarInt(buf, data.getDamagePerBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemAttributeModifiers readItemAttributeModifiers(ByteBuf buf) {
|
public ItemAttributeModifiers readItemAttributeModifiers(ByteBuf buf) {
|
||||||
List<ItemAttributeModifiers.Entry> modifiers = new ArrayList<>();
|
List<ItemAttributeModifiers.Entry> modifiers = this.readList(buf, (input) -> {
|
||||||
int modifierCount = this.readVarInt(buf);
|
int attribute = this.readVarInt(input);
|
||||||
for (int i = 0; i < modifierCount; i++) {
|
|
||||||
int attribute = this.readVarInt(buf);
|
|
||||||
|
|
||||||
UUID id = this.readUUID(buf);
|
UUID id = this.readUUID(input);
|
||||||
String name = this.readString(buf);
|
String name = this.readString(input);
|
||||||
double amount = buf.readDouble();
|
double amount = input.readDouble();
|
||||||
ModifierOperation operation = ModifierOperation.from(this.readVarInt(buf));
|
ModifierOperation operation = ModifierOperation.from(this.readVarInt(input));
|
||||||
ItemAttributeModifiers.AttributeModifier modifier = new ItemAttributeModifiers.AttributeModifier(id, name, amount, operation);
|
ItemAttributeModifiers.AttributeModifier modifier = new ItemAttributeModifiers.AttributeModifier(id, name, amount, operation);
|
||||||
|
|
||||||
ItemAttributeModifiers.EquipmentSlotGroup slot = ItemAttributeModifiers.EquipmentSlotGroup.from(this.readVarInt(buf));
|
ItemAttributeModifiers.EquipmentSlotGroup slot = ItemAttributeModifiers.EquipmentSlotGroup.from(this.readVarInt(input));
|
||||||
modifiers.add(new ItemAttributeModifiers.Entry(attribute, modifier, slot));
|
return new ItemAttributeModifiers.Entry(attribute, modifier, slot);
|
||||||
}
|
});
|
||||||
|
|
||||||
return new ItemAttributeModifiers(modifiers, buf.readBoolean());
|
return new ItemAttributeModifiers(modifiers, buf.readBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeItemAttributeModifiers(ByteBuf buf, ItemAttributeModifiers modifiers) {
|
public void writeItemAttributeModifiers(ByteBuf buf, ItemAttributeModifiers modifiers) {
|
||||||
this.writeVarInt(buf, modifiers.getModifiers().size());
|
this.writeList(buf, modifiers.getModifiers(), (output, entry) -> {
|
||||||
for (ItemAttributeModifiers.Entry modifier : modifiers.getModifiers()) {
|
this.writeVarInt(output, entry.getAttribute());
|
||||||
this.writeVarInt(buf, modifier.getAttribute());
|
this.writeUUID(output, entry.getModifier().getId());
|
||||||
|
this.writeString(output, entry.getModifier().getName());
|
||||||
this.writeUUID(buf, modifier.getModifier().getId());
|
output.writeDouble(entry.getModifier().getAmount());
|
||||||
this.writeString(buf, modifier.getModifier().getName());
|
this.writeVarInt(output, entry.getModifier().getOperation().ordinal());
|
||||||
buf.writeDouble(modifier.getModifier().getAmount());
|
this.writeVarInt(output, entry.getSlot().ordinal());
|
||||||
this.writeVarInt(buf, modifier.getModifier().getOperation().ordinal());
|
});
|
||||||
|
|
||||||
this.writeVarInt(buf, modifier.getSlot().ordinal());
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.writeBoolean(modifiers.isShowInTooltip());
|
buf.writeBoolean(modifiers.isShowInTooltip());
|
||||||
}
|
}
|
||||||
|
@ -255,11 +212,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
int potionId = buf.readBoolean() ? this.readVarInt(buf) : -1;
|
int potionId = buf.readBoolean() ? this.readVarInt(buf) : -1;
|
||||||
int customColor = buf.readBoolean() ? buf.readInt() : -1;
|
int customColor = buf.readBoolean() ? buf.readInt() : -1;
|
||||||
|
|
||||||
Int2ObjectMap<MobEffectDetails> customEffects = new Int2ObjectOpenHashMap<>();
|
List<MobEffectInstance> customEffects = this.readList(buf, this::readEffectInstance);
|
||||||
int effectCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < effectCount; i++) {
|
|
||||||
customEffects.put(this.readVarInt(buf), this.readEffectDetails(buf));
|
|
||||||
}
|
|
||||||
return new PotionContents(potionId, customColor, customEffects);
|
return new PotionContents(potionId, customColor, customEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,11 +231,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
buf.writeInt(contents.getCustomColor());
|
buf.writeInt(contents.getCustomColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.writeVarInt(buf, contents.getCustomEffects().size());
|
this.writeList(buf, contents.getCustomEffects(), this::writeEffectInstance);
|
||||||
for (Int2ObjectMap.Entry<MobEffectDetails> entry : contents.getCustomEffects().int2ObjectEntrySet()) {
|
|
||||||
this.writeVarInt(buf, entry.getIntKey());
|
|
||||||
this.writeEffectDetails(buf, entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FoodProperties readFoodProperties(ByteBuf buf) {
|
public FoodProperties readFoodProperties(ByteBuf buf) {
|
||||||
|
@ -291,11 +240,11 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
boolean canAlwaysEat = buf.readBoolean();
|
boolean canAlwaysEat = buf.readBoolean();
|
||||||
float eatSeconds = buf.readFloat();
|
float eatSeconds = buf.readFloat();
|
||||||
|
|
||||||
List<FoodProperties.PossibleEffect> effects = new ArrayList<>();
|
List<FoodProperties.PossibleEffect> effects = this.readList(buf, (input) -> {
|
||||||
int effectCount = this.readVarInt(buf);
|
MobEffectInstance effect = this.readEffectInstance(input);
|
||||||
for (int i = 0; i < effectCount; i++) {
|
float probability = input.readFloat();
|
||||||
effects.add(new FoodProperties.PossibleEffect(this.readEffectDetails(buf), buf.readFloat()));
|
return new FoodProperties.PossibleEffect(effect, probability);
|
||||||
}
|
});
|
||||||
|
|
||||||
return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, effects);
|
return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, effects);
|
||||||
}
|
}
|
||||||
|
@ -306,11 +255,15 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
buf.writeBoolean(properties.isCanAlwaysEat());
|
buf.writeBoolean(properties.isCanAlwaysEat());
|
||||||
buf.writeFloat(properties.getEatSeconds());
|
buf.writeFloat(properties.getEatSeconds());
|
||||||
|
|
||||||
this.writeVarInt(buf, properties.getEffects().size());
|
this.writeList(buf, properties.getEffects(), (output, effect) -> {
|
||||||
for (FoodProperties.PossibleEffect effect : properties.getEffects()) {
|
this.writeEffectInstance(output, effect.getEffect());
|
||||||
this.writeEffectDetails(buf, effect.getEffect());
|
output.writeFloat(effect.getProbability());
|
||||||
buf.writeFloat(effect.getProbability());
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MobEffectInstance readEffectInstance(ByteBuf buf) {
|
||||||
|
Effect effect = this.readEffect(buf);
|
||||||
|
return new MobEffectInstance(effect, this.readEffectDetails(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MobEffectDetails readEffectDetails(ByteBuf buf) {
|
public MobEffectDetails readEffectDetails(ByteBuf buf) {
|
||||||
|
@ -323,6 +276,11 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
return new MobEffectDetails(amplifier, duration, ambient, showParticles, showIcon, hiddenEffect);
|
return new MobEffectDetails(amplifier, duration, ambient, showParticles, showIcon, hiddenEffect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeEffectInstance(ByteBuf buf, MobEffectInstance instance) {
|
||||||
|
this.writeEffect(buf, instance.getEffect());
|
||||||
|
this.writeEffectDetails(buf, instance.getDetails());
|
||||||
|
}
|
||||||
|
|
||||||
public void writeEffectDetails(ByteBuf buf, MobEffectDetails details) {
|
public void writeEffectDetails(ByteBuf buf, MobEffectDetails details) {
|
||||||
this.writeVarInt(buf, details.getAmplifier());
|
this.writeVarInt(buf, details.getAmplifier());
|
||||||
this.writeVarInt(buf, details.getDuration());
|
this.writeVarInt(buf, details.getDuration());
|
||||||
|
@ -342,20 +300,12 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WritableBookContent readWritableBookContent(ByteBuf buf) {
|
public WritableBookContent readWritableBookContent(ByteBuf buf) {
|
||||||
List<Filterable<String>> pages = new ArrayList<>();
|
List<Filterable<String>> pages = this.readList(buf, (input) -> this.readFilterable(input, this::readString));
|
||||||
int pageCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < pageCount; i++) {
|
|
||||||
pages.add(this.readFilterable(buf, this::readString));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WritableBookContent(pages);
|
return new WritableBookContent(pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeWritableBookContent(ByteBuf buf, WritableBookContent content) {
|
public void writeWritableBookContent(ByteBuf buf, WritableBookContent content) {
|
||||||
this.writeVarInt(buf, content.getPages().size());
|
this.writeList(buf, content.getPages(), (output, page) -> this.writeFilterable(output, page, this::writeString));
|
||||||
for (Filterable<String> page : content.getPages()) {
|
|
||||||
this.writeFilterable(buf, page, this::writeString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WrittenBookContent readWrittenBookContent(ByteBuf buf) {
|
public WrittenBookContent readWrittenBookContent(ByteBuf buf) {
|
||||||
|
@ -363,12 +313,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
String author = this.readString(buf);
|
String author = this.readString(buf);
|
||||||
int generation = this.readVarInt(buf);
|
int generation = this.readVarInt(buf);
|
||||||
|
|
||||||
List<Filterable<Component>> pages = new ArrayList<>();
|
List<Filterable<Component>> pages = this.readList(buf, (input) -> this.readFilterable(input, this::readComponent));
|
||||||
int pageCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < pageCount; i++) {
|
|
||||||
pages.add(this.readFilterable(buf, this::readComponent));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean resolved = buf.readBoolean();
|
boolean resolved = buf.readBoolean();
|
||||||
return new WrittenBookContent(title, author, generation, pages, resolved);
|
return new WrittenBookContent(title, author, generation, pages, resolved);
|
||||||
}
|
}
|
||||||
|
@ -378,10 +323,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
this.writeString(buf, content.getAuthor());
|
this.writeString(buf, content.getAuthor());
|
||||||
this.writeVarInt(buf, content.getGeneration());
|
this.writeVarInt(buf, content.getGeneration());
|
||||||
|
|
||||||
this.writeVarInt(buf, content.getPages().size());
|
this.writeList(buf, content.getPages(), (output, page) -> this.writeFilterable(output, page, this::writeComponent));
|
||||||
for (Filterable<Component> page : content.getPages()) {
|
|
||||||
this.writeFilterable(buf, page, this::writeComponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.writeBoolean(content.isResolved());
|
buf.writeBoolean(content.isResolved());
|
||||||
}
|
}
|
||||||
|
@ -544,11 +486,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
UUID id = this.readNullable(buf, this::readUUID);
|
UUID id = this.readNullable(buf, this::readUUID);
|
||||||
GameProfile profile = new GameProfile(id, name);
|
GameProfile profile = new GameProfile(id, name);
|
||||||
|
|
||||||
List<GameProfile.Property> properties = new ArrayList<>();
|
List<GameProfile.Property> properties = this.readList(buf, this::readProperty);
|
||||||
int propertyCount = this.readVarInt(buf);
|
|
||||||
for (int i = 0; i < propertyCount; i++) {
|
|
||||||
properties.add(this.readProperty(buf));
|
|
||||||
}
|
|
||||||
profile.setProperties(properties);
|
profile.setProperties(properties);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
|
@ -558,10 +496,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
this.writeNullable(buf, profile.getName(), this::writeString);
|
this.writeNullable(buf, profile.getName(), this::writeString);
|
||||||
this.writeNullable(buf, profile.getId(), this::writeUUID);
|
this.writeNullable(buf, profile.getId(), this::writeUUID);
|
||||||
|
|
||||||
this.writeVarInt(buf, profile.getProperties().size());
|
this.writeList(buf, profile.getProperties(), this::writeProperty);
|
||||||
for (GameProfile.Property property : profile.getProperties()) {
|
|
||||||
this.writeProperty(buf, property);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BannerPatternLayer readBannerPatternLayer(ByteBuf buf) {
|
public BannerPatternLayer readBannerPatternLayer(ByteBuf buf) {
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MobEffectInstance {
|
||||||
|
private final @NonNull Effect effect;
|
||||||
|
private final @NonNull MobEffectDetails details;
|
||||||
|
}
|
|
@ -1,13 +1,14 @@
|
||||||
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PotionContents {
|
public class PotionContents {
|
||||||
private final int potionId;
|
private final int potionId;
|
||||||
private final int customColor;
|
private final int customColor;
|
||||||
private final Int2ObjectMap<MobEffectDetails> customEffects;
|
private final List<MobEffectInstance> customEffects;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -16,8 +17,7 @@ public class ToolData {
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Rule {
|
public static class Rule {
|
||||||
private final @Nullable String location;
|
private final @NonNull HolderSet blocks;
|
||||||
private final int @Nullable [] holders;
|
|
||||||
private final @Nullable Float speed;
|
private final @Nullable Float speed;
|
||||||
private final @Nullable Boolean correctForDrops;
|
private final @Nullable Boolean correctForDrops;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ public enum MapIconType {
|
||||||
SNOWY_VILLAGE,
|
SNOWY_VILLAGE,
|
||||||
TAIGA_VILLAGE,
|
TAIGA_VILLAGE,
|
||||||
JUNGLE_TEMPLE,
|
JUNGLE_TEMPLE,
|
||||||
SWAMP_HUT;
|
SWAMP_HUT,
|
||||||
|
TRIAL_CHAMBERS;
|
||||||
|
|
||||||
private static final MapIconType[] VALUES = values();
|
private static final MapIconType[] VALUES = values();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
|
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -20,22 +19,15 @@ public class ClientboundRegistryDataPacket implements MinecraftPacket {
|
||||||
|
|
||||||
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.registry = helper.readResourceLocation(in);
|
this.registry = helper.readResourceLocation(in);
|
||||||
this.entries = new ArrayList<>();
|
this.entries = helper.readList(in, buf -> new RegistryEntry(helper.readResourceLocation(buf), helper.readNullable(buf, helper::readCompoundTag)));
|
||||||
|
|
||||||
int entryCount = helper.readVarInt(in);
|
|
||||||
for (int i = 0; i < entryCount; i++) {
|
|
||||||
this.entries.add(new RegistryEntry(helper.readResourceLocation(in), helper.readNullable(in, helper::readCompoundTag)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeResourceLocation(out, this.registry);
|
helper.writeResourceLocation(out, this.registry);
|
||||||
|
helper.writeList(out, this.entries, (buf, entry) -> {
|
||||||
helper.writeVarInt(out, this.entries.size());
|
helper.writeResourceLocation(buf, entry.getId());
|
||||||
for (RegistryEntry entry : this.entries) {
|
helper.writeNullable(buf, entry.getData(), helper::writeAnyTag);
|
||||||
helper.writeResourceLocation(out, entry.getId());
|
});
|
||||||
helper.writeNullable(out, entry.getData(), helper::writeAnyTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.KnownPack;
|
import org.geysermc.mcprotocollib.protocol.data.game.KnownPack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -18,20 +17,15 @@ public class ClientboundSelectKnownPacks implements MinecraftPacket {
|
||||||
private final List<KnownPack> knownPacks;
|
private final List<KnownPack> knownPacks;
|
||||||
|
|
||||||
public ClientboundSelectKnownPacks(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundSelectKnownPacks(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.knownPacks = new ArrayList<>();
|
this.knownPacks = helper.readList(in, buf -> new KnownPack(helper.readString(buf), helper.readString(buf), helper.readString(buf)));
|
||||||
int entryCount = helper.readVarInt(in);
|
|
||||||
for (int i = 0; i < entryCount; i++) {
|
|
||||||
this.knownPacks.add(new KnownPack(helper.readString(in), helper.readString(in), helper.readString(in)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeVarInt(out, this.knownPacks.size());
|
helper.writeList(out, this.knownPacks, (buf, entry) -> {
|
||||||
for (KnownPack entry : this.knownPacks) {
|
helper.writeString(buf, entry.getNamespace());
|
||||||
helper.writeString(out, entry.getNamespace());
|
helper.writeString(buf, entry.getId());
|
||||||
helper.writeString(out, entry.getId());
|
helper.writeString(buf, entry.getVersion());
|
||||||
helper.writeString(out, entry.getVersion());
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,11 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
|
||||||
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.sender = helper.readUUID(in);
|
this.sender = helper.readUUID(in);
|
||||||
this.index = helper.readVarInt(in);
|
this.index = helper.readVarInt(in);
|
||||||
if (in.readBoolean()) {
|
this.messageSignature = helper.readNullable(in, buf -> {
|
||||||
this.messageSignature = new byte[256];
|
byte[] signature = new byte[256];
|
||||||
in.readBytes(this.messageSignature);
|
buf.readBytes(signature);
|
||||||
} else {
|
return signature;
|
||||||
this.messageSignature = null;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.content = helper.readString(in, 256);
|
this.content = helper.readString(in, 256);
|
||||||
this.timeStamp = in.readLong();
|
this.timeStamp = in.readLong();
|
||||||
|
@ -67,10 +66,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeUUID(out, this.sender);
|
helper.writeUUID(out, this.sender);
|
||||||
helper.writeVarInt(out, this.index);
|
helper.writeVarInt(out, this.index);
|
||||||
out.writeBoolean(this.messageSignature != null);
|
helper.writeNullable(out, this.messageSignature, ByteBuf::writeBytes);
|
||||||
if (this.messageSignature != null) {
|
|
||||||
out.writeBytes(this.messageSignature);
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.writeString(out, this.content);
|
helper.writeString(out, this.content);
|
||||||
out.writeLong(this.timeStamp);
|
out.writeLong(this.timeStamp);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import lombok.With;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -18,17 +17,10 @@ public class ClientboundPlayerInfoRemovePacket implements MinecraftPacket {
|
||||||
private final List<UUID> profileIds;
|
private final List<UUID> profileIds;
|
||||||
|
|
||||||
public ClientboundPlayerInfoRemovePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundPlayerInfoRemovePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.profileIds = new ArrayList<>();
|
this.profileIds = helper.readList(in, helper::readUUID);
|
||||||
int numIds = helper.readVarInt(in);
|
|
||||||
for (int i = 0; i < numIds; i++) {
|
|
||||||
this.profileIds.add(helper.readUUID(in));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeVarInt(out, this.profileIds.size());
|
helper.writeList(out, this.profileIds, helper::writeUUID);
|
||||||
for (UUID id : this.profileIds) {
|
|
||||||
helper.writeUUID(out, id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@ import java.security.GeneralSecurityException;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
|
@ -36,13 +34,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ADD_PLAYER -> {
|
case ADD_PLAYER -> {
|
||||||
GameProfile profile = new GameProfile(entry.getProfileId(), helper.readString(in, 16));
|
GameProfile profile = new GameProfile(entry.getProfileId(), helper.readString(in, 16));
|
||||||
int propertyCount = helper.readVarInt(in);
|
profile.setProperties(helper.readList(in, helper::readProperty));
|
||||||
List<GameProfile.Property> propertyList = new ArrayList<>();
|
|
||||||
for (int index = 0; index < propertyCount; index++) {
|
|
||||||
propertyList.add(helper.readProperty(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
profile.setProperties(propertyList);
|
|
||||||
|
|
||||||
entry.setProfile(profile);
|
entry.setProfile(profile);
|
||||||
}
|
}
|
||||||
|
@ -104,10 +96,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.writeString(out, profile.getName());
|
helper.writeString(out, profile.getName());
|
||||||
helper.writeVarInt(out, profile.getProperties().size());
|
helper.writeList(out, profile.getProperties(), helper::writeProperty);
|
||||||
for (GameProfile.Property property : profile.getProperties()) {
|
|
||||||
helper.writeProperty(out, property);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case INITIALIZE_CHAT -> {
|
case INITIALIZE_CHAT -> {
|
||||||
out.writeBoolean(entry.getPublicKey() != null);
|
out.writeBoolean(entry.getPublicKey() != null);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
|
|
||||||
|
@ -11,23 +12,14 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSelectAdvancementsTabPacket implements MinecraftPacket {
|
public class ClientboundSelectAdvancementsTabPacket implements MinecraftPacket {
|
||||||
private final String tabId;
|
private final @Nullable String tabId;
|
||||||
|
|
||||||
public ClientboundSelectAdvancementsTabPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundSelectAdvancementsTabPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
if (in.readBoolean()) {
|
this.tabId = helper.readNullable(in, helper::readString);
|
||||||
this.tabId = helper.readString(in);
|
|
||||||
} else {
|
|
||||||
this.tabId = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
if (this.tabId != null) {
|
helper.writeNullable(out, this.tabId, helper::writeString);
|
||||||
out.writeBoolean(true);
|
|
||||||
helper.writeString(out, this.tabId);
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.advancement.Advancement.Dis
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.advancement.Advancement.DisplayData.AdvancementType;
|
import org.geysermc.mcprotocollib.protocol.data.game.advancement.Advancement.DisplayData.AdvancementType;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -51,36 +50,25 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
|
||||||
for (int i = 0; i < this.advancements.length; i++) {
|
for (int i = 0; i < this.advancements.length; i++) {
|
||||||
String id = helper.readString(in);
|
String id = helper.readString(in);
|
||||||
String parentId = helper.readNullable(in, helper::readString);
|
String parentId = helper.readNullable(in, helper::readString);
|
||||||
DisplayData displayData = null;
|
DisplayData displayData = helper.readNullable(in, buf -> {
|
||||||
if (in.readBoolean()) {
|
Component title = helper.readComponent(buf);
|
||||||
Component title = helper.readComponent(in);
|
Component description = helper.readComponent(buf);
|
||||||
Component description = helper.readComponent(in);
|
ItemStack icon = helper.readOptionalItemStack(buf);
|
||||||
ItemStack icon = helper.readOptionalItemStack(in);
|
AdvancementType advancementType = AdvancementType.from(helper.readVarInt(buf));
|
||||||
AdvancementType advancementType = AdvancementType.from(helper.readVarInt(in));
|
|
||||||
|
|
||||||
int flags = in.readInt();
|
int flags = buf.readInt();
|
||||||
boolean hasBackgroundTexture = (flags & FLAG_HAS_BACKGROUND_TEXTURE) != 0;
|
boolean hasBackgroundTexture = (flags & FLAG_HAS_BACKGROUND_TEXTURE) != 0;
|
||||||
boolean showToast = (flags & FLAG_SHOW_TOAST) != 0;
|
boolean showToast = (flags & FLAG_SHOW_TOAST) != 0;
|
||||||
boolean hidden = (flags & FLAG_HIDDEN) != 0;
|
boolean hidden = (flags & FLAG_HIDDEN) != 0;
|
||||||
|
|
||||||
String backgroundTexture = hasBackgroundTexture ? helper.readString(in) : null;
|
String backgroundTexture = hasBackgroundTexture ? helper.readString(buf) : null;
|
||||||
float posX = in.readFloat();
|
float posX = buf.readFloat();
|
||||||
float posY = in.readFloat();
|
float posY = buf.readFloat();
|
||||||
|
|
||||||
displayData = new DisplayData(title, description, icon, advancementType, showToast, hidden, posX, posY, backgroundTexture);
|
return new DisplayData(title, description, icon, advancementType, showToast, hidden, posX, posY, backgroundTexture);
|
||||||
}
|
});
|
||||||
|
|
||||||
List<List<String>> requirements = new ArrayList<>();
|
List<List<String>> requirements = helper.readList(in, buf -> helper.readList(buf, helper::readString));
|
||||||
int requirementCount = helper.readVarInt(in);
|
|
||||||
for (int j = 0; j < requirementCount; j++) {
|
|
||||||
List<String> requirement = new ArrayList<>();
|
|
||||||
int componentCount = helper.readVarInt(in);
|
|
||||||
for (int k = 0; k < componentCount; k++) {
|
|
||||||
requirement.add(helper.readString(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
requirements.add(requirement);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean sendTelemetryEvent = in.readBoolean();
|
boolean sendTelemetryEvent = in.readBoolean();
|
||||||
|
|
||||||
|
@ -123,47 +111,36 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayData displayData = advancement.getDisplayData();
|
helper.writeNullable(out, advancement.getDisplayData(), (buf, data) -> {
|
||||||
if (displayData != null) {
|
helper.writeComponent(buf, data.getTitle());
|
||||||
out.writeBoolean(true);
|
helper.writeComponent(buf, data.getDescription());
|
||||||
helper.writeComponent(out, displayData.getTitle());
|
helper.writeOptionalItemStack(buf, data.getIcon());
|
||||||
helper.writeComponent(out, displayData.getDescription());
|
helper.writeVarInt(buf, data.getAdvancementType().ordinal());
|
||||||
helper.writeOptionalItemStack(out, displayData.getIcon());
|
|
||||||
helper.writeVarInt(out, displayData.getAdvancementType().ordinal());
|
|
||||||
String backgroundTexture = displayData.getBackgroundTexture();
|
|
||||||
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
if (backgroundTexture != null) {
|
if (data.getBackgroundTexture() != null) {
|
||||||
flags |= FLAG_HAS_BACKGROUND_TEXTURE;
|
flags |= FLAG_HAS_BACKGROUND_TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayData.isShowToast()) {
|
if (data.isShowToast()) {
|
||||||
flags |= FLAG_SHOW_TOAST;
|
flags |= FLAG_SHOW_TOAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (displayData.isHidden()) {
|
if (data.isHidden()) {
|
||||||
flags |= FLAG_HIDDEN;
|
flags |= FLAG_HIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeInt(flags);
|
buf.writeInt(flags);
|
||||||
|
|
||||||
if (backgroundTexture != null) {
|
if (data.getBackgroundTexture() != null) {
|
||||||
helper.writeString(out, backgroundTexture);
|
helper.writeString(buf, data.getBackgroundTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeFloat(displayData.getPosX());
|
buf.writeFloat(data.getPosX());
|
||||||
out.writeFloat(displayData.getPosY());
|
buf.writeFloat(data.getPosY());
|
||||||
} else {
|
});
|
||||||
out.writeBoolean(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.writeVarInt(out, advancement.getRequirements().size());
|
helper.writeList(out, advancement.getRequirements(), (buf, requirement) -> helper.writeList(buf, requirement, helper::writeString));
|
||||||
for (List<String> requirement : advancement.getRequirements()) {
|
|
||||||
helper.writeVarInt(out, requirement.size());
|
|
||||||
for (String criterion : requirement) {
|
|
||||||
helper.writeString(out, criterion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeBoolean(advancement.isSendsTelemetryEvent());
|
out.writeBoolean(advancement.isSendsTelemetryEvent());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkBiomeData;
|
import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkBiomeData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -16,22 +15,18 @@ public class ClientboundChunksBiomesPacket implements MinecraftPacket {
|
||||||
private final List<ChunkBiomeData> chunkBiomeData;
|
private final List<ChunkBiomeData> chunkBiomeData;
|
||||||
|
|
||||||
public ClientboundChunksBiomesPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundChunksBiomesPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.chunkBiomeData = new ArrayList<>();
|
this.chunkBiomeData = helper.readList(in, buf -> {
|
||||||
|
long raw = buf.readLong();
|
||||||
int length = helper.readVarInt(in);
|
return new ChunkBiomeData((int) raw, (int) (raw >> 32), helper.readByteArray(buf));
|
||||||
for (int i = 0; i < length; i++) {
|
});
|
||||||
long raw = in.readLong();
|
|
||||||
this.chunkBiomeData.add(new ChunkBiomeData((int) raw, (int) (raw >> 32), helper.readByteArray(in)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeVarInt(out, this.chunkBiomeData.size());
|
helper.writeList(out, this.chunkBiomeData, (buf, entry) -> {
|
||||||
for (ChunkBiomeData entry : this.chunkBiomeData) {
|
|
||||||
long raw = (long) entry.getX() & 0xFFFFFFFFL | ((long) entry.getZ() & 0xFFFFFFFFL) << 32;
|
long raw = (long) entry.getX() & 0xFFFFFFFFL | ((long) entry.getZ() & 0xFFFFFFFFL) << 32;
|
||||||
out.writeLong(raw);
|
buf.writeLong(raw);
|
||||||
helper.writeByteArray(out, entry.getBuffer());
|
helper.writeByteArray(buf, entry.getBuffer());
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,10 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.ExplosionInteraction;
|
import org.geysermc.mcprotocollib.protocol.data.game.level.block.ExplosionInteraction;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
|
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.CustomSound;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -37,11 +38,7 @@ public class ClientboundExplodePacket implements MinecraftPacket {
|
||||||
this.y = in.readDouble();
|
this.y = in.readDouble();
|
||||||
this.z = in.readDouble();
|
this.z = in.readDouble();
|
||||||
this.radius = in.readFloat();
|
this.radius = in.readFloat();
|
||||||
this.exploded = new ArrayList<>();
|
this.exploded = helper.readList(in, buf -> Vector3i.from(buf.readByte(), buf.readByte(), buf.readByte()));
|
||||||
int length = helper.readVarInt(in);
|
|
||||||
for (int count = 0; count < length; count++) {
|
|
||||||
this.exploded.add(Vector3i.from(in.readByte(), in.readByte(), in.readByte()));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pushX = in.readFloat();
|
this.pushX = in.readFloat();
|
||||||
this.pushY = in.readFloat();
|
this.pushY = in.readFloat();
|
||||||
|
@ -49,7 +46,7 @@ public class ClientboundExplodePacket implements MinecraftPacket {
|
||||||
this.blockInteraction = ExplosionInteraction.from(helper.readVarInt(in)); // different order than mojang fields
|
this.blockInteraction = ExplosionInteraction.from(helper.readVarInt(in)); // different order than mojang fields
|
||||||
this.smallExplosionParticles = helper.readParticle(in);
|
this.smallExplosionParticles = helper.readParticle(in);
|
||||||
this.largeExplosionParticles = helper.readParticle(in);
|
this.largeExplosionParticles = helper.readParticle(in);
|
||||||
this.explosionSound = helper.readSoundEvent(in);
|
this.explosionSound = helper.readById(in, BuiltinSound::from, helper::readSoundEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,12 +55,11 @@ public class ClientboundExplodePacket implements MinecraftPacket {
|
||||||
out.writeDouble(this.y);
|
out.writeDouble(this.y);
|
||||||
out.writeDouble(this.z);
|
out.writeDouble(this.z);
|
||||||
out.writeFloat(this.radius);
|
out.writeFloat(this.radius);
|
||||||
helper.writeVarInt(out, this.exploded.size());
|
helper.writeList(out, this.exploded, (buf, record) -> {
|
||||||
for (Vector3i record : this.exploded) {
|
buf.writeByte(record.getX());
|
||||||
out.writeByte(record.getX());
|
buf.writeByte(record.getY());
|
||||||
out.writeByte(record.getY());
|
buf.writeByte(record.getZ());
|
||||||
out.writeByte(record.getZ());
|
});
|
||||||
}
|
|
||||||
|
|
||||||
out.writeFloat(this.pushX);
|
out.writeFloat(this.pushX);
|
||||||
out.writeFloat(this.pushY);
|
out.writeFloat(this.pushY);
|
||||||
|
@ -71,6 +67,11 @@ public class ClientboundExplodePacket implements MinecraftPacket {
|
||||||
helper.writeVarInt(out, this.blockInteraction.ordinal()); // different order than mojang fields
|
helper.writeVarInt(out, this.blockInteraction.ordinal()); // different order than mojang fields
|
||||||
helper.writeParticle(out, this.smallExplosionParticles);
|
helper.writeParticle(out, this.smallExplosionParticles);
|
||||||
helper.writeParticle(out, this.largeExplosionParticles);
|
helper.writeParticle(out, this.largeExplosionParticles);
|
||||||
|
if (this.explosionSound instanceof CustomSound) {
|
||||||
|
helper.writeVarInt(out, 0);
|
||||||
helper.writeSoundEvent(out, this.explosionSound);
|
helper.writeSoundEvent(out, this.explosionSound);
|
||||||
|
} else {
|
||||||
|
helper.writeVarInt(out, ((BuiltinSound) this.explosionSound).ordinal() + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,7 @@ public class ClientboundMapItemDataPacket implements MinecraftPacket {
|
||||||
int x = in.readByte();
|
int x = in.readByte();
|
||||||
int z = in.readByte();
|
int z = in.readByte();
|
||||||
int rotation = in.readByte();
|
int rotation = in.readByte();
|
||||||
Component displayName = null;
|
Component displayName = helper.readNullable(in, helper::readComponent);
|
||||||
if (in.readBoolean()) {
|
|
||||||
displayName = helper.readComponent(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.icons[index] = new MapIcon(x, z, MapIconType.from(type), rotation, displayName);
|
this.icons[index] = new MapIcon(x, z, MapIconType.from(type), rotation, displayName);
|
||||||
}
|
}
|
||||||
|
@ -75,12 +72,7 @@ public class ClientboundMapItemDataPacket implements MinecraftPacket {
|
||||||
out.writeByte(icon.getCenterX());
|
out.writeByte(icon.getCenterX());
|
||||||
out.writeByte(icon.getCenterZ());
|
out.writeByte(icon.getCenterZ());
|
||||||
out.writeByte(icon.getIconRotation());
|
out.writeByte(icon.getIconRotation());
|
||||||
if (icon.getDisplayName() != null) {
|
helper.writeNullable(out, icon.getDisplayName(), helper::writeComponent);
|
||||||
out.writeBoolean(true);
|
|
||||||
helper.writeComponent(out, icon.getDisplayName());
|
|
||||||
} else {
|
|
||||||
out.writeBoolean(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
|
|
|
@ -26,12 +26,11 @@ public class ServerboundChatPacket implements MinecraftPacket {
|
||||||
this.message = helper.readString(in);
|
this.message = helper.readString(in);
|
||||||
this.timeStamp = in.readLong();
|
this.timeStamp = in.readLong();
|
||||||
this.salt = in.readLong();
|
this.salt = in.readLong();
|
||||||
if (in.readBoolean()) {
|
this.signature = helper.readNullable(in, buf -> {
|
||||||
this.signature = new byte[256];
|
byte[] signature = new byte[256];
|
||||||
in.readBytes(this.signature);
|
buf.readBytes(signature);
|
||||||
} else {
|
return signature;
|
||||||
this.signature = null;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
this.offset = helper.readVarInt(in);
|
this.offset = helper.readVarInt(in);
|
||||||
this.acknowledgedMessages = helper.readFixedBitSet(in, 20);
|
this.acknowledgedMessages = helper.readFixedBitSet(in, 20);
|
||||||
|
@ -42,10 +41,7 @@ public class ServerboundChatPacket implements MinecraftPacket {
|
||||||
helper.writeString(out, this.message);
|
helper.writeString(out, this.message);
|
||||||
out.writeLong(this.timeStamp);
|
out.writeLong(this.timeStamp);
|
||||||
out.writeLong(this.salt);
|
out.writeLong(this.salt);
|
||||||
out.writeBoolean(this.signature != null);
|
helper.writeNullable(out, this.signature, ByteBuf::writeBytes);
|
||||||
if (this.signature != null) {
|
|
||||||
out.writeBytes(this.signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.writeVarInt(out, this.offset);
|
helper.writeVarInt(out, this.offset);
|
||||||
helper.writeFixedBitSet(out, this.acknowledgedMessages, 20);
|
helper.writeFixedBitSet(out, this.acknowledgedMessages, 20);
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -21,28 +20,14 @@ public class ServerboundEditBookPacket implements MinecraftPacket {
|
||||||
|
|
||||||
public ServerboundEditBookPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ServerboundEditBookPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.slot = helper.readVarInt(in);
|
this.slot = helper.readVarInt(in);
|
||||||
this.pages = new ArrayList<>();
|
this.pages = helper.readList(in, helper::readString);
|
||||||
int pagesSize = helper.readVarInt(in);
|
this.title = helper.readNullable(in, helper::readString);
|
||||||
for (int i = 0; i < pagesSize; i++) {
|
|
||||||
this.pages.add(helper.readString(in));
|
|
||||||
}
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
this.title = helper.readString(in);
|
|
||||||
} else {
|
|
||||||
this.title = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeVarInt(out, slot);
|
helper.writeVarInt(out, slot);
|
||||||
helper.writeVarInt(out, this.pages.size());
|
helper.writeList(out, pages, helper::writeString);
|
||||||
for (String page : this.pages) {
|
helper.writeNullable(out, title, helper::writeString);
|
||||||
helper.writeString(out, page);
|
|
||||||
}
|
|
||||||
out.writeBoolean(this.title != null);
|
|
||||||
if (this.title != null) {
|
|
||||||
helper.writeString(out, title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,6 @@ import lombok.With;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -21,20 +18,7 @@ public class ClientboundGameProfilePacket implements MinecraftPacket {
|
||||||
|
|
||||||
public ClientboundGameProfilePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundGameProfilePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
GameProfile profile = new GameProfile(helper.readUUID(in), helper.readString(in));
|
GameProfile profile = new GameProfile(helper.readUUID(in), helper.readString(in));
|
||||||
int properties = helper.readVarInt(in);
|
profile.setProperties(helper.readList(in, helper::readProperty));
|
||||||
List<GameProfile.Property> propertyList = new ArrayList<>();
|
|
||||||
for (int index = 0; index < properties; index++) {
|
|
||||||
String propertyName = helper.readString(in);
|
|
||||||
String value = helper.readString(in);
|
|
||||||
String signature = null;
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
signature = helper.readString(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
propertyList.add(new GameProfile.Property(propertyName, value, signature));
|
|
||||||
}
|
|
||||||
|
|
||||||
profile.setProperties(propertyList);
|
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
this.strictErrorHandling = in.readBoolean();
|
this.strictErrorHandling = in.readBoolean();
|
||||||
}
|
}
|
||||||
|
@ -43,15 +27,7 @@ public class ClientboundGameProfilePacket implements MinecraftPacket {
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeUUID(out, this.profile.getId());
|
helper.writeUUID(out, this.profile.getId());
|
||||||
helper.writeString(out, this.profile.getName());
|
helper.writeString(out, this.profile.getName());
|
||||||
helper.writeVarInt(out, this.profile.getProperties().size());
|
helper.writeList(out, this.profile.getProperties(), helper::writeProperty);
|
||||||
for (GameProfile.Property property : this.profile.getProperties()) {
|
|
||||||
helper.writeString(out, property.getName());
|
|
||||||
helper.writeString(out, property.getValue());
|
|
||||||
out.writeBoolean(property.hasSignature());
|
|
||||||
if (property.hasSignature()) {
|
|
||||||
helper.writeString(out, property.getSignature());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.writeBoolean(this.strictErrorHandling);
|
out.writeBoolean(this.strictErrorHandling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue