Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed Jun 13, 2024
1 parent 4b6c20f commit b78e657
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ subprojects {
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'it.unimi.dsi:fastutil:8.5.12'
compileOnly('com.mojang:datafixerupper:4.1.27') { transitive = false }

Expand Down
2 changes: 1 addition & 1 deletion rtag-block/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
}
18 changes: 9 additions & 9 deletions rtag-block/src/main/java/com/saicone/rtag/block/BlockObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ public class BlockObject {
method$getHandle = EasyLookup.method("CraftWorld", "getHandle", "WorldServer");

if (ServerInstance.Release.COMPONENT) {
method$save = EasyLookup.method("TileEntity", save, "NBTTagCompound", "HolderLookup.Provider");
method$getWorld = EasyLookup.method("TileEntity", getWorld, "World");
method$save = EasyLookup.method(TILE_ENTITY, save, "NBTTagCompound", "HolderLookup.Provider");
method$getWorld = EasyLookup.method(TILE_ENTITY, getWorld, "World");
method$getRegistry = EasyLookup.method("IWorldReader", getRegistry, "IRegistryCustom");
} else if (ServerInstance.MAJOR_VERSION >= 18) {
method$save = EasyLookup.method("TileEntity", save, "NBTTagCompound");
method$save = EasyLookup.method(TILE_ENTITY, save, "NBTTagCompound");
} else {
// (1.8) void method
method$save = EasyLookup.method("TileEntity", save, "NBTTagCompound", "NBTTagCompound");
method$save = EasyLookup.method(TILE_ENTITY, save, "NBTTagCompound", "NBTTagCompound");
}

if (ServerInstance.Release.COMPONENT) {
method$load = EasyLookup.method("TileEntity", load, void.class, "NBTTagCompound", "HolderLookup.Provider");
method$load = EasyLookup.method(TILE_ENTITY, load, void.class, "NBTTagCompound", "HolderLookup.Provider");
} else if (ServerInstance.MAJOR_VERSION == 16) {
method$getPosition = EasyLookup.method("TileEntity", "getPosition", "BlockPosition");
method$getWorld = EasyLookup.method("TileEntity", "getWorld", "World");
method$getPosition = EasyLookup.method(TILE_ENTITY, "getPosition", "BlockPosition");
method$getWorld = EasyLookup.method(TILE_ENTITY, "getWorld", "World");
method$getType = EasyLookup.method("World", "getType", "IBlockData", "BlockPosition");

method$load = EasyLookup.method("TileEntity", load, void.class, "IBlockData", "NBTTagCompound");
method$load = EasyLookup.method(TILE_ENTITY, load, void.class, "IBlockData", "NBTTagCompound");
} else {
method$load = EasyLookup.method("TileEntity", load, void.class, "NBTTagCompound");
method$load = EasyLookup.method(TILE_ENTITY, load, void.class, "NBTTagCompound");
}
} catch (NoSuchMethodException | IllegalAccessException e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion rtag-entity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
}
2 changes: 1 addition & 1 deletion rtag-item/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repositories {
}

dependencies {
compileOnly 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
compileOnly 'com.mojang:authlib:1.5.26' // 3.11.50
compileOnly('com.mojang:datafixerupper:4.1.27') { transitive = false }
}
2 changes: 1 addition & 1 deletion rtag-item/src/main/java/com/saicone/rtag/RtagItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public boolean addEnchantment(Object enchant, int level) {
}
// Since 1.20.5, items cannot hold invalid enchantments
if (ServerInstance.Release.COMPONENT) {
getItem().addEnchantment(tag.getEnchantment(), level);
getItem().addUnsafeEnchantment(tag.getEnchantment(), level);
return true;
}
final Object enchantment = getEnchantment(tag);
Expand Down
13 changes: 12 additions & 1 deletion rtag-item/src/main/java/com/saicone/rtag/item/ItemObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class ItemObject {
try {
// Old method names
String registry$item = "h";
String key$parse = "a";
String createStack = "createStack";
String save = "save";
String apply = "c";
Expand All @@ -86,6 +87,7 @@ public class ItemObject {
// New method names
if (ServerInstance.Type.MOJANG_MAPPED) {
registry$item = "ITEM";
key$parse = "parse";
getItem = "get";
setItem = "item";
if (ServerInstance.Release.COMPONENT) {
Expand All @@ -102,6 +104,9 @@ public class ItemObject {
} else if (ServerInstance.MAJOR_VERSION >= 11) {
if (ServerInstance.Release.COMPONENT) {
apply = "a";
if (ServerInstance.MAJOR_VERSION >= 21) {
registry$item = "g";
}
} else {
apply = "load";
}
Expand Down Expand Up @@ -129,7 +134,11 @@ public class ItemObject {
const$customData = ComponentType.of("minecraft:custom_data");
const$item = EasyLookup.classById("BuiltInRegistries").getDeclaredField(registry$item).get(null);

new$MinecraftKey = EasyLookup.constructor("MinecraftKey", String.class);
if (ServerInstance.MAJOR_VERSION >= 21) {
new$MinecraftKey = EasyLookup.staticMethod("MinecraftKey", key$parse, "MinecraftKey", String.class);
} else {
new$MinecraftKey = EasyLookup.constructor("MinecraftKey", String.class);
}

method$getItem = EasyLookup.method("RegistryBlocks", getItem, Object.class, "MinecraftKey");
method$setItem = EasyLookup.unreflectSetter(MC_ITEM, setItem);
Expand Down Expand Up @@ -304,6 +313,8 @@ private static void initPaths() {
// - 24w13a
initPath("minecraft:item_name", "tag", "components", "minecraft:item_name");
initPath("minecraft:ominous_bottle_amplifier", "tag", "components", "minecraft:ominous_bottle_amplifier");
// - 24w21a
initPath("minecraft:jukebox_playable", "tag", "components", "minecraft:jukebox_playable");
// --- Not supported
// minecraft:hide_additional_tooltip = Same has 6th bit from tag.HideFlags
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,14 @@ public enum ItemMaterialTag {
MUSIC_DISC_BLOCKS(13, "RECORD_BLOCKS", 8, "RECORD_3"),
MUSIC_DISC_CAT(13, "RECORD_CAT", 8, "GREEN_RECORD"),
MUSIC_DISC_CHIRP(13, "RECORD_CHIRP", 8, "RECORD_4"),
MUSIC_DISC_CREATOR(21),
MUSIC_DISC_CREATOR_MUSIC_BOX(21),
MUSIC_DISC_FAR(13, "RECORD_FAR", 8, "RECORD_5"),
MUSIC_DISC_MALL(13, "RECORD_MALL", 8, "RECORD_6"),
MUSIC_DISC_MELLOHI(13, "RECORD_MELLOHI", 8, "RECORD_7"),
MUSIC_DISC_OTHERSIDE(18),
MUSIC_DISC_PIGSTEP(16),
MUSIC_DISC_PRECIPICE(21),
MUSIC_DISC_RELIC(20),
MUSIC_DISC_STAL(13, "RECORD_STAL", 8, "RECORD_8"),
MUSIC_DISC_STRAD(13, "RECORD_STRAD", 8, "RECORD_9"),
Expand Down
2 changes: 1 addition & 1 deletion rtag-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
implementation project(':rtag-entity')
implementation project(':rtag-item')

compileOnly 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
}

jar.dependsOn (shadowJar)
2 changes: 2 additions & 0 deletions src/main/java/com/saicone/rtag/data/ComponentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class ComponentType {
holder$value = "value";
codec = "codec";
nbtOps$instance = "INSTANCE";
} else if (ServerInstance.MAJOR_VERSION >= 21) {
registry$components = "aq";
}

final Object componentsRegistry = EasyLookup.classById("BuiltInRegistries").getDeclaredField(registry$components).get(null);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/saicone/rtag/util/ServerInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ServerInstance {
VERSION_MAP.put(3578, new Integer[] {20, 2, 12002});
VERSION_MAP.put(3698, new Integer[] {20, 3, 12003});
VERSION_MAP.put(3837, new Integer[] {20, 4, 12004});
VERSION_MAP.put(3953, new Integer[] {21, 1, 12101});

final String serverPackage = Bukkit.getServer().getClass().getPackage().getName();
if (serverPackage.startsWith("org.bukkit.craftbukkit.v1_")) {
Expand Down

0 comments on commit b78e657

Please sign in to comment.