mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Added custom system to save world data because the MC one was always failing on me
This commit is contained in:
parent
7e682af51d
commit
ec07b3da02
14 changed files with 209 additions and 156 deletions
|
@ -28,7 +28,7 @@ import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
|
|||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.playerdata.ExtraClientData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.ExtraClientData;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* © 2015-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.util.playerdata;
|
||||
package de.ellpeck.actuallyadditions.mod.data;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
|
|
@ -8,7 +8,7 @@
|
|||
* © 2015-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.util.playerdata;
|
||||
package de.ellpeck.actuallyadditions.mod.data;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -18,11 +18,10 @@ import java.util.UUID;
|
|||
|
||||
public class PlayerServerData{
|
||||
|
||||
public static final ArrayList<PlayerSave> playerSaveData = new ArrayList<PlayerSave>();
|
||||
|
||||
public static NBTTagCompound getDataFromPlayer(EntityPlayer player){
|
||||
ArrayList<PlayerSave> data = WorldData.getDataForWorld(player.worldObj.provider.getDimension()).PLAYER_SAVE_DATA;
|
||||
//Get Data from existing data
|
||||
for(PlayerSave save : playerSaveData){
|
||||
for(PlayerSave save : data){
|
||||
if(save.thePlayerUUID.equals(player.getUniqueID())){
|
||||
return save.theCompound;
|
||||
}
|
||||
|
@ -30,7 +29,7 @@ public class PlayerServerData{
|
|||
|
||||
//Add Data if none is existant
|
||||
PlayerSave aSave = new PlayerSave(player.getUniqueID(), new NBTTagCompound());
|
||||
playerSaveData.add(aSave);
|
||||
data.add(aSave);
|
||||
return aSave.theCompound;
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* This file ("WorldData.java") is part of the Actually Additions mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://ellpeck.de/actaddlicense
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.data;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerServerData.PlayerSave;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.Network;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.storage.ISaveHandler;
|
||||
import net.minecraftforge.common.WorldSpecificSaveHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class WorldData{
|
||||
|
||||
public static final String DATA_TAG = ModUtil.MOD_ID+"data";
|
||||
private static Map<Integer, WorldData> worldData = new ConcurrentHashMap<Integer, WorldData>();
|
||||
|
||||
private ISaveHandler handler;
|
||||
private int dimension;
|
||||
|
||||
public final ConcurrentSet<Network> laserRelayNetworks = new ConcurrentSet<Network>();
|
||||
public static final ArrayList<PlayerSave> PLAYER_SAVE_DATA = new ArrayList<PlayerSave>();
|
||||
|
||||
public WorldData(ISaveHandler handler, int dimension){
|
||||
this.handler = handler;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public static WorldData getDataForWorld(int world){
|
||||
return worldData.get(world);
|
||||
}
|
||||
|
||||
private void readFromNBT(NBTTagCompound compound){
|
||||
//Laser World Data
|
||||
NBTTagList networkList = compound.getTagList("Networks", 10);
|
||||
for(int i = 0; i < networkList.tagCount(); i++){
|
||||
Network network = LaserRelayConnectionHandler.readNetworkFromNBT(networkList.getCompoundTagAt(i));
|
||||
this.laserRelayNetworks.add(network);
|
||||
}
|
||||
|
||||
if(this.dimension == 0){
|
||||
//Player Data
|
||||
PLAYER_SAVE_DATA.clear();
|
||||
|
||||
NBTTagList playerList = compound.getTagList("PlayerData", 10);
|
||||
for(int i = 0; i < playerList.tagCount(); i++){
|
||||
PlayerSave aSave = PlayerSave.fromNBT(playerList.getCompoundTagAt(i));
|
||||
PLAYER_SAVE_DATA.add(aSave);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeToNBT(NBTTagCompound compound){
|
||||
//Laser World Data
|
||||
NBTTagList networkList = new NBTTagList();
|
||||
for(Network network : this.laserRelayNetworks){
|
||||
networkList.appendTag(LaserRelayConnectionHandler.writeNetworkToNBT(network));
|
||||
}
|
||||
compound.setTag("Networks", networkList);
|
||||
|
||||
if(this.dimension == 0){
|
||||
//Player Data
|
||||
NBTTagList playerList = new NBTTagList();
|
||||
for(PlayerSave theSave : PLAYER_SAVE_DATA){
|
||||
playerList.appendTag(theSave.toNBT());
|
||||
}
|
||||
compound.setTag("PlayerData", playerList);
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(World world){
|
||||
if(!world.isRemote && world instanceof WorldServer){
|
||||
WorldData data = new WorldData(new WorldSpecificSaveHandler((WorldServer)world, world.getSaveHandler()), world.provider.getDimension());
|
||||
worldData.put(data.dimension, data);
|
||||
|
||||
try{
|
||||
File dataFile = data.handler.getMapFileFromName(DATA_TAG+data.dimension);
|
||||
|
||||
if(dataFile != null && dataFile.exists()){
|
||||
FileInputStream stream = new FileInputStream(dataFile);
|
||||
NBTTagCompound compound = CompressedStreamTools.readCompressed(stream);
|
||||
stream.close();
|
||||
data.readFromNBT(compound);
|
||||
|
||||
ModUtil.LOGGER.info("Successfully received WorldData for world "+data.dimension+"!");
|
||||
}
|
||||
else{
|
||||
ModUtil.LOGGER.info("No WorldData found for world "+data.dimension+", creating...");
|
||||
}
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
ModUtil.LOGGER.error("Something went wrong trying to load WorldData for world "+data.dimension+"!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(World world){
|
||||
if(!world.isRemote){
|
||||
WorldData data = worldData.get(world.provider.getDimension());
|
||||
if(data != null && data.handler != null){
|
||||
try{
|
||||
File dataFile = data.handler.getMapFileFromName(DATA_TAG+data.dimension);
|
||||
|
||||
if(dataFile != null){
|
||||
if(!dataFile.exists()){
|
||||
dataFile.createNewFile();
|
||||
ModUtil.LOGGER.info("Creating new WorldData file for world!");
|
||||
}
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
data.writeToNBT(compound);
|
||||
FileOutputStream stream = new FileOutputStream(dataFile);
|
||||
CompressedStreamTools.writeCompressed(compound, stream);
|
||||
stream.close();
|
||||
|
||||
ModUtil.LOGGER.info("Saved WorldData for world "+data.dimension+"!");
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
ModUtil.LOGGER.error("Something went wrong trying to save WorldData for world "+data.dimension+"!", e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
ModUtil.LOGGER.error("Tried to save WorldData without any data being present!?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void unload(World world){
|
||||
if(!world.isRemote){
|
||||
save(world);
|
||||
int dim = world.provider.getDimension();
|
||||
worldData.remove(dim);
|
||||
ModUtil.LOGGER.info("Unloading WorldData for world "+dim+"!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,10 +14,10 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
|||
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
|
||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.playerdata.PlayerServerData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerServerData;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -87,7 +87,6 @@ public class EntityLivingEvents{
|
|||
data.setTag("Deaths", deaths);
|
||||
|
||||
//player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded"));
|
||||
WorldData.markDirty(event.getEntityLiving().getEntityWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
|
|||
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
|
||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
||||
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.playerdata.PlayerServerData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerServerData;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -52,7 +52,6 @@ public class PlayerObtainEvents{
|
|||
NBTTagCompound compound = PlayerServerData.getDataFromPlayer(event.player);
|
||||
if(compound != null && !compound.getBoolean("BookGottenAlready")){
|
||||
compound.setBoolean("BookGottenAlready", true);
|
||||
WorldData.markDirty(event.player.worldObj);
|
||||
|
||||
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
|
||||
entityItem.setPickupDelay(0);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.event;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.util.FakePlayerUtil;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
@ -20,16 +20,23 @@ public class WorldLoadingEvents{
|
|||
@SubscribeEvent
|
||||
public void onLoad(WorldEvent.Load event){
|
||||
if(!event.getWorld().isRemote){
|
||||
WorldData.loadOrGet(event.getWorld());
|
||||
WorldData.load(event.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onUnload(WorldEvent.Unload event){
|
||||
if(!event.getWorld().isRemote){
|
||||
WorldData.markDirty(event.getWorld());
|
||||
WorldData.unload(event.getWorld());
|
||||
FakePlayerUtil.unloadFakePlayer();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSave(WorldEvent.Save event){
|
||||
if(!event.getWorld().isRemote){
|
||||
WorldData.save(event.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +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.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
|
@ -54,14 +54,12 @@ public class ItemLaserWrench extends ItemBase{
|
|||
BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
|
||||
if(savedPos != null){
|
||||
TileEntity savedTile = world.getTileEntity(savedPos);
|
||||
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).isItem == ((TileEntityLaserRelay)tile).isItem && LaserRelayConnectionHandler.getInstance().addConnection(savedPos, pos)){
|
||||
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).isItem == ((TileEntityLaserRelay)tile).isItem && LaserRelayConnectionHandler.addConnection(savedPos, pos, world.provider.getDimension())){
|
||||
ItemPhantomConnector.clearStorage(stack);
|
||||
|
||||
((TileEntityLaserRelay)world.getTileEntity(savedPos)).sendUpdate();
|
||||
((TileEntityLaserRelay)world.getTileEntity(pos)).sendUpdate();
|
||||
|
||||
WorldData.markDirty(world);
|
||||
|
||||
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.misc;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.data.WorldData;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
||||
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
|
@ -19,21 +20,7 @@ import net.minecraft.util.math.BlockPos;
|
|||
|
||||
public class LaserRelayConnectionHandler{
|
||||
|
||||
private static LaserRelayConnectionHandler instance;
|
||||
|
||||
/**
|
||||
* All of the Networks
|
||||
*/
|
||||
public final ConcurrentSet<Network> networks = new ConcurrentSet<Network>();
|
||||
|
||||
public static LaserRelayConnectionHandler getInstance(){
|
||||
if(instance == null){
|
||||
instance = new LaserRelayConnectionHandler();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeNetworkToNBT(Network network){
|
||||
public static NBTTagCompound writeNetworkToNBT(Network network){
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(ConnectionPair pair : network.connections){
|
||||
list.appendTag(pair.writeToNBT());
|
||||
|
@ -43,7 +30,7 @@ public class LaserRelayConnectionHandler{
|
|||
return compound;
|
||||
}
|
||||
|
||||
public Network readNetworkFromNBT(NBTTagCompound tag){
|
||||
public static Network readNetworkFromNBT(NBTTagCompound tag){
|
||||
NBTTagList list = tag.getTagList("Network", 10);
|
||||
Network network = new Network();
|
||||
for(int i = 0; i < list.tagCount(); i++){
|
||||
|
@ -55,9 +42,9 @@ public class LaserRelayConnectionHandler{
|
|||
/**
|
||||
* Gets all Connections for a Relay
|
||||
*/
|
||||
public ConcurrentSet<ConnectionPair> getConnectionsFor(BlockPos relay){
|
||||
public static ConcurrentSet<ConnectionPair> getConnectionsFor(BlockPos relay, int world){
|
||||
ConcurrentSet<ConnectionPair> allPairs = new ConcurrentSet<ConnectionPair>();
|
||||
for(Network aNetwork : this.networks){
|
||||
for(Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks){
|
||||
for(ConnectionPair pair : aNetwork.connections){
|
||||
if(pair.contains(relay)){
|
||||
allPairs.add(pair);
|
||||
|
@ -70,14 +57,14 @@ public class LaserRelayConnectionHandler{
|
|||
/**
|
||||
* Removes a Relay from its Network
|
||||
*/
|
||||
public void removeRelayFromNetwork(BlockPos relay){
|
||||
Network network = this.getNetworkFor(relay);
|
||||
public static void removeRelayFromNetwork(BlockPos relay, int world){
|
||||
Network network = getNetworkFor(relay, world);
|
||||
if(network != null){
|
||||
//Setup new network (so that splitting a network will cause it to break into two)
|
||||
this.networks.remove(network);
|
||||
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
|
||||
for(ConnectionPair pair : network.connections){
|
||||
if(!pair.contains(relay)){
|
||||
this.addConnection(pair.firstRelay, pair.secondRelay);
|
||||
addConnection(pair.firstRelay, pair.secondRelay, world);
|
||||
}
|
||||
}
|
||||
//System.out.println("Removing a Relay from the Network!");
|
||||
|
@ -87,8 +74,8 @@ public class LaserRelayConnectionHandler{
|
|||
/**
|
||||
* Gets a Network for a Relay
|
||||
*/
|
||||
public Network getNetworkFor(BlockPos relay){
|
||||
for(Network aNetwork : this.networks){
|
||||
public static Network getNetworkFor(BlockPos relay, int world){
|
||||
for(Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks){
|
||||
for(ConnectionPair pair : aNetwork.connections){
|
||||
if(pair.contains(relay)){
|
||||
return aNetwork;
|
||||
|
@ -102,28 +89,28 @@ public class LaserRelayConnectionHandler{
|
|||
* Adds a new connection between two relays
|
||||
* (Puts it into the correct network!)
|
||||
*/
|
||||
public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay){
|
||||
public static boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, int world){
|
||||
int distance = (int)PosUtil.toVec(firstRelay).distanceTo(PosUtil.toVec(secondRelay));
|
||||
if(distance > TileEntityLaserRelay.MAX_DISTANCE || PosUtil.areSamePos(firstRelay, secondRelay)){
|
||||
return false;
|
||||
}
|
||||
|
||||
Network firstNetwork = this.getNetworkFor(firstRelay);
|
||||
Network secondNetwork = this.getNetworkFor(secondRelay);
|
||||
Network firstNetwork = getNetworkFor(firstRelay, world);
|
||||
Network secondNetwork = getNetworkFor(secondRelay, world);
|
||||
|
||||
//No Network exists
|
||||
if(firstNetwork == null && secondNetwork == null){
|
||||
firstNetwork = new Network();
|
||||
this.networks.add(firstNetwork);
|
||||
WorldData.getDataForWorld(world).laserRelayNetworks.add(firstNetwork);
|
||||
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||
}
|
||||
//The same Network
|
||||
else if(firstNetwork == secondNetwork){
|
||||
return false;
|
||||
}
|
||||
//Both relays have networks
|
||||
//Both relays have laserRelayNetworks
|
||||
else if(firstNetwork != null && secondNetwork != null){
|
||||
this.mergeNetworks(firstNetwork, secondNetwork);
|
||||
mergeNetworks(firstNetwork, secondNetwork, world);
|
||||
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay));
|
||||
}
|
||||
//Only first network exists
|
||||
|
@ -136,19 +123,19 @@ public class LaserRelayConnectionHandler{
|
|||
}
|
||||
//System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
|
||||
//System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());
|
||||
//System.out.println(this.networks);
|
||||
//System.out.println(laserRelayNetworks);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two networks together
|
||||
* Merges two laserRelayNetworks together
|
||||
* (Actually puts everything from the second network into the first one and removes the second one)
|
||||
*/
|
||||
public void mergeNetworks(Network firstNetwork, Network secondNetwork){
|
||||
public static void mergeNetworks(Network firstNetwork, Network secondNetwork, int world){
|
||||
for(ConnectionPair secondPair : secondNetwork.connections){
|
||||
firstNetwork.connections.add(secondPair);
|
||||
}
|
||||
this.networks.remove(secondNetwork);
|
||||
WorldData.getDataForWorld(world).laserRelayNetworks.remove(secondNetwork);
|
||||
//System.out.println("Merged Two Networks!");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* This file ("WorldData.java") is part of the Actually Additions mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://ellpeck.de/actaddlicense
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015-2016 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.misc;
|
||||
|
||||
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.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
public class WorldData extends WorldSavedData{
|
||||
|
||||
public static final String DATA_TAG = ModUtil.MOD_ID+"worlddata";
|
||||
|
||||
public WorldData(String tag){
|
||||
super(tag);
|
||||
}
|
||||
|
||||
public static WorldData loadOrGet(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);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void markDirty(World world){
|
||||
WorldData data = loadOrGet(world);
|
||||
if(data != null){
|
||||
data.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@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));
|
||||
LaserRelayConnectionHandler.getInstance().networks.add(network);
|
||||
}
|
||||
|
||||
//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));
|
||||
PlayerServerData.playerSaveData.add(aSave);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound){
|
||||
//Laser World Data
|
||||
NBTTagList networkList = new NBTTagList();
|
||||
for(LaserRelayConnectionHandler.Network network : LaserRelayConnectionHandler.getInstance().networks){
|
||||
networkList.appendTag(LaserRelayConnectionHandler.getInstance().writeNetworkToNBT(network));
|
||||
}
|
||||
compound.setTag("Networks", networkList);
|
||||
|
||||
//Player Data
|
||||
NBTTagList playerList = new NBTTagList();
|
||||
for(int i = 0; i < PlayerServerData.playerSaveData.size(); i++){
|
||||
PlayerServerData.PlayerSave theSave = PlayerServerData.playerSaveData.get(i);
|
||||
playerList.appendTag(theSave.toNBT());
|
||||
}
|
||||
compound.setTag("PlayerData", playerList);
|
||||
|
||||
return compound;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud;
|
|||
import de.ellpeck.actuallyadditions.mod.util.FluidStateMapper;
|
||||
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.playerdata.ExtraClientData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.ExtraClientData;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
|
|
|
@ -31,7 +31,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||
TileEntityLaserRelayItem relay = this.getConnectedRelay();
|
||||
if(relay != null){
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(relay.getPos());
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj.provider.getDimension());
|
||||
if(network != null){
|
||||
return relay.getItemHandlersInNetwork(network);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ 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;
|
||||
|
@ -38,13 +37,13 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
|
||||
@Override
|
||||
public void receiveSyncCompound(NBTTagCompound compound){
|
||||
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(this.pos);
|
||||
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj.provider.getDimension());
|
||||
|
||||
NBTTagList list = compound.getTagList("Connections", 10);
|
||||
if(!list.hasNoTags()){
|
||||
for(int i = 0; i < list.tagCount(); i++){
|
||||
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
||||
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
|
||||
LaserRelayConnectionHandler.addConnection(pair.firstRelay, pair.secondRelay, this.worldObj.provider.getDimension());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +56,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
NBTTagCompound compound = super.getUpdateTag();
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getInstance().getConnectionsFor(this.pos);
|
||||
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getConnectionsFor(this.pos, this.worldObj.provider.getDimension());
|
||||
if(connections != null && !connections.isEmpty()){
|
||||
for(LaserRelayConnectionHandler.ConnectionPair pair : connections){
|
||||
list.appendTag(pair.writeToNBT());
|
||||
|
@ -80,7 +79,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
public void renderParticles(){
|
||||
if(Util.RANDOM.nextInt(ConfigValues.lessParticles ? 16 : 8) == 0){
|
||||
BlockPos thisPos = this.pos;
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos);
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(thisPos, this.worldObj.provider.getDimension());
|
||||
if(network != null){
|
||||
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
||||
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
|
||||
|
@ -94,8 +93,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
@Override
|
||||
public void invalidate(){
|
||||
super.invalidate();
|
||||
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(this.pos);
|
||||
WorldData.markDirty(this.worldObj);
|
||||
LaserRelayConnectionHandler.removeRelayFromNetwork(this.pos, this.worldObj.provider.getDimension());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
|||
public int transmitEnergy(BlockPos blockFrom, int maxTransmit, boolean simulate){
|
||||
int transmitted = 0;
|
||||
if(maxTransmit > 0){
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(this.pos);
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(this.pos, this.worldObj.provider.getDimension());
|
||||
if(network != null){
|
||||
transmitted = this.transferEnergyToReceiverInNeed(blockFrom, network, Math.min(ConfigIntValues.LASER_RELAY_MAX_TRANSFER.getValue(), maxTransmit), simulate);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue