From 02387dc6e265eed5744a3521c605a043dd48f329 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 11 Oct 2021 21:14:06 -0400 Subject: [PATCH] Fix all blocks not appearing in /setblock; show effect suggestions in commands --- connector/pom.xml | 2 +- .../connector/entity/type/EntityType.java | 3 ++- .../session/cache/EntityEffectCache.java | 8 ++++---- .../java/JavaDeclareCommandsTranslator.java | 5 ++++- .../populator/BlockRegistryPopulator.java | 5 ++--- .../populator/ItemRegistryPopulator.java | 2 +- .../geysermc/connector/utils/EntityUtils.java | 17 +++++++++++++++++ 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 8964f18c8..0f13d134a 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -149,7 +149,7 @@ com.github.GeyserMC MCProtocolLib - e7979c4 + f1ac2de compile diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 094cb4d61..57ce2de3c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -41,6 +41,7 @@ import org.geysermc.connector.entity.player.PlayerEntity; import java.util.ArrayList; import java.util.List; +import java.util.Locale; @Getter public enum EntityType { @@ -194,7 +195,7 @@ public enum EntityType { if (type == AGENT || type == BALLOON || type == CHALKBOARD || type == NPC || type == TRIPOD_CAMERA || type == ENDER_DRAGON_PART) { continue; } - allJavaIdentifiers.add("minecraft:" + type.name().toLowerCase()); + allJavaIdentifiers.add("minecraft:" + type.name().toLowerCase(Locale.ROOT)); } ALL_JAVA_IDENTIFIERS = allJavaIdentifiers.toArray(new String[0]); } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java index e165ea545..910367889 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityEffectCache.java @@ -49,8 +49,8 @@ public class EntityEffectCache { public void setEffect(Effect effect, int effectAmplifier) { switch (effect) { case CONDUIT_POWER -> conduitPower = effectAmplifier + 1; - case FASTER_DIG -> haste = effectAmplifier + 1; - case SLOWER_DIG -> miningFatigue = effectAmplifier + 1; + case HASTE -> haste = effectAmplifier + 1; + case MINING_FATIGUE -> miningFatigue = effectAmplifier + 1; } entityEffects.add(effect); } @@ -58,8 +58,8 @@ public class EntityEffectCache { public void removeEffect(Effect effect) { switch (effect) { case CONDUIT_POWER -> conduitPower = 0; - case FASTER_DIG -> haste = 0; - case SLOWER_DIG -> miningFatigue = 0; + case HASTE -> haste = 0; + case MINING_FATIGUE -> miningFatigue = 0; } entityEffects.remove(effect); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDeclareCommandsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDeclareCommandsTranslator.java index 996619eac..37760996c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDeclareCommandsTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDeclareCommandsTranslator.java @@ -49,17 +49,19 @@ import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.item.Enchantment; import org.geysermc.connector.registry.BlockRegistries; +import org.geysermc.connector.utils.EntityUtils; import java.util.*; @Translator(packet = ServerDeclareCommandsPacket.class) public class JavaDeclareCommandsTranslator extends PacketTranslator { + private static final String[] ALL_POTION_IDENTIFIERS = EntityUtils.getAllPotionIdentifiers(); private static final String[] ENUM_BOOLEAN = {"true", "false"}; private static final String[] VALID_COLORS; private static final String[] VALID_SCOREBOARD_SLOTS; - private static final Hash.Strategy PARAM_STRATEGY = new Hash.Strategy() { + private static final Hash.Strategy PARAM_STRATEGY = new Hash.Strategy<>() { @Override public int hashCode(CommandParamData[][] o) { return Arrays.deepHashCode(o); @@ -221,6 +223,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator EntityType.ALL_JAVA_IDENTIFIERS; case COLOR -> VALID_COLORS; case SCOREBOARD_SLOT -> VALID_SCOREBOARD_SLOTS; + case MOB_EFFECT -> ALL_POTION_IDENTIFIERS; default -> CommandParam.STRING; }; } diff --git a/connector/src/main/java/org/geysermc/connector/registry/populator/BlockRegistryPopulator.java b/connector/src/main/java/org/geysermc/connector/registry/populator/BlockRegistryPopulator.java index 6d54375f1..a46ca77af 100644 --- a/connector/src/main/java/org/geysermc/connector/registry/populator/BlockRegistryPopulator.java +++ b/connector/src/main/java/org/geysermc/connector/registry/populator/BlockRegistryPopulator.java @@ -299,9 +299,8 @@ public class BlockRegistryPopulator { BlockRegistries.JAVA_BLOCKS.register(javaRuntimeId, builder.build()); // Keeping this here since this is currently unchanged between versions - if (!cleanJavaIdentifier.equals(bedrockIdentifier)) { - BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.register(cleanJavaIdentifier.intern(), bedrockIdentifier.intern()); - } + // It's possible to only have this store differences in names, but the key set of all Java names is used in sending command suggestions + BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.register(cleanJavaIdentifier.intern(), bedrockIdentifier.intern()); if (javaId.startsWith("minecraft:bell[")) { bellBlockId = uniqueJavaId; diff --git a/connector/src/main/java/org/geysermc/connector/registry/populator/ItemRegistryPopulator.java b/connector/src/main/java/org/geysermc/connector/registry/populator/ItemRegistryPopulator.java index 175bf13d7..ae69904df 100644 --- a/connector/src/main/java/org/geysermc/connector/registry/populator/ItemRegistryPopulator.java +++ b/connector/src/main/java/org/geysermc/connector/registry/populator/ItemRegistryPopulator.java @@ -406,7 +406,7 @@ public class ItemRegistryPopulator { } else if (javaIdentifier.startsWith("minecraft:music_disc_")) { // The Java record level event uses the item ID as the "key" to play the record Registries.RECORDS.register(itemIndex, SoundEvent.valueOf("RECORD_" + - javaIdentifier.replace("minecraft:music_disc_", "").toUpperCase(Locale.ENGLISH).intern())); + javaIdentifier.replace("minecraft:music_disc_", "").toUpperCase(Locale.ENGLISH))); } else if (javaIdentifier.endsWith("_spawn_egg")) { spawnEggs.add(mapping.getBedrockId()); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java index 5c4929a91..594fc0601 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java @@ -35,8 +35,22 @@ import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; +import java.util.Locale; + public final class EntityUtils { + /** + * @return a new String array of all known potion identifiers + */ + public static String[] getAllPotionIdentifiers() { + String[] identifiers = new String[Effect.VALUES.length]; + for (int i = 0; i < Effect.VALUES.length; i++) { + identifiers[i] = "minecraft:" + Effect.VALUES[i].name().toLowerCase(Locale.ROOT); + } + + return identifiers; + } + /** * Convert Java edition effect IDs to Bedrock edition * @@ -178,4 +192,7 @@ public final class EntityUtils { } passenger.updateBedrockMetadata(session); } + + private EntityUtils() { + } }