mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-19 14:59:21 +00:00
feat: support newer Map data format, close #406
This commit is contained in:
@@ -4,7 +4,7 @@ dependencies {
|
|||||||
implementation 'net.william278.uniform:uniform-bukkit:1.2.2'
|
implementation 'net.william278.uniform:uniform-bukkit:1.2.2'
|
||||||
implementation 'net.william278:mpdbdataconverter:1.0.1'
|
implementation 'net.william278:mpdbdataconverter:1.0.1'
|
||||||
implementation 'net.william278:hsldataconverter:1.0'
|
implementation 'net.william278:hsldataconverter:1.0'
|
||||||
implementation 'net.william278:mapdataapi:1.0.3'
|
implementation 'net.william278:mapdataapi:2.0'
|
||||||
implementation 'org.bstats:bstats-bukkit:3.1.0'
|
implementation 'org.bstats:bstats-bukkit:3.1.0'
|
||||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
||||||
implementation 'dev.triumphteam:triumph-gui:3.1.10'
|
implementation 'dev.triumphteam:triumph-gui:3.1.10'
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import de.tr7zw.changeme.nbtapi.utils.DataFixerUtil;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -331,6 +332,21 @@ public class BukkitHuskSync extends JavaPlugin implements HuskSync, BukkitTask.S
|
|||||||
return Version.fromString(getServer().getBukkitVersion());
|
return Version.fromString(getServer().getBukkitVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDataVersion(@NotNull Version mcVersion) {
|
||||||
|
return switch (mcVersion.toStringWithoutMetadata()) {
|
||||||
|
case "1.16", "1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5" -> DataFixerUtil.VERSION1_16_5;
|
||||||
|
case "1.17", "1.17.1" -> DataFixerUtil.VERSION1_17_1;
|
||||||
|
case "1.18", "1.18.1", "1.18.2" -> DataFixerUtil.VERSION1_18_2;
|
||||||
|
case "1.19", "1.19.1", "1.19.2" -> DataFixerUtil.VERSION1_19_2;
|
||||||
|
case "1.20", "1.20.1", "1.20.2" -> DataFixerUtil.VERSION1_20_2;
|
||||||
|
case "1.20.3", "1.20.4" -> DataFixerUtil.VERSION1_20_4;
|
||||||
|
case "1.20.5", "1.20.6" -> DataFixerUtil.VERSION1_20_5;
|
||||||
|
case "1.21", "1.21.1" -> DataFixerUtil.VERSION1_21;
|
||||||
|
case "1.21.2", "1.21.3" -> DataFixerUtil.VERSION1_21_2;
|
||||||
|
default -> DataFixerUtil.getCurrentVersion();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getPlatformType() {
|
public String getPlatformType() {
|
||||||
|
|||||||
@@ -153,22 +153,11 @@ public class BukkitSerializer {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private ReadWriteNBT upgradeItemData(@NotNull ReadWriteNBT tag, @NotNull Version mcVersion)
|
private ReadWriteNBT upgradeItemData(@NotNull ReadWriteNBT tag, @NotNull Version mcVersion)
|
||||||
throws NoSuchFieldException, IllegalAccessException {
|
throws NoSuchFieldException, IllegalAccessException {
|
||||||
return DataFixerUtil.fixUpItemData(tag, getDataVersion(mcVersion), DataFixerUtil.getCurrentVersion());
|
return DataFixerUtil.fixUpItemData(
|
||||||
}
|
tag,
|
||||||
|
getPlugin().getDataVersion(mcVersion),
|
||||||
private int getDataVersion(@NotNull Version mcVersion) {
|
DataFixerUtil.getCurrentVersion()
|
||||||
return switch (mcVersion.toStringWithoutMetadata()) {
|
);
|
||||||
case "1.16", "1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5" -> DataFixerUtil.VERSION1_16_5;
|
|
||||||
case "1.17", "1.17.1" -> DataFixerUtil.VERSION1_17_1;
|
|
||||||
case "1.18", "1.18.1", "1.18.2" -> DataFixerUtil.VERSION1_18_2;
|
|
||||||
case "1.19", "1.19.1", "1.19.2" -> DataFixerUtil.VERSION1_19_2;
|
|
||||||
case "1.20", "1.20.1", "1.20.2" -> DataFixerUtil.VERSION1_20_2;
|
|
||||||
case "1.20.3", "1.20.4" -> DataFixerUtil.VERSION1_20_4;
|
|
||||||
case "1.20.5", "1.20.6" -> DataFixerUtil.VERSION1_20_5;
|
|
||||||
case "1.21", "1.21.1" -> DataFixerUtil.VERSION1_21;
|
|
||||||
case "1.21.2", "1.21.3" -> DataFixerUtil.VERSION1_21_2;
|
|
||||||
default -> DataFixerUtil.getCurrentVersion();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ public interface BukkitMapPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render the map
|
// Render the map
|
||||||
final PersistentMapCanvas canvas = new PersistentMapCanvas(view);
|
final int dataVersion = getPlugin().getDataVersion(getPlugin().getMinecraftVersion());
|
||||||
|
final PersistentMapCanvas canvas = new PersistentMapCanvas(view, dataVersion);
|
||||||
for (MapRenderer renderer : view.getRenderers()) {
|
for (MapRenderer renderer : view.getRenderers()) {
|
||||||
renderer.render(view, canvas, delegateRenderer);
|
renderer.render(view, canvas, delegateRenderer);
|
||||||
getPlugin().debug(String.format("Rendered locked map canvas to view (#%s)", view.getId()));
|
getPlugin().debug(String.format("Rendered locked map canvas to view (#%s)", view.getId()));
|
||||||
@@ -140,6 +141,7 @@ public interface BukkitMapPersister {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ItemStack applyMapView(@NotNull ItemStack map) {
|
private ItemStack applyMapView(@NotNull ItemStack map) {
|
||||||
|
final int dataVersion = getPlugin().getDataVersion(getPlugin().getMinecraftVersion());
|
||||||
final MapMeta meta = Objects.requireNonNull((MapMeta) map.getItemMeta());
|
final MapMeta meta = Objects.requireNonNull((MapMeta) map.getItemMeta());
|
||||||
NBT.get(map, nbt -> {
|
NBT.get(map, nbt -> {
|
||||||
if (!nbt.hasTag(MAP_DATA_KEY)) {
|
if (!nbt.hasTag(MAP_DATA_KEY)) {
|
||||||
@@ -178,8 +180,9 @@ public interface BukkitMapPersister {
|
|||||||
final MapData canvasData;
|
final MapData canvasData;
|
||||||
try {
|
try {
|
||||||
getPlugin().debug("Deserializing map data from NBT and generating view...");
|
getPlugin().debug("Deserializing map data from NBT and generating view...");
|
||||||
canvasData = MapData.fromByteArray(Objects.requireNonNull(mapData.getByteArray(MAP_PIXEL_DATA_KEY),
|
canvasData = MapData.fromByteArray(
|
||||||
"Map pixel data is null"));
|
dataVersion,
|
||||||
|
Objects.requireNonNull(mapData.getByteArray(MAP_PIXEL_DATA_KEY), "Pixel data null!"));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
getPlugin().log(Level.WARNING, "Failed to deserialize map data from NBT", e);
|
getPlugin().log(Level.WARNING, "Failed to deserialize map data from NBT", e);
|
||||||
return;
|
return;
|
||||||
@@ -357,11 +360,13 @@ public interface BukkitMapPersister {
|
|||||||
*/
|
*/
|
||||||
class PersistentMapCanvas implements MapCanvas {
|
class PersistentMapCanvas implements MapCanvas {
|
||||||
|
|
||||||
|
private final int mapDataVersion;
|
||||||
private final MapView mapView;
|
private final MapView mapView;
|
||||||
private final int[][] pixels = new int[128][128];
|
private final int[][] pixels = new int[128][128];
|
||||||
private MapCursorCollection cursors;
|
private MapCursorCollection cursors;
|
||||||
|
|
||||||
private PersistentMapCanvas(@NotNull MapView mapView) {
|
private PersistentMapCanvas(@NotNull MapView mapView, int mapDataVersion) {
|
||||||
|
this.mapDataVersion = mapDataVersion;
|
||||||
this.mapView = mapView;
|
this.mapView = mapView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,7 +464,7 @@ public interface BukkitMapPersister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return MapData.fromPixels(pixels, getDimension(), (byte) 2, banners, List.of());
|
return MapData.fromPixels(mapDataVersion, pixels, getDimension(), (byte) 2, banners, List.of());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -249,6 +249,14 @@ public interface HuskSync extends Task.Supplier, EventDispatcher, ConfigProvider
|
|||||||
@NotNull
|
@NotNull
|
||||||
Version getMinecraftVersion();
|
Version getMinecraftVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data version for a Minecraft version
|
||||||
|
*
|
||||||
|
* @param minecraftVersion the Minecraft version
|
||||||
|
* @return the data version int
|
||||||
|
*/
|
||||||
|
int getDataVersion(@NotNull Version minecraftVersion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the platform type
|
* Returns the platform type
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -84,6 +84,18 @@ public class FabricHuskSync implements DedicatedServerModInitializer, HuskSync,
|
|||||||
|
|
||||||
private static final String PLATFORM_TYPE_ID = "fabric";
|
private static final String PLATFORM_TYPE_ID = "fabric";
|
||||||
|
|
||||||
|
private static final int VERSION1_16_5 = 2586;
|
||||||
|
private static final int VERSION1_17_1 = 2730;
|
||||||
|
private static final int VERSION1_18_2 = 2975;
|
||||||
|
private static final int VERSION1_19_2 = 3120;
|
||||||
|
private static final int VERSION1_19_4 = 3337;
|
||||||
|
private static final int VERSION1_20_1 = 3465;
|
||||||
|
private static final int VERSION1_20_2 = 3578;
|
||||||
|
private static final int VERSION1_20_4 = 3700;
|
||||||
|
private static final int VERSION1_20_5 = 3837;
|
||||||
|
private static final int VERSION1_21_1 = 3955;
|
||||||
|
private static final int VERSION1_21_3 = 4082; // Current
|
||||||
|
|
||||||
private final TreeMap<Identifier, Serializer<? extends Data>> serializers = Maps.newTreeMap(
|
private final TreeMap<Identifier, Serializer<? extends Data>> serializers = Maps.newTreeMap(
|
||||||
SerializerRegistry.DEPENDENCY_ORDER_COMPARATOR
|
SerializerRegistry.DEPENDENCY_ORDER_COMPARATOR
|
||||||
);
|
);
|
||||||
@@ -346,6 +358,24 @@ public class FabricHuskSync implements DedicatedServerModInitializer, HuskSync,
|
|||||||
return Version.fromString(minecraftServer.getVersion());
|
return Version.fromString(minecraftServer.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public int getDataVersion(@NotNull Version mcVersion) {
|
||||||
|
return switch (mcVersion.toStringWithoutMetadata()) {
|
||||||
|
case "1.16", "1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5" -> VERSION1_16_5;
|
||||||
|
case "1.17", "1.17.1" -> VERSION1_17_1;
|
||||||
|
case "1.18", "1.18.1", "1.18.2" -> VERSION1_18_2;
|
||||||
|
case "1.19", "1.19.1", "1.19.2" -> VERSION1_19_2;
|
||||||
|
case "1.19.4" -> VERSION1_19_4;
|
||||||
|
case "1.20", "1.20.1" -> VERSION1_20_1;
|
||||||
|
case "1.20.2" -> VERSION1_20_2;
|
||||||
|
case "1.20.4" -> VERSION1_20_4;
|
||||||
|
case "1.20.5", "1.20.6" -> VERSION1_20_5;
|
||||||
|
case "1.21", "1.21.1" -> VERSION1_21_1;
|
||||||
|
case "1.21.2", "1.21.3" -> VERSION1_21_3;
|
||||||
|
default -> VERSION1_21_3; // Current supported ver
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getPlatformType() {
|
public String getPlatformType() {
|
||||||
|
|||||||
@@ -142,18 +142,6 @@ public abstract class FabricSerializer {
|
|||||||
|
|
||||||
private interface ItemDeserializer {
|
private interface ItemDeserializer {
|
||||||
|
|
||||||
int VERSION1_16_5 = 2586;
|
|
||||||
int VERSION1_17_1 = 2730;
|
|
||||||
int VERSION1_18_2 = 2975;
|
|
||||||
int VERSION1_19_2 = 3120;
|
|
||||||
int VERSION1_19_4 = 3337;
|
|
||||||
int VERSION1_20_1 = 3465;
|
|
||||||
int VERSION1_20_2 = 3578;
|
|
||||||
int VERSION1_20_4 = 3700;
|
|
||||||
int VERSION1_20_5 = 3837;
|
|
||||||
int VERSION1_21_1 = 3955;
|
|
||||||
int VERSION1_21_3 = 4082; // Current
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
default ItemStack[] getItems(@NotNull NbtCompound tag, @NotNull Version mcVersion, @NotNull FabricHuskSync plugin) {
|
default ItemStack[] getItems(@NotNull NbtCompound tag, @NotNull Version mcVersion, @NotNull FabricHuskSync plugin) {
|
||||||
try {
|
try {
|
||||||
@@ -220,27 +208,10 @@ public abstract class FabricSerializer {
|
|||||||
@NotNull FabricHuskSync plugin) {
|
@NotNull FabricHuskSync plugin) {
|
||||||
return (NbtCompound) plugin.getMinecraftServer().getDataFixer().update(
|
return (NbtCompound) plugin.getMinecraftServer().getDataFixer().update(
|
||||||
TypeReferences.ITEM_STACK, new Dynamic<Object>((DynamicOps) NbtOps.INSTANCE, tag),
|
TypeReferences.ITEM_STACK, new Dynamic<Object>((DynamicOps) NbtOps.INSTANCE, tag),
|
||||||
getDataVersion(mcVersion), getDataVersion(plugin.getMinecraftVersion())
|
plugin.getDataVersion(mcVersion), plugin.getDataVersion(plugin.getMinecraftVersion())
|
||||||
).getValue();
|
).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getDataVersion(@NotNull Version mcVersion) {
|
|
||||||
return switch (mcVersion.toStringWithoutMetadata()) {
|
|
||||||
case "1.16", "1.16.1", "1.16.2", "1.16.3", "1.16.4", "1.16.5" -> VERSION1_16_5;
|
|
||||||
case "1.17", "1.17.1" -> VERSION1_17_1;
|
|
||||||
case "1.18", "1.18.1", "1.18.2" -> VERSION1_18_2;
|
|
||||||
case "1.19", "1.19.1", "1.19.2" -> VERSION1_19_2;
|
|
||||||
case "1.19.4" -> VERSION1_19_4;
|
|
||||||
case "1.20", "1.20.1" -> VERSION1_20_1;
|
|
||||||
case "1.20.2" -> VERSION1_20_2;
|
|
||||||
case "1.20.4" -> VERSION1_20_4;
|
|
||||||
case "1.20.5", "1.20.6" -> VERSION1_20_5;
|
|
||||||
case "1.21", "1.21.1" -> VERSION1_21_1;
|
|
||||||
case "1.21.2", "1.21.3" -> VERSION1_21_3;
|
|
||||||
default -> VERSION1_21_3; // Current supported ver
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PotionEffects extends FabricSerializer implements Serializer<FabricData.PotionEffects> {
|
public static class PotionEffects extends FabricSerializer implements Serializer<FabricData.PotionEffects> {
|
||||||
|
|||||||
Reference in New Issue
Block a user