Merge branch '1.20.1' into 1.20.1
This commit is contained in:
commit
5d1a166dcf
|
|
@ -3,4 +3,4 @@
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
mod_version=1.20.1-1.3.4
|
mod_version=1.20.1-1.3.5
|
||||||
|
|
@ -130,11 +130,13 @@ public class PlayerSync {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create backpack_data table
|
// Create backpack_data table
|
||||||
JDBCsetUp.executeUpdate(
|
if(ModList.get().isLoaded("sophisticatedbackpacks")){
|
||||||
"CREATE TABLE IF NOT EXISTS " + dbName + ".backpack_data (" +
|
JDBCsetUp.executeUpdate(
|
||||||
"uuid CHAR(36) NOT NULL, backpack_nbt MEDIUMBLOB, PRIMARY KEY (uuid)" +
|
"CREATE TABLE IF NOT EXISTS " + dbName + ".backpack_data (" +
|
||||||
");", 1
|
"uuid CHAR(36) NOT NULL, backpack_nbt MEDIUMBLOB, PRIMARY KEY (uuid)" +
|
||||||
);
|
");", 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ----- NEW BLOCK: Schema Update for backpack_data and player_data -----
|
// ----- NEW BLOCK: Schema Update for backpack_data and player_data -----
|
||||||
// Check if backpack_data table has the 'uuid' column
|
// Check if backpack_data table has the 'uuid' column
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import vip.fubuki.playersync.PlayerSync;
|
||||||
import vip.fubuki.playersync.util.JDBCsetUp;
|
import vip.fubuki.playersync.util.JDBCsetUp;
|
||||||
import vip.fubuki.playersync.util.LocalJsonUtil;
|
import vip.fubuki.playersync.util.LocalJsonUtil;
|
||||||
|
|
||||||
|
|
@ -13,10 +14,16 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import top.theillusivec4.curios.api.CuriosApi;
|
import top.theillusivec4.curios.api.CuriosApi;
|
||||||
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
|
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
|
||||||
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
||||||
import top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler;
|
import top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static vip.fubuki.playersync.sync.VanillaSync.deserializeString;
|
||||||
|
|
||||||
|
|
||||||
public class ModsSupport {
|
public class ModsSupport {
|
||||||
|
|
||||||
|
|
@ -90,6 +97,42 @@ public class ModsSupport {
|
||||||
StoreCurios(player, true);
|
StoreCurios(player, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(ModList.get().isLoaded("sophisticatedbackpacks")){
|
||||||
|
// --- Begin Backpack Data Restore ---
|
||||||
|
PlayerSync.LOGGER.info("Restoring backpack data for player " + player.getUUID());
|
||||||
|
net.p3pp3rf1y.sophisticatedbackpacks.util.PlayerInventoryProvider.get().runOnBackpacks(player, (ItemStack backpackItem, String handler, String identifier, int slot) -> {
|
||||||
|
backpackItem.getCapability(net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper.getCapabilityInstance())
|
||||||
|
.ifPresent(wrapper -> {
|
||||||
|
// Retrieve the contents UUID from the backpack's NBT using NBTHelper
|
||||||
|
Optional<UUID> uuidOpt = net.p3pp3rf1y.sophisticatedcore.util.NBTHelper.getUniqueId(wrapper.getBackpack(), "contentsUuid");
|
||||||
|
if (uuidOpt.isPresent()) {
|
||||||
|
UUID contentsUuid = uuidOpt.get();
|
||||||
|
try {
|
||||||
|
JDBCsetUp.QueryResult qrBackpack = JDBCsetUp.executeQuery("SELECT backpack_nbt FROM backpack_data WHERE uuid='" + contentsUuid.toString() + "'");
|
||||||
|
ResultSet rsBackpack = qrBackpack.resultSet();
|
||||||
|
if (rsBackpack.next()) {
|
||||||
|
String serialized = rsBackpack.getString("backpack_nbt");
|
||||||
|
String nbtString = deserializeString(serialized);
|
||||||
|
CompoundTag backpackNbt = NbtUtils.snbtToStructure(nbtString);
|
||||||
|
// Update BackpackStorage with the retrieved NBT
|
||||||
|
net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackStorage.get().setBackpackContents(contentsUuid, backpackNbt);
|
||||||
|
PlayerSync.LOGGER.info("Restored backpack data for UUID " + contentsUuid);
|
||||||
|
}
|
||||||
|
rsBackpack.close();
|
||||||
|
qrBackpack.connection().close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
PlayerSync.LOGGER.error("Error restoring backpack data for UUID " + contentsUuid, e);
|
||||||
|
} catch (CommandSyntaxException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PlayerSync.LOGGER.warn("Backpack item in slot " + slot + " has no contentsUuid during restore");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
// --- End Backpack Data Restore ---
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -167,41 +167,6 @@ public class VanillaSync {
|
||||||
modsSupport.onPlayerJoin(serverPlayer);
|
modsSupport.onPlayerJoin(serverPlayer);
|
||||||
serverPlayer.addTag("player_synced");
|
serverPlayer.addTag("player_synced");
|
||||||
|
|
||||||
// --- Begin Backpack Data Restore ---
|
|
||||||
PlayerSync.LOGGER.info("Restoring backpack data for player " + player_uuid);
|
|
||||||
net.p3pp3rf1y.sophisticatedbackpacks.util.PlayerInventoryProvider.get().runOnBackpacks(serverPlayer, (ItemStack backpackItem, String handler, String identifier, int slot) -> {
|
|
||||||
backpackItem.getCapability(net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper.getCapabilityInstance())
|
|
||||||
.ifPresent(wrapper -> {
|
|
||||||
// Retrieve the contents UUID from the backpack's NBT using NBTHelper
|
|
||||||
Optional<UUID> uuidOpt = net.p3pp3rf1y.sophisticatedcore.util.NBTHelper.getUniqueId(wrapper.getBackpack(), "contentsUuid");
|
|
||||||
if (uuidOpt.isPresent()) {
|
|
||||||
UUID contentsUuid = uuidOpt.get();
|
|
||||||
try {
|
|
||||||
JDBCsetUp.QueryResult qrBackpack = JDBCsetUp.executeQuery("SELECT backpack_nbt FROM backpack_data WHERE uuid='" + contentsUuid.toString() + "'");
|
|
||||||
ResultSet rsBackpack = qrBackpack.resultSet();
|
|
||||||
if (rsBackpack.next()) {
|
|
||||||
String serialized = rsBackpack.getString("backpack_nbt");
|
|
||||||
String nbtString = deserializeString(serialized);
|
|
||||||
CompoundTag backpackNbt = NbtUtils.snbtToStructure(nbtString);
|
|
||||||
// Update BackpackStorage with the retrieved NBT
|
|
||||||
net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackStorage.get().setBackpackContents(contentsUuid, backpackNbt);
|
|
||||||
PlayerSync.LOGGER.info("Restored backpack data for UUID " + contentsUuid);
|
|
||||||
}
|
|
||||||
rsBackpack.close();
|
|
||||||
qrBackpack.connection().close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
PlayerSync.LOGGER.error("Error restoring backpack data for UUID " + contentsUuid, e);
|
|
||||||
} catch (CommandSyntaxException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
PlayerSync.LOGGER.warn("Backpack item in slot " + slot + " has no contentsUuid during restore");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
// --- End Backpack Data Restore ---
|
|
||||||
|
|
||||||
rs2.close();
|
rs2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user