-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from AerWyn81/master
Added support 1.20.2
- Loading branch information
Showing
6 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":nms:interfaces")) | ||
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") | ||
compileOnly(files("../../libs/spigot-1.20.2-R0.1-SNAPSHOT.jar")) | ||
} |
53 changes: 53 additions & 0 deletions
53
...1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package fr.fabienhebuterne.customcraft.nms; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
import net.minecraft.nbt.NBTCompressedStreamTools; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
public class ItemStackSerializer_1_20_R2 implements ItemStackSerializer { | ||
@Override | ||
public String serializeItemStack(ItemStack itemStack) { | ||
if (itemStack == null) { | ||
return "null"; | ||
} | ||
|
||
ByteArrayOutputStream outputStream = null; | ||
|
||
try { | ||
NBTTagCompound nbtTagCompound = new NBTTagCompound(); | ||
net.minecraft.world.item.ItemStack itemStackNms = CraftItemStack.asNMSCopy(itemStack); | ||
NBTTagCompound nbtToSave = itemStackNms.b(nbtTagCompound); | ||
outputStream = new ByteArrayOutputStream(); | ||
NBTCompressedStreamTools.a(nbtToSave, outputStream); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return BaseEncoding.base64().encode(outputStream.toByteArray()); | ||
} | ||
|
||
@Override | ||
public ItemStack deserializeItemStack(String itemStack) { | ||
if (itemStack.equals("null")) { | ||
return null; | ||
} | ||
|
||
ByteArrayInputStream inputStream = new ByteArrayInputStream(BaseEncoding.base64().decode(itemStack)); | ||
|
||
try { | ||
NBTTagCompound tagCompound = NBTCompressedStreamTools.a(inputStream); | ||
net.minecraft.world.item.ItemStack itemStackNms = net.minecraft.world.item.ItemStack.a(tagCompound); | ||
return CraftItemStack.asBukkitCopy(itemStackNms); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ include( | |
"nms:v1_19_R1", | ||
"nms:v1_19_R2", | ||
"nms:v1_19_R3", | ||
"nms:v1_20_R1" | ||
"nms:v1_20_R1", | ||
"nms:v1_20_R2" | ||
) |