mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Made player data less world independent but still world independent
This commit is contained in:
parent
79f18910f2
commit
0ca678dae1
2 changed files with 26 additions and 32 deletions
|
@ -13,13 +13,13 @@ package de.ellpeck.actuallyadditions.mod.data;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class PlayerData{
|
public final class PlayerData{
|
||||||
|
|
||||||
public static PlayerSave getDataFromPlayer(UUID id){
|
public static PlayerSave getDataFromPlayer(UUID id){
|
||||||
ArrayList<PlayerSave> data = WorldData.PLAYER_SAVE_DATA;
|
List<PlayerSave> data = WorldData.getWorldUnspecificData().playerSaveData;
|
||||||
//Get Data from existing data
|
//Get Data from existing data
|
||||||
for(PlayerSave save : data){
|
for(PlayerSave save : data){
|
||||||
if(save.theId != null && save.theId.equals(id)){
|
if(save.theId != null && save.theId.equals(id)){
|
||||||
|
|
|
@ -18,6 +18,7 @@ import io.netty.util.internal.ConcurrentSet;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.DimensionType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraft.world.storage.ISaveHandler;
|
import net.minecraft.world.storage.ISaveHandler;
|
||||||
|
@ -27,14 +28,15 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class WorldData{
|
public class WorldData{
|
||||||
|
|
||||||
public static final String DATA_TAG = ModUtil.MOD_ID+"data";
|
public static final String DATA_TAG = ModUtil.MOD_ID+"data";
|
||||||
public static final ArrayList<PlayerSave> PLAYER_SAVE_DATA = new ArrayList<PlayerSave>();
|
|
||||||
private static final ConcurrentHashMap<Integer, WorldData> WORLD_DATA = new ConcurrentHashMap<Integer, WorldData>();
|
private static final ConcurrentHashMap<Integer, WorldData> WORLD_DATA = new ConcurrentHashMap<Integer, WorldData>();
|
||||||
public final ConcurrentSet<Network> laserRelayNetworks = new ConcurrentSet<Network>();
|
public final ConcurrentSet<Network> laserRelayNetworks = new ConcurrentSet<Network>();
|
||||||
|
public final ArrayList<PlayerSave> playerSaveData = new ArrayList<PlayerSave>();
|
||||||
private final ISaveHandler handler;
|
private final ISaveHandler handler;
|
||||||
private final int dimension;
|
private final int dimension;
|
||||||
|
|
||||||
|
@ -43,20 +45,20 @@ public class WorldData{
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WorldData getWorldUnspecificData(){
|
||||||
|
return getDataForWorld(DimensionType.OVERWORLD.getId());
|
||||||
|
}
|
||||||
|
|
||||||
public static WorldData getDataForWorld(World world){
|
public static WorldData getDataForWorld(World world){
|
||||||
int dim = world.provider.getDimension();
|
return getDataForWorld(world.provider.getDimension());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorldData getDataForWorld(int dim){
|
||||||
WorldData data = WORLD_DATA.get(dim);
|
WorldData data = WORLD_DATA.get(dim);
|
||||||
|
|
||||||
if(data == null){
|
if(data == null){
|
||||||
data = new WorldData(null, dim);
|
data = new WorldData(null, dim);
|
||||||
|
WORLD_DATA.put(dim, data);
|
||||||
if(world.isRemote){
|
|
||||||
WORLD_DATA.put(dim, data);
|
|
||||||
ModUtil.LOGGER.info("Creating temporary WorldData for world "+dim+" on the client!");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
ModUtil.LOGGER.warn("Trying to get WorldData from world "+dim+" that doesn't have any data!? This shouldn't happen!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
@ -64,9 +66,6 @@ public class WorldData{
|
||||||
|
|
||||||
public static void load(World world){
|
public static void load(World world){
|
||||||
if(!world.isRemote && world instanceof WorldServer){
|
if(!world.isRemote && world instanceof WorldServer){
|
||||||
//Just to be sure it actually gets cleared all the time
|
|
||||||
PLAYER_SAVE_DATA.clear();
|
|
||||||
|
|
||||||
WorldData data = new WorldData(new WorldSpecificSaveHandler((WorldServer)world, world.getSaveHandler()), world.provider.getDimension());
|
WorldData data = new WorldData(new WorldSpecificSaveHandler((WorldServer)world, world.getSaveHandler()), world.provider.getDimension());
|
||||||
WORLD_DATA.put(data.dimension, data);
|
WORLD_DATA.put(data.dimension, data);
|
||||||
|
|
||||||
|
@ -117,7 +116,7 @@ public class WorldData{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ModUtil.LOGGER.error("Tried to save WorldData for "+world.provider.getDimension()+" without any data being present!?");
|
ModUtil.LOGGER.error("Tried to save WorldData for "+world.provider.getDimension()+" without any data handler being present!?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,15 +138,12 @@ public class WorldData{
|
||||||
this.laserRelayNetworks.add(network);
|
this.laserRelayNetworks.add(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.dimension == 0){
|
//Player Data
|
||||||
//Player Data
|
this.playerSaveData.clear();
|
||||||
PLAYER_SAVE_DATA.clear();
|
NBTTagList playerList = compound.getTagList("PlayerData", 10);
|
||||||
|
for(int i = 0; i < playerList.tagCount(); i++){
|
||||||
NBTTagList playerList = compound.getTagList("PlayerData", 10);
|
PlayerSave aSave = PlayerSave.fromNBT(playerList.getCompoundTagAt(i));
|
||||||
for(int i = 0; i < playerList.tagCount(); i++){
|
this.playerSaveData.add(aSave);
|
||||||
PlayerSave aSave = PlayerSave.fromNBT(playerList.getCompoundTagAt(i));
|
|
||||||
PLAYER_SAVE_DATA.add(aSave);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,13 +155,11 @@ public class WorldData{
|
||||||
}
|
}
|
||||||
compound.setTag("Networks", networkList);
|
compound.setTag("Networks", networkList);
|
||||||
|
|
||||||
if(this.dimension == 0){
|
//Player Data
|
||||||
//Player Data
|
NBTTagList playerList = new NBTTagList();
|
||||||
NBTTagList playerList = new NBTTagList();
|
for(PlayerSave theSave : this.playerSaveData){
|
||||||
for(PlayerSave theSave : PLAYER_SAVE_DATA){
|
playerList.appendTag(theSave.toNBT());
|
||||||
playerList.appendTag(theSave.toNBT());
|
|
||||||
}
|
|
||||||
compound.setTag("PlayerData", playerList);
|
|
||||||
}
|
}
|
||||||
|
compound.setTag("PlayerData", playerList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue