Skip to content

Commit

Permalink
Support Bedrock 1.20.70 (GeyserMC#4477)
Browse files Browse the repository at this point in the history
* Support 1.20.70

Signed-off-by: Joshua Castle <[email protected]>

* Update readme

Signed-off-by: Joshua Castle <[email protected]>

* Use 1.20.70 mappings

Signed-off-by: Joshua Castle <[email protected]>

* Creative lectern drops work but not survival yet

Signed-off-by: Joshua Castle <[email protected]>

* Fix lectern book pickup in survival

Signed-off-by: Joshua Castle <[email protected]>

* Add copyright notices to new files

Signed-off-by: Joshua Castle <[email protected]>

* Temp fix for incorrect creative_items from Cloudburst/Data

Signed-off-by: Joshua Castle <[email protected]>

* Fix item frame breaking in creative

Signed-off-by: Joshua Castle <[email protected]>

* Clarify what to remove when 1.20.60 support is dropped

Signed-off-by: Joshua Castle <[email protected]>

* Don't use dim change enum pre 1.20.70

Signed-off-by: Joshua Castle <[email protected]>

---------

Signed-off-by: Joshua Castle <[email protected]>
  • Loading branch information
Kas-tle authored Mar 11, 2024
1 parent a0fd720 commit 1df63c6
Show file tree
Hide file tree
Showing 20 changed files with 12,288 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t

Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here!

### Currently supporting Minecraft Bedrock 1.20.40 - 1.20.61 and Minecraft Java 1.20.4
### Currently supporting Minecraft Bedrock 1.20.40 - 1.20.70 and Minecraft Java 1.20.4

## Setting Up
Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser.
Expand Down
48 changes: 47 additions & 1 deletion build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.options.Option
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.named
import java.io.File
import java.net.URL

fun Project.relocate(pattern: String) {
tasks.named<ShadowJar>("shadowJar") {
Expand Down Expand Up @@ -69,5 +75,45 @@ fun Project.provided(dependency: MinimalExternalModuleDependency) =
fun Project.provided(provider: Provider<MinimalExternalModuleDependency>) =
provided(provider.get())

open class DownloadFilesTask : DefaultTask() {
@Input
var urls: List<String> = listOf()

@Input
var destinationDir: String = ""

@Option(option="suffix", description="suffix")
@Input
var suffix: String = ""

@Input
var suffixedFiles: List<String> = listOf()

@TaskAction
fun downloadAndAddSuffix() {
urls.forEach { fileUrl ->
val fileName = fileUrl.substringAfterLast("/")
val baseName = fileName.substringBeforeLast(".")
val extension = fileName.substringAfterLast(".", "")
val shouldSuffix = fileName in suffixedFiles
val suffixedFileName = if (shouldSuffix && extension.isNotEmpty()) "$baseName.$suffix.$extension" else fileName
val outputFile = File(destinationDir, suffixedFileName)

if (!outputFile.parentFile.exists()) {
outputFile.parentFile.mkdirs()
}

URL(fileUrl).openStream().use { input ->
outputFile.outputStream().use { output ->
input.copyTo(output)
}
}

println("Downloaded: $suffixedFileName")
}
}
}

private fun calcExclusion(section: String, bit: Int, excludedOn: Int): String =
if (excludedOn and bit > 0) section else ""
if (excludedOn and bit > 0) section else ""

16 changes: 16 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,19 @@ inner class GitInfo {

// todo remove this when we're not using Jenkins anymore
fun jenkinsBuildNumber(): String? = System.getenv("BUILD_NUMBER")

// Manual task to download the bedrock data files from the CloudburstMC/Data repository
// Invoke with ./gradlew :core:downloadBedrockData --suffix=1_20_70
// Set suffix to the current Bedrock version
tasks.register<DownloadFilesTask>("downloadBedrockData") {
urls = listOf(
"https://raw.githubusercontent.com/CloudburstMC/Data/master/entity_identifiers.dat",
"https://raw.githubusercontent.com/CloudburstMC/Data/master/biome_definitions.dat",
"https://raw.githubusercontent.com/CloudburstMC/Data/master/block_palette.nbt",
"https://raw.githubusercontent.com/CloudburstMC/Data/master/creative_items.json",
"https://raw.githubusercontent.com/CloudburstMC/Data/master/runtime_item_states.json"
)
suffixedFiles = listOf("block_palette.nbt", "creative_items.json", "runtime_item_states.json")

destinationDir = "$projectDir/src/main/resources/bedrock"
}
12 changes: 10 additions & 2 deletions core/src/main/java/org/geysermc/geyser/network/GameProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.cloudburstmc.protocol.bedrock.codec.v622.Bedrock_v622;
import org.cloudburstmc.protocol.bedrock.codec.v630.Bedrock_v630;
import org.cloudburstmc.protocol.bedrock.codec.v649.Bedrock_v649;
import org.cloudburstmc.protocol.bedrock.codec.v662.Bedrock_v662;
import org.cloudburstmc.protocol.bedrock.netty.codec.packet.BedrockPacketCodec;
import org.geysermc.geyser.session.GeyserSession;

Expand All @@ -47,7 +48,7 @@ public final class GameProtocol {
* Default Bedrock codec that should act as a fallback. Should represent the latest available
* release of the game that Geyser supports.
*/
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = Bedrock_v649.CODEC;
public static final BedrockCodec DEFAULT_BEDROCK_CODEC = Bedrock_v662.CODEC;

/**
* A list of all supported Bedrock versions that can join Geyser
Expand All @@ -67,8 +68,11 @@ public final class GameProtocol {
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v630.CODEC.toBuilder()
.minecraftVersion("1.20.50/1.20.51")
.build());
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v649.CODEC.toBuilder()
.minecraftVersion("1.20.60/1.20.62")
.build());
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
.minecraftVersion("1.20.60/1.20.61")
.minecraftVersion("1.20.70")
.build());
}

Expand All @@ -92,6 +96,10 @@ public static boolean isPre1_20_50(GeyserSession session) {
return session.getUpstream().getProtocolVersion() < Bedrock_v630.CODEC.getProtocolVersion();
}

public static boolean isPre1_20_70(GeyserSession session) {
return session.getUpstream().getProtocolVersion() < Bedrock_v662.CODEC.getProtocolVersion();
}

public static boolean is1_20_60orHigher(int protocolVersion) {
return protocolVersion >= Bedrock_v649.CODEC.getProtocolVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.cloudburstmc.protocol.bedrock.codec.v622.Bedrock_v622;
import org.cloudburstmc.protocol.bedrock.codec.v630.Bedrock_v630;
import org.cloudburstmc.protocol.bedrock.codec.v649.Bedrock_v649;
import org.cloudburstmc.protocol.bedrock.codec.v662.Bedrock_v662;
import org.cloudburstmc.protocol.bedrock.data.BlockPropertyData;
import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition;
import org.geysermc.geyser.GeyserImpl;
Expand Down Expand Up @@ -118,9 +119,10 @@ private static void nullifyBlocksNode() {
private static void registerBedrockBlocks() {
var blockMappers = ImmutableMap.<ObjectIntPair<String>, Remapper>builder()
.put(ObjectIntPair.of("1_20_40", Bedrock_v622.CODEC.getProtocolVersion()), Conversion630_622::remapBlock)
.put(ObjectIntPair.of("1_20_50", Bedrock_v630.CODEC.getProtocolVersion()), tag -> tag)
.put(ObjectIntPair.of("1_20_50", Bedrock_v630.CODEC.getProtocolVersion()), Conversion649_630::remapBlock)
// Only changes in 1.20.60 are hard_stained_glass (an EDU only block)
.put(ObjectIntPair.of("1_20_60", Bedrock_v649.CODEC.getProtocolVersion()), tag -> tag)
.put(ObjectIntPair.of("1_20_60", Bedrock_v649.CODEC.getProtocolVersion()), Conversion662_649::remapBlock)
.put(ObjectIntPair.of("1_20_70", Bedrock_v662.CODEC.getProtocolVersion()), tag -> tag)
.build();

// We can keep this strong as nothing should be garbage collected
Expand All @@ -133,7 +135,7 @@ private static void registerBedrockBlocks() {
List<NbtMap> vanillaBlockStates;
List<NbtMap> blockStates;
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(String.format("bedrock/block_palette.%s.nbt", palette.key()));
NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) {
NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) {
NbtMap blockPalette = (NbtMap) nbtInputStream.readTag();

vanillaBlockStates = new ArrayList<>(blockPalette.getList("blocks", NbtType.COMPOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class Conversion630_622 {
}

static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, GeyserMappingItem mapping) {
mapping = Conversion649_630.remapItem(item, mapping);

String replacement = ITEMS.get(mapping.getBedrockIdentifier());
if (replacement == null) {
return mapping;
Expand All @@ -130,6 +132,8 @@ static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, Geyser
}

static NbtMap remapBlock(NbtMap tag) {
tag = Conversion649_630.remapBlock(tag);

final String name = tag.getString("name");

String replacement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,41 @@
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.registry.populator;

import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.registry.type.GeyserMappingItem;

public class Conversion649_630 {

static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, GeyserMappingItem mapping) {
mapping = Conversion662_649.remapItem(item, mapping);

String identifer = mapping.getBedrockIdentifier();

public class Conversion630_649 {
switch (identifer) {
case "minecraft:turtle_scute" -> { return mapping.withBedrockIdentifier("minecraft:scute"); }
case "minecraft:trial_spawner" -> { return mapping.withBedrockIdentifier("minecraft:mob_spawner"); }
case "minecraft:trial_key" -> { return mapping.withBedrockIdentifier("minecraft:echo_shard"); }
default -> { return mapping; }
}
}

static NbtMap remapBlock(NbtMap tag) {
tag = Conversion662_649.remapBlock(tag);

static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, GeyserMappingItem mapping) {
if (mapping.getBedrockIdentifier().equalsIgnoreCase("minecraft:scute")) {
return mapping.withBedrockIdentifier("minecraft:turtle_scute");
final String name = tag.getString("name");

if (name.equals("minecraft:trial_spawner")) {
NbtMapBuilder builder = tag.toBuilder()
.putString("name", "minecraft:mob_spawner")
.putCompound("states", NbtMap.EMPTY);

return builder.build();
}

return tag;
}
return mapping;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.registry.populator;

import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.registry.type.GeyserMappingItem;

import java.util.List;
import java.util.stream.Stream;

public class Conversion662_649 {

private static final List<String> NEW_MISC = List.of("minecraft:grass_block", "minecraft:trial_spawner");
private static final List<String> NEW_WOODS = List.of("minecraft:oak_wood", "minecraft:spruce_wood", "minecraft:birch_wood", "minecraft:jungle_wood", "minecraft:acacia_wood", "minecraft:dark_oak_wood", "minecraft:stripped_oak_wood", "minecraft:stripped_spruce_wood", "minecraft:stripped_birch_wood", "minecraft:stripped_jungle_wood", "minecraft:stripped_acacia_wood", "minecraft:stripped_dark_oak_wood");
private static final List<String> NEW_LEAVES = List.of("minecraft:oak_leaves", "minecraft:spruce_leaves", "minecraft:birch_leaves", "minecraft:jungle_leaves");
private static final List<String> NEW_LEAVES2 = List.of("minecraft:acacia_leaves", "minecraft:dark_oak_leaves");
private static final List<String> NEW_SLABS = List.of("minecraft:oak_slab", "minecraft:spruce_slab", "minecraft:birch_slab", "minecraft:jungle_slab", "minecraft:acacia_slab", "minecraft:dark_oak_slab", "minecraft:oak_double_slab", "minecraft:spruce_double_slab", "minecraft:birch_double_slab", "minecraft:jungle_double_slab", "minecraft:acacia_double_slab", "minecraft:dark_oak_double_slab");
private static final List<String> NEW_BLOCKS = Stream.of(NEW_WOODS, NEW_LEAVES, NEW_LEAVES2, NEW_SLABS, NEW_MISC).flatMap(List::stream).toList();


static GeyserMappingItem remapItem(@SuppressWarnings("unused") Item item, GeyserMappingItem mapping) {
String identifer = mapping.getBedrockIdentifier();

if (identifer.equals("minecraft:grass_block")) {
return mapping.withBedrockIdentifier("minecraft:grass");
}

if (NEW_WOODS.contains(identifer)) {
switch (identifer) {
case "minecraft:oak_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(0); }
case "minecraft:spruce_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(1); }
case "minecraft:birch_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(2); }
case "minecraft:jungle_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(3); }
case "minecraft:acacia_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(4); }
case "minecraft:dark_oak_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(5); }
case "minecraft:stripped_oak_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(8); }
case "minecraft:stripped_spruce_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(9); }
case "minecraft:stripped_birch_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(10); }
case "minecraft:stripped_jungle_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(11); }
case "minecraft:stripped_acacia_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(12); }
case "minecraft:stripped_dark_oak_wood" -> { return mapping.withBedrockIdentifier("minecraft:wood").withBedrockData(13); }
}
}

if (NEW_LEAVES.contains(identifer) || NEW_LEAVES2.contains(identifer)) {
switch (identifer) {
case "minecraft:oak_leaves" -> { return mapping.withBedrockIdentifier("minecraft:leaves").withBedrockData(0); }
case "minecraft:spruce_leaves" -> { return mapping.withBedrockIdentifier("minecraft:leaves").withBedrockData(1); }
case "minecraft:birch_leaves" -> { return mapping.withBedrockIdentifier("minecraft:leaves").withBedrockData(2); }
case "minecraft:jungle_leaves" -> { return mapping.withBedrockIdentifier("minecraft:leaves").withBedrockData(3); }
case "minecraft:acacia_leaves" -> { return mapping.withBedrockIdentifier("minecraft:leaves2").withBedrockData(0); }
case "minecraft:dark_oak_leaves" -> { return mapping.withBedrockIdentifier("minecraft:leaves2").withBedrockData(1); }
}
}

return mapping;
}

static NbtMap remapBlock(NbtMap tag) {
final String name = tag.getString("name");

if (!NEW_BLOCKS.contains(name)) {
return tag;
}

String replacement;

if (name.equals("minecraft:grass_block")) {
replacement = "minecraft:grass";

NbtMapBuilder builder = tag.toBuilder();
builder.putString("name", replacement);

return builder.build();
}

if (NEW_WOODS.contains(name)) {
replacement = "minecraft:wood";

NbtMap states = tag.getCompound("states");
boolean stripped = name.startsWith("minecraft:stripped_");
String woodType = name.replaceAll("minecraft:|_wood|stripped_", "");

NbtMapBuilder statesBuilder = states.toBuilder()
.putString("wood_type", woodType)
.putBoolean("stripped_bit", stripped);

NbtMapBuilder builder = tag.toBuilder()
.putString("name", replacement)
.putCompound("states", statesBuilder.build());

return builder.build();
}

if (NEW_LEAVES.contains(name) || NEW_LEAVES2.contains(name)) {
boolean leaves2 = NEW_LEAVES2.contains(name);
replacement = leaves2 ? "minecraft:leaves2" : "minecraft:leaves";

NbtMap states = tag.getCompound("states");
String leafType = name.replaceAll("minecraft:|_leaves", "");

NbtMapBuilder statesBuilder = states.toBuilder()
.putString(leaves2 ? "new_leaf_type" : "old_leaf_type", leafType);

NbtMapBuilder builder = tag.toBuilder()
.putString("name", replacement)
.putCompound("states", statesBuilder.build());

return builder.build();
}


if (NEW_SLABS.contains(name)) {
replacement = name.contains("double") ? "minecraft:double_wooden_slab" : "minecraft:wooden_slab";

NbtMap states = tag.getCompound("states");
String woodType = name.replaceAll("minecraft:|_double|_slab", "");

NbtMapBuilder statesBuilder = states.toBuilder()
.putString("wood_type", woodType);

NbtMapBuilder builder = tag.toBuilder()
.putString("name", replacement)
.putCompound("states", statesBuilder.build());

return builder.build();
}

return tag;
}
}
Loading

0 comments on commit 1df63c6

Please sign in to comment.