Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.21 #824

Merged
merged 14 commits into from
Jun 13, 2024
2 changes: 1 addition & 1 deletion protocol/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("mcprotocollib.publish-conventions")
}

version = "1.20.6-2-SNAPSHOT"
version = "1.21-SNAPSHOT"
description = "MCProtocolLib is a simple library for communicating with Minecraft clients and servers."

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public Class<? extends Packet> getServerboundClass(int id) {

public static NbtMap loadNetworkCodec() {
try (InputStream inputStream = Objects.requireNonNull(MinecraftProtocol.class.getClassLoader().getResourceAsStream("networkCodec.nbt"))) {
return (NbtMap) NbtUtils.createGZIPReader(inputStream).readTag();
return (NbtMap) NbtUtils.createGZIPReader(inputStream).readTag(512);
} catch (Exception e) {
throw new AssertionError("Unable to load network codec.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundCookieRequestPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundCustomReportDetailsPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundKeepAlivePacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundPingPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundResourcePackPopPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundResourcePackPushPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundServerLinksPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundStoreCookiePacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundTransferPacket;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundUpdateTagsPacket;
Expand Down Expand Up @@ -223,9 +225,9 @@ public class MinecraftCodec {
}

public static final PacketCodec CODEC = PacketCodec.builder()
.protocolVersion(766)
.protocolVersion(767)
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
.minecraftVersion("1.20.6")
.minecraftVersion("1.21")
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
)
Expand Down Expand Up @@ -262,6 +264,8 @@ public class MinecraftCodec {
.registerClientboundPacket(ClientboundUpdateEnabledFeaturesPacket.class, ClientboundUpdateEnabledFeaturesPacket::new)
.registerClientboundPacket(ClientboundUpdateTagsPacket.class, ClientboundUpdateTagsPacket::new)
.registerClientboundPacket(ClientboundSelectKnownPacks.class, ClientboundSelectKnownPacks::new)
.registerClientboundPacket(ClientboundCustomReportDetailsPacket.class, ClientboundCustomReportDetailsPacket::new)
.registerClientboundPacket(ClientboundServerLinksPacket.class, ClientboundServerLinksPacket::new)
.registerServerboundPacket(ServerboundClientInformationPacket.class, ServerboundClientInformationPacket::new)
.registerServerboundPacket(ServerboundCookieResponsePacket.class, ServerboundCookieResponsePacket::new)
.registerServerboundPacket(ServerboundCustomPayloadPacket.class, ServerboundCustomPayloadPacket::new)
Expand Down Expand Up @@ -393,6 +397,8 @@ public class MinecraftCodec {
.registerClientboundPacket(ClientboundUpdateRecipesPacket.class, ClientboundUpdateRecipesPacket::new)
.registerClientboundPacket(ClientboundUpdateTagsPacket.class, ClientboundUpdateTagsPacket::new)
.registerClientboundPacket(ClientboundProjectilePowerPacket.class, ClientboundProjectilePowerPacket::new)
.registerClientboundPacket(ClientboundCustomReportDetailsPacket.class, ClientboundCustomReportDetailsPacket::new)
.registerClientboundPacket(ClientboundServerLinksPacket.class, ClientboundServerLinksPacket::new)
.registerServerboundPacket(ServerboundAcceptTeleportationPacket.class, ServerboundAcceptTeleportationPacket::new)
.registerServerboundPacket(ServerboundBlockEntityTagQueryPacket.class, ServerboundBlockEntityTagQueryPacket::new)
.registerServerboundPacket(ServerboundChangeDifficultyPacket.class, ServerboundChangeDifficultyPacket::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.geysermc.mcprotocollib.network.codec.BasePacketCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer;
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType;
import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatTypeDecoration;
import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.BlankFormat;
import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.FixedFormat;
import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.NumberFormat;
Expand All @@ -42,9 +44,11 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.PaintingVariant;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.SnifferState;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.VillagerData;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.WolfVariant;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.BlockBreakStage;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
Expand Down Expand Up @@ -92,6 +96,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Function;
Expand Down Expand Up @@ -477,12 +482,56 @@ public void writePose(ByteBuf buf, Pose pose) {
this.writeEnum(buf, pose);
}

public PaintingType readPaintingType(ByteBuf buf) {
return PaintingType.from(this.readVarInt(buf));
public Holder<WolfVariant> readWolfVariant(ByteBuf buf) {
return this.readHolder(buf, input -> {
Key wildTexture = this.readResourceLocation(input);
Key tameTexture = this.readResourceLocation(input);
Key angryTexture = this.readResourceLocation(input);
Key biomeLocation = null;
int[] biomeHolders = null;

int length = this.readVarInt(input) - 1;
if (length == -1) {
biomeLocation = this.readResourceLocation(input);
} else {
biomeHolders = new int[length];
for (int j = 0; j < length; j++) {
biomeHolders[j] = this.readVarInt(input);
}
}
return new WolfVariant(wildTexture, tameTexture, angryTexture, biomeLocation, biomeHolders);
});
}

public void writeWolfVariant(ByteBuf buf, Holder<WolfVariant> variantHolder) {
this.writeHolder(buf, variantHolder, (output, variant) -> {
this.writeResourceLocation(output, variant.wildTexture());
this.writeResourceLocation(output, variant.tameTexture());
this.writeResourceLocation(output, variant.angryTexture());
if (variant.biomeLocation() != null) {
this.writeVarInt(output, 0);
this.writeResourceLocation(output, variant.biomeLocation());
} else {
this.writeVarInt(output, variant.biomeHolders().length + 1);
for (int holder : variant.biomeHolders()) {
this.writeVarInt(output, holder);
}
}
});
}

public void writePaintingType(ByteBuf buf, PaintingType type) {
this.writeEnum(buf, type);
public Holder<PaintingVariant> readPaintingVariant(ByteBuf buf) {
return this.readHolder(buf, input -> {
return new PaintingVariant(this.readVarInt(input), this.readVarInt(input), this.readResourceLocation(input));
});
}

public void writePaintingVariant(ByteBuf buf, Holder<PaintingVariant> variantHolder) {
this.writeHolder(buf, variantHolder, (output, variant) -> {
this.writeVarInt(buf, variant.width());
this.writeVarInt(buf, variant.height());
this.writeResourceLocation(buf, variant.assetId());
});
}

public SnifferState readSnifferState(ByteBuf buf) {
Expand Down Expand Up @@ -717,6 +766,39 @@ public void writeNumberFormat(ByteBuf buf, NumberFormat numberFormat) {
}
}

public ChatType readChatType(ByteBuf buf) {
return new ChatType(readChatTypeDecoration(buf), readChatTypeDecoration(buf));
}

public void writeChatType(ByteBuf buf, ChatType chatType) {
this.writeChatTypeDecoration(buf, chatType.chat());
this.writeChatTypeDecoration(buf, chatType.narration());
}

public ChatTypeDecoration readChatTypeDecoration(ByteBuf buf) {
String translationKey = this.readString(buf);

int size = this.readVarInt(buf);
List<ChatTypeDecoration.Parameter> parameters = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
parameters.add(ChatTypeDecoration.Parameter.VALUES[this.readVarInt(buf)]);
}

NbtMap style = this.readCompoundTag(buf);
return new ChatType.ChatTypeDecorationImpl(translationKey, parameters, style);
}

public void writeChatTypeDecoration(ByteBuf buf, ChatTypeDecoration decoration) {
this.writeString(buf, decoration.translationKey());

this.writeVarInt(buf, decoration.parameters().size());
for (ChatTypeDecoration.Parameter parameter : decoration.parameters()) {
this.writeVarInt(buf, parameter.ordinal());
}

this.writeAnyTag(buf, decoration.style());
}

public PositionSource readPositionSource(ByteBuf buf) {
PositionSourceType type = PositionSourceType.from(this.readVarInt(buf));
return switch (type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.geysermc.mcprotocollib.protocol.data.game;

import java.util.function.Consumer;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;

/**
* Represents an object that could either be a network ID, or a custom-defined one.
Expand All @@ -22,9 +24,14 @@ static <T> Holder<T> ofCustom(T object) {

T custom();

Holder<T> ifId(Consumer<Holder<T>> action);
Holder<T> ifId(IntConsumer action);

Holder<T> ifCustom(Consumer<Holder<T>> action);
Holder<T> ifCustom(Consumer<T> action);

/**
* Returns the holder as an object, or else looks up the item in the registry.
*/
T getOrCompute(IntFunction<T> supplier);

record IdHolder<T>(int id) implements Holder<T> {
@Override
Expand All @@ -43,16 +50,21 @@ public T custom() {
}

@Override
public Holder<T> ifId(Consumer<Holder<T>> action) {
action.accept(this);
public Holder<T> ifId(IntConsumer action) {
action.accept(id);
return this;
}

@Override
public Holder<T> ifCustom(Consumer<Holder<T>> action) {
public Holder<T> ifCustom(Consumer<T> action) {
// no-op
return this;
}

@Override
public T getOrCompute(IntFunction<T> supplier) {
return supplier.apply(id);
}
}

record CustomHolder<T>(T object) implements Holder<T> {
Expand All @@ -77,14 +89,19 @@ public T custom() {
}

@Override
public Holder<T> ifId(Consumer<Holder<T>> action) {
public Holder<T> ifId(IntConsumer action) {
return this;
}

@Override
public Holder<T> ifCustom(Consumer<Holder<T>> action) {
action.accept(this);
public Holder<T> ifCustom(Consumer<T> action) {
action.accept(object);
return this;
}

@Override
public T getOrCompute(IntFunction<T> supplier) {
return object;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.geysermc.mcprotocollib.protocol.data.game;

import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

public record ServerLink(@Nullable ServerLinkType knownType, @Nullable Component unknownType, String link) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.geysermc.mcprotocollib.protocol.data.game;

public enum ServerLinkType {
BUG_REPORT,
COMMUNITY_GUIDELINES,
SUPPORT,
STATUS,
FEEDBACK,
COMMUNITY,
WEBSITE,
FORUMS,
NEWS,
ANNOUNCEMENTS;

private static final ServerLinkType[] VALUES = values();

public static ServerLinkType from(int id) {
return VALUES[id];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.geysermc.mcprotocollib.protocol.data.game.chat;

import org.cloudburstmc.nbt.NbtMap;

import java.util.List;

public record ChatType(ChatTypeDecoration chat, ChatTypeDecoration narration) {
public record ChatTypeDecorationImpl(String translationKey,
List<ChatTypeDecoration.Parameter> parameters,
NbtMap style) implements ChatTypeDecoration {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.geysermc.mcprotocollib.protocol.data.game.chat;

import org.cloudburstmc.nbt.NbtMap;

import java.util.List;

// Here for implementation if one wants to cache the Style tag while we don't have DFU Codecs.
public interface ChatTypeDecoration {
String translationKey();

List<Parameter> parameters();

NbtMap style();

enum Parameter {
CONTENT,
SENDER,
TARGET;

public static final Parameter[] VALUES = values();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import lombok.Data;
import lombok.NonNull;
import net.kyori.adventure.key.Key;

import java.util.UUID;

@Data
public class AttributeModifier {
/**
* Use {@link ModifierType} to determine built-in modifiers.
*/
private final @NonNull UUID uuid;
private final @NonNull Key id;
private final double amount;
private final @NonNull ModifierOperation operation;

public AttributeModifier(@NonNull UUID uuid, double amount, @NonNull ModifierOperation operation) {
this.uuid = uuid;
public AttributeModifier(@NonNull Key id, double amount, @NonNull ModifierOperation operation) {
this.id = id;
this.amount = amount;
this.operation = operation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,30 @@ enum Builtin implements AttributeType {
GENERIC_ATTACK_SPEED("minecraft:generic.attack_speed", 4, 0, 1024),
PLAYER_BLOCK_BREAK_SPEED("minecraft:player.block_break_speed", 1, 0, 1024),
PLAYER_BLOCK_INTERACTION_RANGE("minecraft:player.block_interaction_range", 4.5, 0, 64),
GENERIC_BURNING_TIME("minecraft:generic.burning_time", 1, 0, 1024),
GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE("minecraft:generic.explosion_knockback_resistance", 0, 0, 1),
PLAYER_ENTITY_INTERACTION_RANGE("minecraft:player.entity_interaction_range", 3, 0, 64),
GENERIC_FALL_DAMAGE_MULTIPLIER("minecraft:generic.fall_damage_multiplier", 1, 0, 100),
GENERIC_FLYING_SPEED("minecraft:generic.flying_speed", 0.4F, 0, 1024),
GENERIC_FLYING_SPEED("minecraft:generic.flying_speed", 0.4, 0, 1024),
GENERIC_FOLLOW_RANGE("minecraft:generic.follow_range", 32, 0, 2048),
GENERIC_GRAVITY("minecraft:generic.gravity", 0.08, -1, 1),
GENERIC_JUMP_STRENGTH("minecraft:generic.jump_strength", 0.42, 0, 32),
GENERIC_KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", 0, 0, 1),
GENERIC_LUCK("minecraft:generic.luck", 0, -1024, 1024),
GENERIC_MAX_ABSORPTION("minecraft:generic.max_absorption", 0, 0, 2048),
GENERIC_MAX_HEALTH("minecraft:generic.max_health", 20, 1, 1024),
GENERIC_MOVEMENT_SPEED("minecraft:generic.movement_speed", 0.7F, 0, 1024),
PLAYER_MINING_EFFICIENCY("minecraft:player.mining_efficiency", 0, 0, 1024),
GENERIC_MOVEMENT_EFFICIENCY("minecraft:generic.movement_efficiency", 0, 0, 1),
GENERIC_MOVEMENT_SPEED("minecraft:generic.movement_speed", 0.7, 0, 1024),
GENERIC_OXYGEN_BONUS("minecraft:generic.oxygen_bonus", 0, 0, 1024),
GENERIC_SAFE_FALL_DISTANCE("minecraft:generic.safe_fall_distance", 3, -1024, 1024),
GENERIC_SCALE("minecraft:generic.scale", 1, 0.0625, 16),
PLAYER_SNEAKING_SPEED("minecraft:player.sneaking_speed", 0.3, 0, 1),
ZOMBIE_SPAWN_REINFORCEMENTS("minecraft:zombie.spawn_reinforcements", 0, 0, 1),
GENERIC_STEP_HEIGHT("minecraft:generic.step_height", 0.6, 0, 10);
GENERIC_STEP_HEIGHT("minecraft:generic.step_height", 0.6, 0, 10),
PLAYER_SUBMERGED_MINING_SPEED("minecraft:player.submerged_mining_speed", 0.2, 0, 20),
PLAYER_SWEEPING_DAMAGE_RATIO("minecraft:player.sweeping_damage_ratio", 0, 0, 1),
GENERIC_WATER_MOVEMENT_EFFICIENCY("minecraft:generic.water_movement_efficiency", 0, 0, 1);

private final Key identifier;
private final double def;
Expand Down
Loading
Loading