mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Changed world data save system in hope that laser relays will disconnect less often
This commit is contained in:
parent
596d2d0175
commit
bec7252405
8 changed files with 28 additions and 55 deletions
|
@ -127,11 +127,6 @@ public class ActuallyAdditions{
|
|||
FakePlayerUtil.info();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent event){
|
||||
WorldData.init(event.getServer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void missingMapping(FMLMissingMappingsEvent event){
|
||||
for(FMLMissingMappingsEvent.MissingMapping mapping : event.getAll()){
|
||||
|
|
|
@ -87,7 +87,7 @@ public class EntityLivingEvents{
|
|||
data.setTag("Deaths", deaths);
|
||||
|
||||
//player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded"));
|
||||
WorldData.makeDirty();
|
||||
WorldData.get(((EntityPlayer)event.getEntityLiving()).worldObj).markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public class PlayerObtainEvents{
|
|||
NBTTagCompound compound = PlayerServerData.getDataFromPlayer(event.player);
|
||||
if(compound != null && !compound.getBoolean("BookGottenAlready")){
|
||||
compound.setBoolean("BookGottenAlready", true);
|
||||
WorldData.makeDirty();
|
||||
WorldData.get(event.player.worldObj).markDirty();
|
||||
|
||||
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
|
||||
entityItem.setPickupDelay(0);
|
||||
|
|
|
@ -19,17 +19,17 @@ public class WorldLoadingEvents{
|
|||
|
||||
@SubscribeEvent
|
||||
public void onLoad(WorldEvent.Load event){
|
||||
WorldData.makeDirty();
|
||||
if(!event.getWorld().isRemote){
|
||||
WorldData.get(event.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onUnload(WorldEvent.Unload event){
|
||||
WorldData.makeDirty();
|
||||
if(!event.getWorld().isRemote){
|
||||
WorldData.get(event.getWorld()).markDirty();
|
||||
FakePlayerUtil.unloadFakePlayer();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSave(WorldEvent.Save event){
|
||||
WorldData.makeDirty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.items;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
|
@ -59,6 +60,8 @@ public class ItemLaserWrench extends ItemBase{
|
|||
((TileEntityLaserRelay)world.getTileEntity(savedPos)).sendUpdate();
|
||||
((TileEntityLaserRelay)world.getTileEntity(pos)).sendUpdate();
|
||||
|
||||
WorldData.get(world).markDirty();
|
||||
|
||||
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -82,7 +82,6 @@ public class LaserRelayConnectionHandler{
|
|||
}
|
||||
//System.out.println("Removing a Relay from the Network!");
|
||||
}
|
||||
WorldData.makeDirty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,7 +134,6 @@ public class LaserRelayConnectionHandler{
|
|||
else{
|
||||
secondNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||
}
|
||||
WorldData.makeDirty();
|
||||
//System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
|
||||
//System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());
|
||||
//System.out.println(this.networks);
|
||||
|
@ -151,7 +149,6 @@ public class LaserRelayConnectionHandler{
|
|||
firstNetwork.connections.add(secondPair);
|
||||
}
|
||||
this.networks.remove(secondNetwork);
|
||||
WorldData.makeDirty();
|
||||
//System.out.println("Merged Two Networks!");
|
||||
}
|
||||
|
||||
|
|
|
@ -14,64 +14,38 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|||
import de.ellpeck.actuallyadditions.mod.util.playerdata.PlayerServerData;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
public class WorldData extends WorldSavedData{
|
||||
|
||||
public static final String DATA_TAG = ModUtil.MOD_ID+"worlddata";
|
||||
private static WorldData instance;
|
||||
|
||||
public WorldData(String tag){
|
||||
super(tag);
|
||||
}
|
||||
|
||||
public static void makeDirty(){
|
||||
if(instance != null){
|
||||
instance.markDirty();
|
||||
}
|
||||
public static WorldData get(World world){
|
||||
if(world.getMapStorage() != null){
|
||||
WorldData data = (WorldData)world.getMapStorage().getOrLoadData(WorldData.class, DATA_TAG);
|
||||
if(data == null){
|
||||
data = new WorldData(DATA_TAG);
|
||||
data.markDirty();
|
||||
world.getMapStorage().setData(DATA_TAG, data);
|
||||
}
|
||||
|
||||
public static void init(MinecraftServer server){
|
||||
if(server != null){
|
||||
World world = server.getEntityWorld();
|
||||
if(!world.isRemote){
|
||||
clearOldData();
|
||||
ModUtil.LOGGER.info("Loading WorldData!");
|
||||
|
||||
WorldData savedData = (WorldData)world.loadItemData(WorldData.class, DATA_TAG);
|
||||
//Generate new SavedData
|
||||
if(savedData == null){
|
||||
ModUtil.LOGGER.info("No WorldData found, creating...");
|
||||
|
||||
savedData = new WorldData(DATA_TAG);
|
||||
world.setItemData(DATA_TAG, savedData);
|
||||
return data;
|
||||
}
|
||||
else{
|
||||
ModUtil.LOGGER.info("WorldData sucessfully received!");
|
||||
}
|
||||
|
||||
//Set the current SavedData to the retreived one
|
||||
WorldData.instance = savedData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearOldData(){
|
||||
if(!LaserRelayConnectionHandler.getInstance().networks.isEmpty()){
|
||||
ModUtil.LOGGER.info("Clearing leftover Laser Relay Connection Data from other worlds!");
|
||||
LaserRelayConnectionHandler.getInstance().networks.clear();
|
||||
}
|
||||
if(!PlayerServerData.playerSaveData.isEmpty()){
|
||||
ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!");
|
||||
PlayerServerData.playerSaveData.clear();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
//Laser World Data
|
||||
LaserRelayConnectionHandler.getInstance().networks.clear();
|
||||
|
||||
NBTTagList networkList = compound.getTagList("Networks", 10);
|
||||
for(int i = 0; i < networkList.tagCount(); i++){
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().readNetworkFromNBT(networkList.getCompoundTagAt(i));
|
||||
|
@ -79,6 +53,8 @@ public class WorldData extends WorldSavedData{
|
|||
}
|
||||
|
||||
//Player Data
|
||||
PlayerServerData.playerSaveData.clear();
|
||||
|
||||
NBTTagList playerList = compound.getTagList("PlayerData", 10);
|
||||
for(int i = 0; i < playerList.tagCount(); i++){
|
||||
PlayerServerData.PlayerSave aSave = PlayerServerData.PlayerSave.fromNBT(playerList.getCompoundTagAt(i));
|
||||
|
|
|
@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketParticle;
|
||||
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
|
@ -99,6 +100,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
public void invalidate(){
|
||||
super.invalidate();
|
||||
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(this.pos);
|
||||
WorldData.get(this.worldObj).markDirty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue