Allow 1.19.0 to join and use new block mappings

This commit is contained in:
davchoo 2022-05-25 19:41:31 -04:00
parent 1a7b57018e
commit c5de293373
9 changed files with 10066 additions and 47 deletions

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.network;
import com.github.steveice10.mc.protocol.codec.MinecraftCodec; import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
import com.github.steveice10.mc.protocol.codec.PacketCodec; import com.github.steveice10.mc.protocol.codec.PacketCodec;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.beta.BedrockBeta;
import com.nukkitx.protocol.bedrock.v503.Bedrock_v503; import com.nukkitx.protocol.bedrock.v503.Bedrock_v503;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,7 +44,7 @@ public final class MinecraftProtocol {
* Default Bedrock codec that should act as a fallback. Should represent the latest available * Default Bedrock codec that should act as a fallback. Should represent the latest available
* release of the game that Geyser supports. * release of the game that Geyser supports.
*/ */
public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = Bedrock_v503.V503_CODEC; public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = BedrockBeta.BETA_CODEC;
/** /**
* A list of all supported Bedrock versions that can join Geyser * A list of all supported Bedrock versions that can join Geyser
*/ */
@ -56,9 +57,13 @@ public final class MinecraftProtocol {
private static final PacketCodec DEFAULT_JAVA_CODEC = MinecraftCodec.CODEC; private static final PacketCodec DEFAULT_JAVA_CODEC = MinecraftCodec.CODEC;
static { static {
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder() SUPPORTED_BEDROCK_CODECS.add(Bedrock_v503.V503_CODEC.toBuilder()
.minecraftVersion("1.18.30/1.18.31") .minecraftVersion("1.18.30/1.18.31")
.build()); .build());
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
.minecraftVersion("1.19.0")
.build());
} }
/** /**

View file

@ -164,6 +164,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
// Allow custom items to work // Allow custom items to work
stackPacket.getExperiments().add(new ExperimentData("data_driven_items", true)); stackPacket.getExperiments().add(new ExperimentData("data_driven_items", true));
} }
stackPacket.getExperiments().add(new ExperimentData("wild_update", true));
session.sendUpstreamPacket(stackPacket); session.sendUpstreamPacket(stackPacket);
break; break;

View file

@ -28,8 +28,7 @@ package org.geysermc.geyser.registry.populator;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.nukkitx.nbt.*; import com.nukkitx.nbt.*;
import com.nukkitx.protocol.bedrock.v475.Bedrock_v475; import com.nukkitx.protocol.bedrock.beta.BedrockBeta;
import com.nukkitx.protocol.bedrock.v486.Bedrock_v486;
import com.nukkitx.protocol.bedrock.v503.Bedrock_v503; import com.nukkitx.protocol.bedrock.v503.Bedrock_v503;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
@ -61,51 +60,94 @@ public class BlockRegistryPopulator {
private static final ImmutableMap<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> BLOCK_MAPPERS; private static final ImmutableMap<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> BLOCK_MAPPERS;
private static final BiFunction<String, NbtMapBuilder, String> EMPTY_MAPPER = (bedrockIdentifier, statesBuilder) -> null; private static final BiFunction<String, NbtMapBuilder, String> EMPTY_MAPPER = (bedrockIdentifier, statesBuilder) -> null;
private static final BiFunction<String, NbtMapBuilder, String> V486_MAPPER = (bedrockIdentifier, statesBuilder) -> { private static final BiFunction<String, NbtMapBuilder, String> V503_MAPPER = (bedrockIdentifier, statesBuilder) -> {
statesBuilder.remove("no_drop_bit"); // Used in skulls // TODO some new blocks exist in the block palette, but don't properly work in game (mangrove leaves + mud stuff)
if (bedrockIdentifier.equals("minecraft:glow_lichen")) { if (bedrockIdentifier.contains("stone_block_slab")) {
// Moved around north, south, west return bedrockIdentifier.replace("stone_block_slab", "stone_slab");
int bits = (int) statesBuilder.get("multi_face_direction_bits"); }
boolean north = (bits & (1 << 2)) != 0; switch (bedrockIdentifier) {
boolean south = (bits & (1 << 3)) != 0; case "minecraft:mangrove_planks" -> {
boolean west = (bits & (1 << 4)) != 0; statesBuilder.putString("wood_type", "jungle");
if (north) { return "minecraft:planks";
bits |= 1 << 4;
} else {
bits &= ~(1 << 4);
} }
if (south) { case "minecraft:mangrove_log" -> {
bits |= 1 << 2; statesBuilder.putString("old_log_type", "jungle");
} else { return "minecraft:log";
bits &= ~(1 << 2);
} }
if (west) { case "minecraft:stripped_mangrove_log" -> {
bits |= 1 << 3; return "minecraft:stripped_jungle_log";
} else { }
bits &= ~(1 << 3); case "minecraft:mangrove_roots", "minecraft:muddy_mangrove_roots", "minecraft:mangrove_wood" -> {
statesBuilder.putString("wood_type", "jungle");
statesBuilder.putBoolean("stripped_bit", false);
statesBuilder.putString("pillar_axis", "x");
return "minecraft:wood";
}
case "minecraft:stripped_mangrove_wood" -> {
statesBuilder.putString("wood_type", "jungle");
statesBuilder.putBoolean("stripped_bit", true);
return "minecraft:wood";
}
case "minecraft:mangrove_standing_sign" -> {
return "minecraft:jungle_standing_sign";
}
case "minecraft:mangrove_wall_sign" -> {
return "minecraft:jungle_wall_sign";
}
case "minecraft:mangrove_pressure_plate" -> {
return "minecraft:jungle_pressure_plate";
}
case "minecraft:mangrove_trapdoor" -> {
return "minecraft:jungle_trapdoor";
}
case "minecraft:mangrove_button" -> {
return "minecraft:jungle_button";
}
case "minecraft:mangrove_stairs" -> {
return "minecraft:jungle_stairs";
}
case "minecraft:mangrove_slab" -> {
statesBuilder.putString("wood_type", "jungle");
return "minecraft:wooden_slab";
}
case "minecraft:mangrove_double_slab" -> {
statesBuilder.putString("wood_type", "jungle");
return "minecraft:double_wooden_slab";
}
case "minecraft:mangrove_fence_gate" -> {
return "minecraft:jungle_fence_gate";
}
case "minecraft:mangrove_fence" -> {
statesBuilder.putString("wood_type", "jungle");
return "minecraft:fence";
}
case "minecraft:mangrove_door" -> {
return "minecraft:jungle_door";
}
case "minecraft:mangrove_propagule" -> {
statesBuilder.put("growth", statesBuilder.get("propagule_stage"));
statesBuilder.remove("propagule_stage");
statesBuilder.putInt("facing_direction", 0);
if ((Byte) statesBuilder.remove("hanging") == 1) {
return "minecraft:mangrove_propagule_hanging";
} else {
return "minecraft:mangrove_propagule";
}
}
case "minecraft:sculk_shrieker" -> {
statesBuilder.remove("can_summon");
return bedrockIdentifier;
} }
statesBuilder.put("multi_face_direction_bits", bits);
} }
return null; return null;
}; };
static { static {
ImmutableMap.Builder<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> stateMapperBuilder = ImmutableMap.<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>>builder() ImmutableMap.Builder<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> stateMapperBuilder = ImmutableMap.<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>>builder()
.put(ObjectIntPair.of("1_18_0", Bedrock_v475.V475_CODEC.getProtocolVersion()), EMPTY_MAPPER) .put(ObjectIntPair.of("1_18_30", Bedrock_v503.V503_CODEC.getProtocolVersion()), V503_MAPPER)
.put(ObjectIntPair.of("1_18_10", Bedrock_v486.V486_CODEC.getProtocolVersion()), V486_MAPPER) .put(ObjectIntPair.of("1_19_0", BedrockBeta.BETA_CODEC.getProtocolVersion()), EMPTY_MAPPER);
.put(ObjectIntPair.of("1_18_30", Bedrock_v503.V503_CODEC.getProtocolVersion()), (bedrockIdentifier, statesBuilder) -> {
// Apply these fixes too
V486_MAPPER.apply(bedrockIdentifier, statesBuilder);
return switch (bedrockIdentifier) {
case "minecraft:pistonArmCollision" -> "minecraft:piston_arm_collision";
case "minecraft:stickyPistonArmCollision" -> "minecraft:sticky_piston_arm_collision";
case "minecraft:movingBlock" -> "minecraft:moving_block";
case "minecraft:tripWire" -> "minecraft:trip_wire";
case "minecraft:seaLantern" -> "minecraft:sea_lantern";
case "minecraft:concretePowder" -> "minecraft:concrete_powder";
default -> null;
};
});
BLOCK_MAPPERS = stateMapperBuilder.build(); BLOCK_MAPPERS = stateMapperBuilder.build();
} }
@ -171,10 +213,8 @@ public class BlockRegistryPopulator {
int bedrockRuntimeId = blockStateOrderedMap.getOrDefault(buildBedrockState(entry.getValue(), stateVersion, stateMapper), -1); int bedrockRuntimeId = blockStateOrderedMap.getOrDefault(buildBedrockState(entry.getValue(), stateVersion, stateMapper), -1);
if (bedrockRuntimeId == -1) { if (bedrockRuntimeId == -1) {
bedrockRuntimeId = 0; throw new RuntimeException("Unable to find " + javaId + " Bedrock runtime ID! Built NBT tag: \n" +
//TODO remove buildBedrockState(entry.getValue(), stateVersion, stateMapper));
//throw new RuntimeException("Unable to find " + javaId + " Bedrock runtime ID! Built NBT tag: \n" +
// buildBedrockState(entry.getValue(), stateVersion, stateMapper));
} }
switch (javaId) { switch (javaId) {

View file

@ -31,6 +31,7 @@ import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder; import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.NbtType; import com.nukkitx.nbt.NbtType;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.protocol.bedrock.beta.BedrockBeta;
import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData; import com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
@ -66,9 +67,8 @@ public class ItemRegistryPopulator {
public static void populate() { public static void populate() {
Map<String, PaletteVersion> paletteVersions = new Object2ObjectOpenHashMap<>(); Map<String, PaletteVersion> paletteVersions = new Object2ObjectOpenHashMap<>();
paletteVersions.put("1_18_0", new PaletteVersion(Bedrock_v475.V475_CODEC.getProtocolVersion(), Collections.emptyMap()));
paletteVersions.put("1_18_10", new PaletteVersion(Bedrock_v486.V486_CODEC.getProtocolVersion(), Collections.emptyMap()));
paletteVersions.put("1_18_30", new PaletteVersion(Bedrock_v503.V503_CODEC.getProtocolVersion(), Collections.emptyMap())); paletteVersions.put("1_18_30", new PaletteVersion(Bedrock_v503.V503_CODEC.getProtocolVersion(), Collections.emptyMap()));
paletteVersions.put("1_19_0", new PaletteVersion(BedrockBeta.BETA_CODEC.getProtocolVersion(), Collections.emptyMap()));
GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap(); GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap();

View file

@ -64,6 +64,7 @@ import com.github.steveice10.packetlib.tcp.TcpClientSession;
import com.github.steveice10.packetlib.tcp.TcpSession; import com.github.steveice10.packetlib.tcp.TcpSession;
import com.nukkitx.math.GenericMath; import com.nukkitx.math.GenericMath;
import com.nukkitx.math.vector.*; import com.nukkitx.math.vector.*;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.data.*; import com.nukkitx.protocol.bedrock.data.*;
@ -1461,6 +1462,11 @@ public class GeyserSession implements GeyserConnection, CommandSender {
startGamePacket.setInventoriesServerAuthoritative(true); startGamePacket.setInventoriesServerAuthoritative(true);
startGamePacket.setServerEngine(""); // Do we want to fill this in? startGamePacket.setServerEngine(""); // Do we want to fill this in?
startGamePacket.setPlayerPropertyData(NbtMap.EMPTY);
startGamePacket.setWorldTemplateId(UUID.randomUUID());
startGamePacket.getExperiments().add(new ExperimentData("wild_update", true));
SyncedPlayerMovementSettings settings = new SyncedPlayerMovementSettings(); SyncedPlayerMovementSettings settings = new SyncedPlayerMovementSettings();
settings.setMovementMode(AuthoritativeMovementMode.CLIENT); settings.setMovementMode(AuthoritativeMovementMode.CLIENT);
settings.setRewindHistorySize(0); settings.setRewindHistorySize(0);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

@ -1 +1 @@
Subproject commit f73b45844f1185c3898db3052ce4ea0d18246168 Subproject commit dbd6e29245843f8a2469a282c01b4de6157ba4e4