If the lasers still disconnect on their own now I'm gonna jump out of the window

This commit is contained in:
Ellpeck 2015-11-15 13:13:58 +01:00
parent 8409d10f74
commit eae2d1d288
6 changed files with 28 additions and 25 deletions

View file

@ -43,7 +43,6 @@ import ellpeck.actuallyadditions.tile.TileEntityBase;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util;
import ellpeck.actuallyadditions.util.playerdata.PersistentServerData;
import net.minecraft.init.Items;
import net.minecraft.server.MinecraftServer;
@ -129,10 +128,4 @@ public class ActuallyAdditions{
WorldData.init(MinecraftServer.getServer());
}
@EventHandler
public void serverStopped(FMLServerStoppedEvent event){
//Clear Data so that it won't be carried over to other worlds
PersistentServerData.playerSaveData.clear();
}
}

View file

@ -36,7 +36,7 @@ public class CraftEvent{
NBTTagCompound compound = PersistentServerData.getDataFromPlayer(event.player);
if(compound != null && !compound.getBoolean("BookGottenAlready")){
compound.setBoolean("BookGottenAlready", true);
WorldData.makeDirty();
WorldData.makeDirty(false);
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemLexicon));
entityItem.delayBeforeCanPickup = 0;

View file

@ -26,12 +26,11 @@ public class WorldLoadingEvents{
@SubscribeEvent
public void onUnload(WorldEvent.Unload event){
//Clear Data so that it won't be carried over to other worlds
LaserRelayConnectionHandler.getInstance().networks.clear();
WorldData.makeDirty(true);
}
@SubscribeEvent
public void onSave(WorldEvent.Save event){
WorldData.makeDirty();
WorldData.makeDirty(false);
}
}

View file

@ -87,7 +87,7 @@ public class LaserRelayConnectionHandler{
}
//System.out.println("Removing a Relay from the Network!");
}
WorldData.makeDirty();
WorldData.makeDirty(false);
}
/**
@ -140,7 +140,7 @@ public class LaserRelayConnectionHandler{
else if(secondNetwork != null){
secondNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
}
WorldData.makeDirty();
WorldData.makeDirty(false);
//System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
//System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());
//System.out.println(this.networks);
@ -156,7 +156,7 @@ public class LaserRelayConnectionHandler{
firstNetwork.connections.add(secondPair);
}
this.networks.remove(secondNetwork);
WorldData.makeDirty();
WorldData.makeDirty(false);
//System.out.println("Merged Two Networks!");
}

View file

@ -23,13 +23,16 @@ public class WorldData extends WorldSavedData{
public static final String DATA_TAG = ModUtil.MOD_ID+"WorldData";
public static WorldData instance;
public boolean shouldClearAfterSave;
public WorldData(String tag){
super(tag);
}
public static void makeDirty(){
public static void makeDirty(boolean shouldClearAfterSave){
if(instance != null){
instance.markDirty();
instance.shouldClearAfterSave = shouldClearAfterSave;
}
}
@ -90,5 +93,13 @@ public class WorldData extends WorldSavedData{
playerList.appendTag(theSave.toNBT());
}
compound.setTag("PlayerData", playerList);
if(this.shouldClearAfterSave){
ModUtil.LOGGER.info("Clearing WorldData after saving! (Probably because the world is getting unloaded)");
this.shouldClearAfterSave = false;
PersistentServerData.playerSaveData.clear();
LaserRelayConnectionHandler.getInstance().networks.clear();
}
}
}

View file

@ -87,19 +87,19 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt){
if(pkt != null){
NBTTagCompound compound = pkt.func_148857_g();
WorldPos thisPos = new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
if(pkt != null && pkt.func_148857_g() != null){
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(thisPos);
if(compound != null){
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
NBTTagList list = compound.getTagList("Connections", 10);
for(int i = 0; i < list.tagCount(); i++){
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
}
NBTTagList list = pkt.func_148857_g().getTagList("Connections", 10);
for(int i = 0; i < list.tagCount(); i++){
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
}
}
else{
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(thisPos);
}
}
@Override