Fix all blocks not appearing in /setblock; show effect suggestions in commands

This commit is contained in:
Camotoy 2021-10-11 21:14:06 -04:00
parent 265c42fe09
commit 02387dc6e2
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
7 changed files with 31 additions and 11 deletions

View file

@ -149,7 +149,7 @@
<dependency>
<groupId>com.github.GeyserMC</groupId>
<artifactId>MCProtocolLib</artifactId>
<version>e7979c4</version>
<version>f1ac2de</version>
<scope>compile</scope>
<exclusions>
<exclusion>

View file

@ -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]);
}

View file

@ -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);
}

View file

@ -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<ServerDeclareCommandsPacket> {
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<CommandParamData[][]> PARAM_STRATEGY = new Hash.Strategy<CommandParamData[][]>() {
private static final Hash.Strategy<CommandParamData[][]> PARAM_STRATEGY = new Hash.Strategy<>() {
@Override
public int hashCode(CommandParamData[][] o) {
return Arrays.deepHashCode(o);
@ -221,6 +223,7 @@ public class JavaDeclareCommandsTranslator extends PacketTranslator<ServerDeclar
case ENTITY_SUMMON -> EntityType.ALL_JAVA_IDENTIFIERS;
case COLOR -> VALID_COLORS;
case SCOREBOARD_SLOT -> VALID_SCOREBOARD_SLOTS;
case MOB_EFFECT -> ALL_POTION_IDENTIFIERS;
default -> CommandParam.STRING;
};
}

View file

@ -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)) {
// 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;

View file

@ -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());
}

View file

@ -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() {
}
}