Skip to content

Commit

Permalink
Minecraft 1.21 and Velocity b398+ support (#154)
Browse files Browse the repository at this point in the history
* 1.21 support

* Disable blockstate mappings generation for 1.21

* Fix registries on 1.20.5 and older

* Remove workaround for downloading 1.21 manifest
  • Loading branch information
UserNugget committed Jun 13, 2024
1 parent 1b18b3d commit 35e9edd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ allprojects() {
setName("papermc-repo")
setUrl("https://papermc.io/repo/repository/maven-public/")
}
maven() {
setName("sonatype-snapshots-repo")
setUrl("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}

checkstyle() {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fastutilVersion=8.5.11
bstatsVersion=3.0.0
spotbugsVersion=4.7.3
elytriumCommonsVersion=1.2.3
adventureVersion=4.15.0-SNAPSHOT
adventureVersion=4.15.0
manifestUrl=https://launchermeta.mojang.com/mc/game/version_manifest.json
cacheValidMillis=6000000
6 changes: 4 additions & 2 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ enum MinecraftVersion {
MINECRAFT_1_20(763),
MINECRAFT_1_20_2(764),
MINECRAFT_1_20_3(765),
MINECRAFT_1_20_5(766)
MINECRAFT_1_20_5(766),
MINECRAFT_1_21(767)

public static final List<MinecraftVersion> WORLD_VERSIONS = List.of(
MINECRAFT_1_13,
Expand All @@ -146,7 +147,8 @@ enum MinecraftVersion {
)

public static final List<MinecraftVersion> COMPONENT_VERSIONS = List.of(
MINECRAFT_1_20_5
MINECRAFT_1_20_5,
MINECRAFT_1_21
)

public static final MinecraftVersion MINIMUM_VERSION = MINECRAFT_1_7_2
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/java/net/elytrium/limboapi/LimboAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
@SuppressFBWarnings("MS_EXPOSE_REP")
public class LimboAPI implements LimboFactory {

private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 766;
private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 767;

@MonotonicNonNull
private static Logger LOGGER;
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/java/net/elytrium/limboapi/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static class MAIN {
"1_7_2, 1_7_6, 1_8, 1_9, 1_9_1, 1_9_2, 1_9_4, 1_10, 1_11, 1_11_1, 1_12, 1_12_1, 1_12_2,",
"1_13, 1_13_1, 1_13_2, 1_14, 1_14_1, 1_14_2, 1_14_3, 1_14_4, 1_15, 1_15_1, 1_15_2,",
"1_16, 1_16_1, 1_16_2, 1_16_3, 1_16_4, 1_17, 1_17_1, 1_18, 1_18_2, 1_19, 1_19_1, 1_19_3,",
"1_20, 1_20_2, 1_20_3, 1_20_5, LATEST"
"1_20, 1_20_2, 1_20_3, 1_20_5, 1_21, LATEST"
})
public String PREPARE_MIN_VERSION = "1_7_2";
public String PREPARE_MAX_VERSION = "LATEST";
Expand Down
75 changes: 69 additions & 6 deletions plugin/src/main/java/net/elytrium/limboapi/server/LimboImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
Expand Down Expand Up @@ -113,6 +114,7 @@
import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.ListBinaryTag;
import net.kyori.adventure.nbt.StringBinaryTag;
import net.kyori.adventure.text.Component;

public class LimboImpl implements Limbo {
Expand Down Expand Up @@ -234,7 +236,8 @@ protected void refresh() {

this.configPackets = this.plugin.createConfigPreparedPacket();
this.configPackets.prepare(this::createRegistrySyncLegacy, ProtocolVersion.MINECRAFT_1_20_2, ProtocolVersion.MINECRAFT_1_20_3);
this.createRegistrySyncModern(this.configPackets, ProtocolVersion.MINECRAFT_1_20_5);
this.createRegistrySyncModern(this.configPackets, ProtocolVersion.MINECRAFT_1_20_5, ProtocolVersion.MINECRAFT_1_20_5);
this.createRegistrySyncModern(this.configPackets, ProtocolVersion.MINECRAFT_1_21, ProtocolVersion.MAXIMUM_VERSION);
if (this.shouldUpdateTags) {
this.configPackets.prepare(this::createTagsUpdate, ProtocolVersion.MINECRAFT_1_20_2);
}
Expand Down Expand Up @@ -268,7 +271,6 @@ private ChangeGameStatePacket createLevelChunksLoadStartGameState() {
private RegistrySyncPacket createRegistrySyncLegacy(ProtocolVersion version) {
JoinGamePacket join = this.createJoinGamePacket(version);

// Blame Velocity for this madness
ByteBuf encodedRegistry = this.plugin.getPreparedPacketFactory().getPreparedPacketAllocator().ioBuffer();
ProtocolUtils.writeBinaryTag(encodedRegistry, version, join.getRegistry());

Expand All @@ -277,10 +279,9 @@ private RegistrySyncPacket createRegistrySyncLegacy(ProtocolVersion version) {
return sync;
}

private void createRegistrySyncModern(PreparedPacket packet, ProtocolVersion initialVersion) {
JoinGamePacket join = this.createJoinGamePacket(initialVersion);
private void createRegistrySyncModern(PreparedPacket packet, ProtocolVersion from, ProtocolVersion to) {
JoinGamePacket join = this.createJoinGamePacket(from);

// Blame Velocity for this madness
CompoundBinaryTag registryTag = join.getRegistry();
for (String key : registryTag.keySet()) {
CompoundBinaryTag entry = registryTag.getCompound(key);
Expand Down Expand Up @@ -328,7 +329,7 @@ private void createRegistrySyncModern(PreparedPacket packet, ProtocolVersion ini
RegistrySyncPacket sync = new RegistrySyncPacket();
sync.replace(registry);
return sync;
}, initialVersion);
}, from, to);
}
}

Expand Down Expand Up @@ -749,6 +750,27 @@ private <T extends Command> boolean tryRegister(CommandRegistrar<T> registrar, C
}
}

private CompoundBinaryTag createRegistry(String registryName, Map<String, CompoundBinaryTag> tags) {
int id = 0;

ListBinaryTag.Builder<CompoundBinaryTag> builder = ListBinaryTag.builder(BinaryTagTypes.COMPOUND);
for (Entry<String, CompoundBinaryTag> tag : tags.entrySet()) {
builder.add(CompoundBinaryTag.builder()
.putString("name", tag.getKey())
.putInt("id", id++)
.put("element", tag.getValue())
.build());
}

return this.createRegistry(registryName, builder.build());
}

private CompoundBinaryTag createRegistry(String registryName, ListBinaryTag tags) {
return CompoundBinaryTag.builder()
.putString("type", registryName)
.put("value", tags).build();
}

private CompoundBinaryTag createDimensionData(Dimension dimension, ProtocolVersion version) {
CompoundBinaryTag details = CompoundBinaryTag.builder()
.putBoolean("natural", false)
Expand Down Expand Up @@ -827,11 +849,52 @@ private JoinGamePacket createJoinGamePacket(ProtocolVersion version) {
registryContainer.put("minecraft:chat_type", CHAT_TYPE_1191);
}

// TODO: Generate mappings for damage_type registry
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_4) == 0) {
registryContainer.put("minecraft:damage_type", DAMAGE_TYPE_1194);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_21) >= 0) {
CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder();
ListBinaryTag values = DAMAGE_TYPE_120.getList("value");

ListBinaryTag.Builder<CompoundBinaryTag> tags = ListBinaryTag.builder(BinaryTagTypes.COMPOUND);
for (BinaryTag tag : values) {
tags.add((CompoundBinaryTag) tag);
}

CompoundBinaryTag.Builder campfileType = CompoundBinaryTag.builder()
.putString("name", "minecraft:campfire")
.putInt("id", values.size())
.put("element", values.getCompound(0).getCompound("element"));

tags.add(campfileType.build());

registryContainer.put("minecraft:damage_type", this.createRegistry("minecraft:damage_type", tags.build()));
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
registryContainer.put("minecraft:damage_type", DAMAGE_TYPE_120);
}

// TODO: Generate mappings for painting_variant and wolf_variant registries
if (version.compareTo(ProtocolVersion.MINECRAFT_1_21) >= 0) {
// TODO: API
CompoundBinaryTag.Builder paintingVariant = CompoundBinaryTag.builder()
.putInt("width", 1)
.putInt("height", 1)
.putString("asset_id", "minecraft:alban");

registryContainer.put("minecraft:painting_variant", this.createRegistry("minecraft:painting_variant",
Map.of("minecraft:alban", paintingVariant.build())));

CompoundBinaryTag.Builder wolfVariant = CompoundBinaryTag.builder()
.putString("wild_texture", "minecraft:entity/wolf/wolf_ashen")
.putString("tame_texture", "minecraft:entity/wolf/wolf_ashen_tame")
.putString("angry_texture", "minecraft:entity/wolf/wolf_ashen_angry")
.put("biomes", ListBinaryTag.builder()
.add(StringBinaryTag.stringBinaryTag("minecraft:plains")).build()
);

registryContainer.put("minecraft:wolf_variant", this.createRegistry("minecraft:wolf_variant",
Map.of("minecraft:ashen", wolfVariant.build())));
}
} else {
registryContainer.put("dimension", encodedDimensionRegistry);
}
Expand Down

0 comments on commit 35e9edd

Please sign in to comment.