mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-10 01:11:25 +01:00
fix: dont oom reading item component, stub banner pattern component
This commit is contained in:
parent
0ed5a2ad16
commit
67fe007bb3
@ -132,6 +132,9 @@ public class PlayerInit {
|
||||
.set(ItemComponent.BLOCK_STATE, new ItemBlockState(Map.of("facing", "west", "half", "top")))
|
||||
.build());
|
||||
|
||||
player.getInventory().addItemStack(ItemStack.builder(Material.BLACK_BANNER)
|
||||
.build());
|
||||
|
||||
if (event.isFirstSpawn()) {
|
||||
Notification notification = new Notification(
|
||||
Component.text("Welcome!"),
|
||||
|
@ -69,7 +69,7 @@ public sealed interface ItemComponent<T> extends StaticProtocolObject permits It
|
||||
ItemComponent<FireworkList> FIREWORKS = declare("fireworks", FireworkList.NETWORK_TYPE, FireworkList.NBT_TYPE);
|
||||
ItemComponent<HeadProfile> PROFILE = declare("profile", HeadProfile.NETWORK_TYPE, HeadProfile.NBT_TYPE);
|
||||
ItemComponent<String> NOTE_BLOCK_SOUND = declare("note_block_sound", NetworkBuffer.STRING, BinaryTagSerializer.STRING);
|
||||
ItemComponent<Void> BANNER_PATTERNS = declare("banner_patterns", null, null); //todo
|
||||
ItemComponent<BannerPatterns> BANNER_PATTERNS = declare("banner_patterns", BannerPatterns.NETWORK_TYPE, BannerPatterns.NBT_TYPE);
|
||||
ItemComponent<DyeColor> BASE_COLOR = declare("base_color", DyeColor.NETWORK_TYPE, DyeColor.NBT_TYPE);
|
||||
ItemComponent<PotDecorations> POT_DECORATIONS = declare("pot_decorations", PotDecorations.NETWORK_TYPE, PotDecorations.NBT_TYPE);
|
||||
ItemComponent<List<ItemStack>> CONTAINER = declare("container", ItemStack.NETWORK_TYPE.list(256), BinaryTagSerializer.ITEM.list());
|
||||
|
@ -22,6 +22,8 @@ import java.util.Map;
|
||||
record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
||||
private static final char REMOVAL_PREFIX = '!';
|
||||
|
||||
static final int MAX_SIZE = ItemComponent.values().size() * 2;
|
||||
|
||||
public static final ItemComponentPatch EMPTY = new ItemComponentPatch(new Int2ObjectArrayMap<>(0));
|
||||
|
||||
public static final @NotNull NetworkBuffer.Type<ItemComponentPatch> NETWORK_TYPE = new NetworkBuffer.Type<>() {
|
||||
@ -54,6 +56,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
||||
public ItemComponentPatch read(@NotNull NetworkBuffer buffer) {
|
||||
int added = buffer.read(NetworkBuffer.VAR_INT);
|
||||
int removed = buffer.read(NetworkBuffer.VAR_INT);
|
||||
Check.stateCondition(added + removed > MAX_SIZE, "Item component patch too large: {0}", added + removed);
|
||||
Int2ObjectMap<Object> patch = new Int2ObjectArrayMap<>(added + removed);
|
||||
for (int i = 0; i < added; i++) {
|
||||
int id = buffer.read(NetworkBuffer.VAR_INT);
|
||||
|
@ -0,0 +1,48 @@
|
||||
package net.minestom.server.item.component;
|
||||
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import net.minestom.server.color.DyeColor;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.utils.nbt.BinaryTagSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record BannerPatterns(@NotNull List<Layer> layers) {
|
||||
public static final int MAX_LAYERS = 1024;
|
||||
|
||||
// public static final NetworkBuffer.Type<BannerPatterns> NETWORK_TYPE = Layer.NETWORK_TYPE.list(MAX_LAYERS).map(BannerPatterns::new, BannerPatterns::layers);
|
||||
public static final NetworkBuffer.Type<BannerPatterns> NETWORK_TYPE = new NetworkBuffer.Type<>() {
|
||||
@Override
|
||||
public void write(@NotNull NetworkBuffer buffer, BannerPatterns value) {
|
||||
buffer.write(NetworkBuffer.VAR_INT, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BannerPatterns read(@NotNull NetworkBuffer buffer) {
|
||||
throw new UnsupportedOperationException("todo, banner pattern registry");
|
||||
}
|
||||
};
|
||||
public static final BinaryTagSerializer<BannerPatterns> NBT_TYPE = Layer.NBT_TYPE.list().map(BannerPatterns::new, BannerPatterns::layers);
|
||||
|
||||
public record Layer(@NotNull String pattern, @NotNull DyeColor color) {
|
||||
public static final NetworkBuffer.Type<Layer> NETWORK_TYPE = new NetworkBuffer.Type<>() {
|
||||
@Override
|
||||
public void write(@NotNull NetworkBuffer buffer, Layer value) {
|
||||
throw new UnsupportedOperationException("todo, banner pattern registry");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Layer read(@NotNull NetworkBuffer buffer) {
|
||||
throw new UnsupportedOperationException("todo, banner pattern registry");
|
||||
}
|
||||
};
|
||||
public static final BinaryTagSerializer<Layer> NBT_TYPE = BinaryTagSerializer.COMPOUND.map(
|
||||
tag -> new Layer(tag.getString("pattern"), DyeColor.NBT_TYPE.read(tag.get("color"))),
|
||||
layer -> CompoundBinaryTag.builder()
|
||||
.putString("pattern", layer.pattern)
|
||||
.put("color", DyeColor.NBT_TYPE.write(layer.color))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user