Skip to content

Commit 53c9826

Browse files
committed
2.0.1 - 1.21.3 support
1 parent 704cef7 commit 53c9826

File tree

8 files changed

+86
-7
lines changed

8 files changed

+86
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ A simple library for storing and retrieving ItemStacks in Bukkit-related environ
66
Version support
77
------
88

9-
Currently, Cardboard Box supports 1.7 through 1.21.1.
10-
Will it need an update for 1.21.2 (if it happens)? Maybe.
9+
Currently, Cardboard Box supports 1.7 through 1.21.3.
10+
Will it need an update for 1.21.4? Maybe.
1111
Will it need an update for 1.22? Definitely.
1212

1313
Support

combined/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
implementation(project(":api"))
1616
implementation(project(":v1.20.6"))
1717
implementation(project(":v1.21"))
18+
implementation(project(":v1.21.3"))
1819
}
1920

2021
java {
@@ -37,7 +38,7 @@ publishing {
3738
//artifact(tasks["shadowJar"])
3839
groupId = "dev.kitteh"
3940
artifactId = "cardboardbox"
40-
version = "2.0.0"
41+
version = "2.0.1"
4142
pom {
4243
name = "CardboardBox"
4344
description = "A Bukkit-related data storage handler"

combined/src/main/java/dev/kitteh/cardboardbox/CardboardBox.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ private static void init() {
3838
JavaPlugin.getProvidingPlugin(CardboardBox.class).getLogger().warning("CardboardBox could not identify Minecraft version.");
3939
ready = false;
4040
}
41-
if (mcVersion >= 2100) {
41+
if (mcVersion >= 2103) {
42+
chosenBox = getBox("v1_21_3");
43+
} else if (mcVersion >= 2100) {
4244
chosenBox = getBox("v1_21");
4345
} else if (mcVersion == 2006) {
4446
chosenBox = getBox("v1_20_6");

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ rootProject.name = "cardboardbox"
22
include("api")
33
include("v1.20.6")
44
include("v1.21")
5+
include("v1.21.3")
56
include("combined")
6-

v1.20.6/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("java")
3-
id("io.papermc.paperweight.userdev") version "1.7.1"
3+
id("io.papermc.paperweight.userdev") version "1.7.4"
44
}
55

66
java {

v1.21.3/build.gradle.kts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id("java")
3+
id("io.papermc.paperweight.userdev") version "1.7.4"
4+
}
5+
6+
java {
7+
toolchain {
8+
languageVersion = JavaLanguageVersion.of(21)
9+
}
10+
}
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT")
18+
compileOnly(project(":api"))
19+
}
20+
21+
tasks.assemble {
22+
dependsOn(tasks.reobfJar)
23+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package dev.kitteh.cardboardbox.v1_21_3;
2+
3+
import com.google.common.base.Preconditions;
4+
import com.mojang.serialization.Dynamic;
5+
import net.minecraft.nbt.CompoundTag;
6+
import net.minecraft.nbt.NbtOps;
7+
import net.minecraft.server.MinecraftServer;
8+
import net.minecraft.util.datafix.fixes.References;
9+
import org.bukkit.craftbukkit.inventory.CraftItemStack;
10+
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
11+
import org.bukkit.inventory.ItemStack;
12+
13+
import java.io.IOException;
14+
15+
public class Box implements dev.kitteh.cardboardbox.api.Box {
16+
public boolean check(ItemStack itemStack) {
17+
return itemStack.equals(deserializeItem(serializeItem(itemStack)));
18+
}
19+
20+
private static final int DATA_VERSION = CraftMagicNumbers.INSTANCE.getDataVersion();
21+
22+
@Override
23+
public byte[] serializeItem(ItemStack item) {
24+
CompoundTag compound = (net.minecraft.nbt.CompoundTag) CraftItemStack.asNMSCopy(item).save(MinecraftServer.getServer().registryAccess());
25+
compound.putInt("DataVersion", DATA_VERSION);
26+
java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
27+
try {
28+
net.minecraft.nbt.NbtIo.writeCompressed(
29+
compound,
30+
outputStream
31+
);
32+
} catch (IOException ex) {
33+
throw new RuntimeException(ex);
34+
}
35+
return outputStream.toByteArray();
36+
}
37+
38+
@Override
39+
public ItemStack deserializeItem(byte[] data) {
40+
net.minecraft.nbt.CompoundTag compound;
41+
try {
42+
compound = net.minecraft.nbt.NbtIo.readCompressed(
43+
new java.io.ByteArrayInputStream(data), net.minecraft.nbt.NbtAccounter.unlimitedHeap()
44+
);
45+
} catch (IOException ex) {
46+
throw new RuntimeException(ex);
47+
}
48+
final int dataVersion = compound.getInt("DataVersion");
49+
Preconditions.checkArgument(dataVersion <= DATA_VERSION, "Newer version! Server downgrades are not supported!");
50+
compound = (net.minecraft.nbt.CompoundTag) MinecraftServer.getServer().fixerUpper.update(References.ITEM_STACK, new Dynamic<>(NbtOps.INSTANCE, compound), dataVersion, dataVersion).getValue();
51+
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.parse(MinecraftServer.getServer().registryAccess(), compound).orElseThrow());
52+
}
53+
}

v1.21/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("java")
3-
id("io.papermc.paperweight.userdev") version "1.7.1"
3+
id("io.papermc.paperweight.userdev") version "1.7.4"
44
}
55

66
java {

0 commit comments

Comments
 (0)