Remove the map and use the world saved data, #986
This commit is contained in:
@@ -36,13 +36,12 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapStorage;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class API implements IRSAPI {
|
||||
@@ -50,7 +49,6 @@ public class API implements IRSAPI {
|
||||
|
||||
private IComparer comparer = new Comparer();
|
||||
private INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
||||
private Map<Integer, INetworkNodeManager> networkNodeManagers = new HashMap<>();
|
||||
private IStorageDiskBehavior storageDiskBehavior = new StorageDiskBehavior();
|
||||
private ISoldererRegistry soldererRegistry = new SoldererRegistry();
|
||||
private ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
||||
@@ -98,7 +96,18 @@ public class API implements IRSAPI {
|
||||
throw new IllegalStateException("Attempting to access network node manager on the client");
|
||||
}
|
||||
|
||||
return networkNodeManagers.computeIfAbsent(world.provider.getDimension(), m -> NetworkNodeManager.getManager(world));
|
||||
MapStorage storage = world.getPerWorldStorage();
|
||||
NetworkNodeManager instance = (NetworkNodeManager) storage.getOrLoadData(NetworkNodeManager.class, NetworkNodeManager.NAME);
|
||||
|
||||
if (instance == null) {
|
||||
System.out.println("[RS DEBUG] Initializing Network Node Manager for " + world.provider.getDimension());
|
||||
|
||||
instance = new NetworkNodeManager(NetworkNodeManager.NAME);
|
||||
|
||||
storage.setData(NetworkNodeManager.NAME, instance);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,9 +6,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
import net.minecraft.world.storage.MapStorage;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -18,7 +16,7 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class NetworkNodeManager extends WorldSavedData implements INetworkNodeManager {
|
||||
private static final String NAME = "refinedstorage_nodes";
|
||||
public static final String NAME = "refinedstorage_nodes";
|
||||
|
||||
private static final String NBT_NODES = "Nodes";
|
||||
private static final String NBT_NODE_ID = "Id";
|
||||
@@ -37,8 +35,11 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
||||
|
||||
clear();
|
||||
|
||||
if (tag.hasKey(NBT_NODES)) {
|
||||
NBTTagList list = tag.getTagList(NBT_NODES, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
int nodesRead = 0;
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
NBTTagCompound nodeTag = list.getCompoundTagAt(i);
|
||||
|
||||
@@ -50,8 +51,13 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
||||
|
||||
if (factory != null) {
|
||||
setNode(pos, factory.apply(data));
|
||||
|
||||
++nodesRead;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("[RS DEBUG] Read " + nodesRead + " nodes!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,22 +81,6 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static NetworkNodeManager getManager(World world) {
|
||||
MapStorage storage = world.getPerWorldStorage();
|
||||
NetworkNodeManager instance = (NetworkNodeManager) storage.getOrLoadData(NetworkNodeManager.class, NAME);
|
||||
|
||||
if (instance == null) {
|
||||
System.out.println("[RS DEBUG] Initializing Network Node Manager for " + world.provider.getDimension());
|
||||
instance = new NetworkNodeManager(NAME);
|
||||
|
||||
storage.setData(NAME, instance);
|
||||
} else {
|
||||
System.out.println("[RS DEBUG] Network Node Manager for " + world.provider.getDimension() + " already exists, OK...");
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public INetworkNode getNode(BlockPos pos) {
|
||||
|
Reference in New Issue
Block a user