From 94a810b68346cd3986e9380cb528aba815c0e7dd Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 18 Oct 2022 19:04:02 -0400 Subject: [PATCH] Initial 1.19.40.24 Bedrock support --- .../geysermc/geyser/level/JavaDimension.java | 4 +- .../geysermc/geyser/network/GameProtocol.java | 2 + .../translator/level/BiomeTranslator.java | 4 +- .../protocol/java/JavaLoginTranslator.java | 4 +- ...JavaCodecEntry.java => JavaCodecUtil.java} | 5 ++- .../geyser/util/StatisticFormatters.java | 9 +++-- .../geysermc/geyser/util/StatisticsUtils.java | 39 +++++++++---------- 7 files changed, 37 insertions(+), 30 deletions(-) rename core/src/main/java/org/geysermc/geyser/util/{JavaCodecEntry.java => JavaCodecUtil.java} (96%) diff --git a/core/src/main/java/org/geysermc/geyser/level/JavaDimension.java b/core/src/main/java/org/geysermc/geyser/level/JavaDimension.java index 5f3c96b86..a3f6b55e4 100644 --- a/core/src/main/java/org/geysermc/geyser/level/JavaDimension.java +++ b/core/src/main/java/org/geysermc/geyser/level/JavaDimension.java @@ -27,7 +27,7 @@ package org.geysermc.geyser.level; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; -import org.geysermc.geyser.util.JavaCodecEntry; +import org.geysermc.geyser.util.JavaCodecUtil; import java.util.Map; @@ -39,7 +39,7 @@ import java.util.Map; public record JavaDimension(int minY, int maxY, boolean piglinSafe, double worldCoordinateScale) { public static void load(CompoundTag tag, Map map) { - for (CompoundTag dimension : JavaCodecEntry.iterateAsTag(tag.get("minecraft:dimension_type"))) { + for (CompoundTag dimension : JavaCodecUtil.iterateAsTag(tag.get("minecraft:dimension_type"))) { CompoundTag elements = dimension.get("element"); int minY = ((IntTag) elements.get("min_y")).getValue(); int maxY = ((IntTag) elements.get("height")).getValue(); diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 844fd0f51..5870b92b6 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -33,6 +33,7 @@ import com.nukkitx.protocol.bedrock.v534.Bedrock_v534; import com.nukkitx.protocol.bedrock.v544.Bedrock_v544; import com.nukkitx.protocol.bedrock.v545.Bedrock_v545; import com.nukkitx.protocol.bedrock.v554.Bedrock_v554; +import com.nukkitx.protocol.bedrock.v557.Bedrock_v557; import org.geysermc.geyser.session.GeyserSession; import java.util.ArrayList; @@ -75,6 +76,7 @@ public final class GameProtocol { SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder() .minecraftVersion("1.19.30/1.19.31") .build()); + SUPPORTED_BEDROCK_CODECS.add(Bedrock_v557.V557_CODEC); } /** diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/BiomeTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/BiomeTranslator.java index 3e47bfc37..04b39deeb 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/BiomeTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/BiomeTranslator.java @@ -45,7 +45,7 @@ import org.geysermc.geyser.level.chunk.bitarray.BitArrayVersion; import org.geysermc.geyser.level.chunk.bitarray.SingletonBitArray; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.util.JavaCodecEntry; +import org.geysermc.geyser.util.JavaCodecUtil; import org.geysermc.geyser.util.MathUtils; // Array index formula by https://wiki.vg/Chunk_Format @@ -59,7 +59,7 @@ public class BiomeTranslator { ListTag serverBiomes = worldGen.get("value"); session.setBiomeGlobalPalette(MathUtils.getGlobalPaletteForSize(serverBiomes.size())); - for (CompoundTag biomeTag : JavaCodecEntry.iterateAsTag(worldGen)) { + for (CompoundTag biomeTag : JavaCodecUtil.iterateAsTag(worldGen)) { String javaIdentifier = ((StringTag) biomeTag.get("name")).getValue(); int bedrockId = Registries.BIOME_IDENTIFIERS.get().getOrDefault(javaIdentifier, 0); int javaId = ((IntTag) biomeTag.get("id")).getValue(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java index 978d4b6fb..60382e17a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java @@ -46,7 +46,7 @@ import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.util.ChunkUtils; import org.geysermc.geyser.util.DimensionUtils; -import org.geysermc.geyser.util.JavaCodecEntry; +import org.geysermc.geyser.util.JavaCodecUtil; import org.geysermc.geyser.util.PluginMessageUtils; import java.util.Map; @@ -66,7 +66,7 @@ public class JavaLoginTranslator extends PacketTranslator chatTypes = session.getChatTypes(); chatTypes.clear(); - for (CompoundTag tag : JavaCodecEntry.iterateAsTag(packet.getRegistry().get("minecraft:chat_type"))) { + for (CompoundTag tag : JavaCodecUtil.iterateAsTag(packet.getRegistry().get("minecraft:chat_type"))) { // The ID is NOT ALWAYS THE SAME! ViaVersion as of 1.19 adds two registry entries that do NOT match vanilla. int id = ((IntTag) tag.get("id")).getValue(); CompoundTag element = tag.get("element"); diff --git a/core/src/main/java/org/geysermc/geyser/util/JavaCodecEntry.java b/core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java similarity index 96% rename from core/src/main/java/org/geysermc/geyser/util/JavaCodecEntry.java rename to core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java index 45be5bf99..f0b8ee6bc 100644 --- a/core/src/main/java/org/geysermc/geyser/util/JavaCodecEntry.java +++ b/core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java @@ -32,7 +32,7 @@ import com.github.steveice10.opennbt.tag.builtin.Tag; import javax.annotation.Nonnull; import java.util.Iterator; -public record JavaCodecEntry() { +public final class JavaCodecUtil { /** * Iterate over a Java Edition codec and return each entry as a CompoundTag @@ -58,4 +58,7 @@ public record JavaCodecEntry() { } }; } + + private JavaCodecUtil() { + } } diff --git a/core/src/main/java/org/geysermc/geyser/util/StatisticFormatters.java b/core/src/main/java/org/geysermc/geyser/util/StatisticFormatters.java index 7e1f6e7b7..d46a759fe 100644 --- a/core/src/main/java/org/geysermc/geyser/util/StatisticFormatters.java +++ b/core/src/main/java/org/geysermc/geyser/util/StatisticFormatters.java @@ -26,17 +26,17 @@ package org.geysermc.geyser.util; import com.github.steveice10.mc.protocol.data.game.statistic.StatisticFormat; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.EnumMap; import java.util.Locale; import java.util.Map; import java.util.function.IntFunction; -public class StatisticFormatters { +public final class StatisticFormatters { - private static final Map> FORMATTERS = new Object2ObjectOpenHashMap<>(); + private static final Map> FORMATTERS = new EnumMap<>(StatisticFormat.class); private static final DecimalFormat FORMAT = new DecimalFormat("###,###,##0.00"); public static final IntFunction INTEGER = NumberFormat.getIntegerInstance(Locale.US)::format; @@ -78,4 +78,7 @@ public class StatisticFormatters { public static IntFunction get(StatisticFormat format) { return FORMATTERS.getOrDefault(format, INTEGER); } + + private StatisticFormatters() { + } } diff --git a/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java b/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java index f01670106..58e0b131a 100644 --- a/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.util; import com.github.steveice10.mc.protocol.data.game.statistic.*; +import it.unimi.dsi.fastutil.objects.Object2IntMap; import org.geysermc.cumulus.form.SimpleForm; import org.geysermc.cumulus.util.FormImage; import org.geysermc.geyser.registry.BlockRegistries; @@ -37,7 +38,6 @@ import org.geysermc.geyser.text.MinecraftLocale; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.function.IntFunction; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -79,23 +79,23 @@ public class StatisticsUtils { case 0: builder.title("stat.generalButton"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof CustomStatistic statistic) { String statName = statistic.name().toLowerCase(Locale.ROOT); IntFunction formatter = StatisticFormatters.get(statistic.getFormat()); - content.add("stat.minecraft." + statName + ": " + formatter.apply(entry.getValue())); + content.add("stat.minecraft." + statName + ": " + formatter.apply(entry.getIntValue())); } } break; case 1: builder.title("stat.itemsButton - stat_type.minecraft.mined"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof BreakBlockStatistic statistic) { String identifier = BlockRegistries.CLEAN_JAVA_IDENTIFIERS.get(statistic.getId()); if (identifier != null) { String block = identifier.replace("minecraft:", "block.minecraft."); - content.add(block + ": " + entry.getValue()); + content.add(block + ": " + entry.getIntValue()); } } } @@ -103,71 +103,70 @@ public class StatisticsUtils { case 2: builder.title("stat.itemsButton - stat_type.minecraft.broken"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof BreakItemStatistic statistic) { String item = mappings.getMapping(statistic.getId()).getJavaIdentifier(); - content.add(getItemTranslateKey(item, language) + ": " + entry.getValue()); + content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue()); } } break; case 3: builder.title("stat.itemsButton - stat_type.minecraft.crafted"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof CraftItemStatistic statistic) { String item = mappings.getMapping(statistic.getId()).getJavaIdentifier(); - content.add(getItemTranslateKey(item, language) + ": " + entry.getValue()); + content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue()); } } break; case 4: builder.title("stat.itemsButton - stat_type.minecraft.used"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof UseItemStatistic statistic) { String item = mappings.getMapping(statistic.getId()).getJavaIdentifier(); - content.add(getItemTranslateKey(item, language) + ": " + entry.getValue()); + content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue()); } } break; case 5: builder.title("stat.itemsButton - stat_type.minecraft.picked_up"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof PickupItemStatistic statistic) { String item = mappings.getMapping(statistic.getId()).getJavaIdentifier(); - content.add(getItemTranslateKey(item, language) + ": " + entry.getValue()); + content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue()); } } break; case 6: builder.title("stat.itemsButton - stat_type.minecraft.dropped"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof DropItemStatistic statistic) { String item = mappings.getMapping(statistic.getId()).getJavaIdentifier(); - content.add(getItemTranslateKey(item, language) + ": " + entry.getValue()); + content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue()); } } break; case 7: builder.title("stat.mobsButton - geyser.statistics.killed"); - for (Map.Entry entry : session.getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof KillEntityStatistic statistic) { String entityName = statistic.getEntity().name().toLowerCase(Locale.ROOT); - content.add("entity.minecraft." + entityName + ": " + entry.getValue()); + content.add("entity.minecraft." + entityName + ": " + entry.getIntValue()); } } break; case 8: builder.title("stat.mobsButton - geyser.statistics.killed_by"); - for (Map.Entry entry : session - .getStatistics().entrySet()) { + for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof KilledByEntityStatistic statistic) { String entityName = statistic.getEntity().name().toLowerCase(Locale.ROOT); - content.add("entity.minecraft." + entityName + ": " + entry.getValue()); + content.add("entity.minecraft." + entityName + ": " + entry.getIntValue()); } } break;