From b7931f8d704f638273bb13215df0077fd144e049 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 6 Jun 2024 23:34:06 +0200 Subject: [PATCH 1/3] Update protocol to suppress packet warnings --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1995a6ada..9ff1f3afd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ netty-io-uring = "0.0.25.Final-SNAPSHOT" guava = "29.0-jre" gson = "2.3.1" # Provided by Spigot 1.8.8 websocket = "1.5.1" -protocol = "3.0.0.Beta2-20240520.153053-5" +protocol = "3.0.0.Beta2-20240606.172607-7" raknet = "1.0.0.CR3-20240416.144209-1" mcauthlib = "e5b0bcc" mcprotocollib = "1.20.6-2-20240520.030045-8" From 8ae1150c8026af625bd39143b50f3b9a08acdfed Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Fri, 7 Jun 2024 19:47:21 +0200 Subject: [PATCH 2/3] Remove unused lectern code in ModWorldManager, fix spelling error in SessionLoginEvent --- .../api/event/bedrock/SessionLoginEvent.java | 6 +-- .../mod/world/GeyserModWorldManager.java | 38 ------------------- 2 files changed, 3 insertions(+), 41 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java index 522562d11..86a5ec6f8 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java @@ -36,7 +36,7 @@ import java.util.Map; import java.util.Objects; /** - * Called when a session has logged in, and is about to connect to a remote java server. + * Called when a session has logged in, and is about to connect to a remote Java server. * This event is cancellable, and can be used to prevent the player from connecting to the remote server. */ public final class SessionLoginEvent extends ConnectionEvent implements Cancellable { @@ -99,9 +99,9 @@ public final class SessionLoginEvent extends ConnectionEvent implements Cancella } /** - * Gets the {@link RemoteServer} the section will attempt to connect to. + * Gets the {@link RemoteServer} the session will attempt to connect to. * - * @return the {@link RemoteServer} the section will attempt to connect to. + * @return the {@link RemoteServer} the session will attempt to connect to. */ public @NonNull RemoteServer remoteServer() { return this.remoteServer; diff --git a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/world/GeyserModWorldManager.java b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/world/GeyserModWorldManager.java index 7aac684bb..5543dbcee 100644 --- a/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/world/GeyserModWorldManager.java +++ b/bootstrap/mod/src/main/java/org/geysermc/geyser/platform/mod/world/GeyserModWorldManager.java @@ -26,7 +26,6 @@ package org.geysermc.geyser.platform.mod.world; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.minecraft.SharedConstants; import net.minecraft.core.BlockPos; import net.minecraft.core.RegistryAccess; @@ -34,10 +33,7 @@ import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.Filterable; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.component.WritableBookContent; -import net.minecraft.world.item.component.WrittenBookContent; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BannerBlockEntity; @@ -63,7 +59,6 @@ import java.util.concurrent.CompletableFuture; public class GeyserModWorldManager extends GeyserWorldManager { private static final GsonComponentSerializer GSON_SERIALIZER = GsonComponentSerializer.gson(); - private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.legacySection(); private final MinecraftServer server; public GeyserModWorldManager(MinecraftServer server) { @@ -169,39 +164,6 @@ public class GeyserModWorldManager extends GeyserWorldManager { return server.getPlayerList().getPlayer(session.getPlayerEntity().getUuid()); } - private static int getPageCount(ItemStack itemStack) { - WrittenBookContent writtenBookContent = itemStack.get(DataComponents.WRITTEN_BOOK_CONTENT); - if (writtenBookContent != null) { - return writtenBookContent.pages().size(); - } else { - WritableBookContent writableBookContent = itemStack.get(DataComponents.WRITABLE_BOOK_CONTENT); - return writableBookContent != null ? writableBookContent.pages().size() : 0; - } - } - - private static List getPages(ItemStack itemStack) { - WrittenBookContent writtenBookContent = itemStack.get(DataComponents.WRITTEN_BOOK_CONTENT); - if (writtenBookContent != null) { - return writtenBookContent.pages().stream() - .map(Filterable::raw) - .map(GeyserModWorldManager::fromComponent) - .toList(); - } else { - WritableBookContent writableBookContent = itemStack.get(DataComponents.WRITABLE_BOOK_CONTENT); - if (writableBookContent == null) { - return List.of(); - } - return writableBookContent.pages().stream() - .map(Filterable::raw) - .toList(); - } - } - - private static String fromComponent(Component component) { - String json = Component.Serializer.toJson(component, RegistryAccess.EMPTY); - return LEGACY_SERIALIZER.serialize(GSON_SERIALIZER.deserializeOr(json, net.kyori.adventure.text.Component.empty())); - } - private static net.kyori.adventure.text.Component toKyoriComponent(Component component) { String json = Component.Serializer.toJson(component, RegistryAccess.EMPTY); return GSON_SERIALIZER.deserializeOr(json, net.kyori.adventure.text.Component.empty()); From 007ecb4363dcb7ca0f396732b4440f274d5b9842 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:06:39 -0400 Subject: [PATCH 3/3] Ensure custom blocks can be represented at any index --- .../java/org/geysermc/geyser/item/Items.java | 8 +------- .../geyser/registry/ListRegistry.java | 20 +++++++++++++++++++ .../geysermc/geyser/registry/Registries.java | 5 ++++- .../populator/BlockRegistryPopulator.java | 3 +-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/item/Items.java b/core/src/main/java/org/geysermc/geyser/item/Items.java index 8c271a7bb..03f044068 100644 --- a/core/src/main/java/org/geysermc/geyser/item/Items.java +++ b/core/src/main/java/org/geysermc/geyser/item/Items.java @@ -30,8 +30,6 @@ import org.geysermc.geyser.item.type.*; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.registry.Registries; -import java.util.Collections; - import static org.geysermc.geyser.item.type.Item.builder; /** @@ -1378,11 +1376,7 @@ public final class Items { public static T register(T item, int id) { item.setJavaId(id); - // This makes sure that the array is large enough to put the java item at the correct location - if (Registries.JAVA_ITEMS.get().size() <= id) { - Registries.JAVA_ITEMS.get().addAll(Collections.nCopies(id - Registries.JAVA_ITEMS.get().size() + 1, AIR)); - } - Registries.JAVA_ITEMS.get().set(id, item); + Registries.JAVA_ITEMS.registerWithAnyIndex(id, item, AIR); Registries.JAVA_ITEM_IDENTIFIERS.register(item.javaIdentifier(), item); return item; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java index 34a78c370..2070d67ae 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.registry.loader.RegistryLoader; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.function.Supplier; @@ -94,6 +95,25 @@ public class ListRegistry extends Registry> { return this.mappings.set(index, value); } + /** + * Registers a new value into this registry with the given index, even if this value would normally be outside + * the range of a list. + * + * @param index the index + * @param value the value + * @param defaultValue the default value to fill empty spaces in the registry with. + * @return a new value into this registry with the given index. + */ + public M registerWithAnyIndex(int index, M value, M defaultValue) { + if (this.frozen) { + throw new IllegalStateException("Registry should not be modified after frozen!"); + } + if (this.mappings.size() <= index) { + this.mappings.addAll(Collections.nCopies(index - this.mappings.size() + 1, defaultValue)); + } + return this.mappings.set(index, value); + } + /** * Mark this registry as unsuitable for new additions. The backing list will then be optimized for storage. */ diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index 54d013140..b509d6ac0 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -127,7 +127,10 @@ public final class Registries { */ public static final PacketTranslatorRegistry JAVA_PACKET_TRANSLATORS = PacketTranslatorRegistry.create(); - public static final SimpleRegistry> JAVA_ITEMS = SimpleRegistry.create(RegistryLoaders.empty(ArrayList::new)); + /** + * A registry containing all Java items ordered by their network ID. + */ + public static final ListRegistry JAVA_ITEMS = ListRegistry.create(RegistryLoaders.empty(ArrayList::new)); public static final SimpleMappedRegistry JAVA_ITEM_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java index 6b856c509..a8fb0001d 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java @@ -213,7 +213,6 @@ public final class BlockRegistryPopulator { GeyserBedrockBlock[] javaToBedrockBlocks = new GeyserBedrockBlock[JAVA_BLOCKS_SIZE]; GeyserBedrockBlock[] javaToVanillaBedrockBlocks = new GeyserBedrockBlock[JAVA_BLOCKS_SIZE]; - //List javaToBedrockIdentifiers = new ArrayList<>(BlockRegistries.JAVA_BLOCKS.get().size()); var javaToBedrockIdentifiers = new Int2ObjectOpenHashMap(); Block lastBlockSeen = null; @@ -456,7 +455,7 @@ public final class BlockRegistryPopulator { }; block.setJavaId(javaBlockState.stateGroupId()); - BlockRegistries.JAVA_BLOCKS.get().add(javaBlockState.stateGroupId(), block); //TODO don't allow duplicates, allow blanks + BlockRegistries.JAVA_BLOCKS.registerWithAnyIndex(javaBlockState.stateGroupId(), block, Blocks.AIR); BlockRegistries.JAVA_IDENTIFIER_TO_ID.register(javaId, stateRuntimeId); BlockRegistries.BLOCK_STATES.register(stateRuntimeId, new BlockState(block, stateRuntimeId)); }