diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index 6902745dd..6d6f393a7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -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()){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/EntityLivingEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/EntityLivingEvents.java index ee1ab2bc4..db81ba522 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/EntityLivingEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/EntityLivingEvents.java @@ -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(); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/PlayerObtainEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/PlayerObtainEvents.java index f6fc2871f..6bdc36f6f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/PlayerObtainEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/PlayerObtainEvents.java @@ -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); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java index 472f3fe10..1d6ad85ed 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java @@ -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(); - FakePlayerUtil.unloadFakePlayer(); + if(!event.getWorld().isRemote){ + WorldData.get(event.getWorld()).markDirty(); + FakePlayerUtil.unloadFakePlayer(); + } } - @SubscribeEvent - public void onSave(WorldEvent.Save event){ - WorldData.makeDirty(); - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java index 944c0cf56..5deee458f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java @@ -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{ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java index c8100301b..6b48ad426 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java @@ -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!"); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java index 10ef6f7f9..b9b016a55 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/WorldData.java @@ -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 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); - } - else{ - ModUtil.LOGGER.info("WorldData sucessfully received!"); - } - - //Set the current SavedData to the retreived one - WorldData.instance = savedData; + 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 clearOldData(){ - if(!LaserRelayConnectionHandler.getInstance().networks.isEmpty()){ - ModUtil.LOGGER.info("Clearing leftover Laser Relay Connection Data from other worlds!"); - LaserRelayConnectionHandler.getInstance().networks.clear(); + return data; } - if(!PlayerServerData.playerSaveData.isEmpty()){ - ModUtil.LOGGER.info("Clearing leftover Persistent Server Data from other worlds!"); - PlayerServerData.playerSaveData.clear(); + else{ + 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)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index bca485f01..b741e0f57 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -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(); } }