1.20.5-pre4, improve DataComponentPatch methods

This commit is contained in:
basaigh 2024-04-17 15:56:11 +01:00
parent ce74fb497e
commit a09e7fd4a3
2 changed files with 9 additions and 5 deletions

View file

@ -223,9 +223,9 @@ public class MinecraftCodec {
}
public static final PacketCodec CODEC = PacketCodec.builder()
.protocolVersion((1 << 30) | 187)
.protocolVersion((1 << 30) | 188)
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
.minecraftVersion("1.20.5-pre3")
.minecraftVersion("1.20.5-pre4")
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
)

View file

@ -2,6 +2,8 @@ package com.github.steveice10.mc.protocol.data.game.item.component;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@ -10,11 +12,13 @@ import java.util.Map;
public class DataComponentPatch {
private final Map<DataComponentType<?>, DataComponent<?, ?>> dataComponents;
public <T> DataComponent<T, DataComponentType<T>> get(DataComponentType<T> type) {
return (DataComponent<T, DataComponentType<T>>) dataComponents.get(type);
@Nullable
public <T> T get(DataComponentType<T> type) {
DataComponent component = dataComponents.get(type);
return component == null ? null : (T) component.getValue();
}
public <T> void put(DataComponentType<T> type, T value) {
public <T> void put(DataComponentType<T> type, @NonNull T value) {
dataComponents.put(type, type.dataComponentFactory.create(type, value));
}
}