mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-25 11:46:54 +01:00
Update ItemStac Serialization, add new 1.20.5+ default schematic
This commit is contained in:
parent
68a47ce0c5
commit
09e5291478
@ -1,5 +1,6 @@
|
||||
package com.craftaro.skyblock.config;
|
||||
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.skyblock.SkyBlock;
|
||||
import com.craftaro.skyblock.island.IslandWorld;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@ -93,6 +94,16 @@ public class FileManager {
|
||||
|
||||
if (fileName.equals("structures/default.structure")) {
|
||||
configFile.delete();
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_20_5)) {
|
||||
//Copy default_1_20_5.structure instead of default.structure
|
||||
try (InputStream is = this.plugin.getResource("structures/default_1_20_5.structure"); OutputStream os = Files.newOutputStream(configFile.toPath())) {
|
||||
if (is != null) {
|
||||
ByteStreams.copy(is, os);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
configFile.createNewFile();
|
||||
} catch (IOException ex) {
|
||||
@ -105,6 +116,7 @@ public class FileManager {
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,9 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ItemStackUtil {
|
||||
private static final boolean isAbove1_16_R1 = MajorServerVersion.isServerVersionAtLeast(MajorServerVersion.V1_16)
|
||||
@ -28,6 +30,11 @@ public class ItemStackUtil {
|
||||
|
||||
ItemStack itemStack = null;
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_20_5)) {
|
||||
//We need net.minecraft.nbt.NbtIo class in this version
|
||||
byte[] bytes = new BigInteger(data, 32).toByteArray();
|
||||
itemStack = ItemStack.deserializeBytes(bytes);
|
||||
} else {
|
||||
try {
|
||||
Class<?> NBTTagCompoundClass = ClassMapping.NBT_TAG_COMPOUND.getClazz();
|
||||
Class<?> NMSItemStackClass = ClassMapping.ITEM_STACK.getClazz();
|
||||
@ -64,11 +71,18 @@ public class ItemStackUtil {
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static String serializeItemStack(ItemStack item) {
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_20_5)) {
|
||||
//We need net.minecraft.nbt.NbtIo class in this version
|
||||
byte[] bytes = item.serializeAsBytes();
|
||||
return new BigInteger(bytes).toString(32);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
DataOutputStream dataOutput = new DataOutputStream(outputStream);
|
||||
|
||||
|
1
src/main/resources/structures/default_1_20_5.structure
Normal file
1
src/main/resources/structures/default_1_20_5.structure
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user