Another possible fix for #986 - "Disks Disappearing"
This commit is contained in:
@@ -14,6 +14,8 @@ import java.util.List;
|
|||||||
public final class RSConfig {
|
public final class RSConfig {
|
||||||
private Configuration config;
|
private Configuration config;
|
||||||
|
|
||||||
|
public boolean debugLog;
|
||||||
|
|
||||||
//region Energy
|
//region Energy
|
||||||
public int controllerBaseUsage;
|
public int controllerBaseUsage;
|
||||||
public int cableUsage;
|
public int cableUsage;
|
||||||
@@ -135,6 +137,8 @@ public final class RSConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
private void loadConfig() {
|
||||||
|
debugLog = config.getBoolean("debugLog", "misc", false, "Whether to debug log diagnostic info to a file");
|
||||||
|
|
||||||
//region Energy
|
//region Energy
|
||||||
controllerBaseUsage = config.getInt("controllerBase", ENERGY, 0, 0, Integer.MAX_VALUE, "The base energy used by the Controller");
|
controllerBaseUsage = config.getInt("controllerBase", ENERGY, 0, 0, Integer.MAX_VALUE, "The base energy used by the Controller");
|
||||||
cableUsage = config.getInt("cable", ENERGY, 0, 0, Integer.MAX_VALUE, "The energy used by Cables");
|
cableUsage = config.getInt("cable", ENERGY, 0, 0, Integer.MAX_VALUE, "The energy used by Cables");
|
||||||
|
|||||||
@@ -58,8 +58,13 @@ import javax.annotation.Nullable;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public final class RSUtils {
|
public final class RSUtils {
|
||||||
public static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
|
public static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
|
||||||
@@ -588,4 +593,33 @@ public final class RSUtils {
|
|||||||
vertexBuffer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
|
vertexBuffer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Logger debugLog = Logger.getLogger("Refined Storage");
|
||||||
|
private static FileHandler debugLogFileHandler;
|
||||||
|
|
||||||
|
public static void debugLog(String message) {
|
||||||
|
if (RS.INSTANCE.config.debugLog) {
|
||||||
|
if (debugLogFileHandler == null) {
|
||||||
|
try {
|
||||||
|
debugLogFileHandler = new FileHandler("refinedstorage_debuglog_" + new SimpleDateFormat("Y-m-d_HH_mm_ss").format(Calendar.getInstance().getTime()) + ".log");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
debugLogFileHandler.setFormatter(new Formatter() {
|
||||||
|
private SimpleDateFormat logFormatter = new SimpleDateFormat("Y-m-d HH:mm:ss");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(LogRecord record) {
|
||||||
|
return "[" + logFormatter.format(new Date(record.getMillis())) + "] " + record.getMessage() + "\r\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
debugLog.setUseParentHandlers(false);
|
||||||
|
debugLog.addHandler(debugLogFileHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
debugLog.info(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network;
|
package com.raoulvdberge.refinedstorage.apiimpl.network;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
@@ -36,7 +37,11 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
|||||||
if (tag.hasKey(NBT_NODES)) {
|
if (tag.hasKey(NBT_NODES)) {
|
||||||
NBTTagList list = tag.getTagList(NBT_NODES, Constants.NBT.TAG_COMPOUND);
|
NBTTagList list = tag.getTagList(NBT_NODES, Constants.NBT.TAG_COMPOUND);
|
||||||
|
|
||||||
int nodesRead = 0;
|
int toRead = list.tagCount();
|
||||||
|
|
||||||
|
RSUtils.debugLog("Reading " + toRead + " nodes...");
|
||||||
|
|
||||||
|
int read = 0;
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
NBTTagCompound nodeTag = list.getCompoundTagAt(i);
|
NBTTagCompound nodeTag = list.getCompoundTagAt(i);
|
||||||
@@ -50,16 +55,28 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
|||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
setNode(pos, factory.apply(data));
|
setNode(pos, factory.apply(data));
|
||||||
|
|
||||||
++nodesRead;
|
RSUtils.debugLog("Node at " + pos + " read... (" + (++read) + "/" + toRead + ")");
|
||||||
|
} else {
|
||||||
|
RSUtils.debugLog("Factory for node at " + pos + " is null (id: " + id + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RSUtils.debugLog("Read " + read + " nodes out of " + toRead + " to read");
|
||||||
|
} else {
|
||||||
|
RSUtils.debugLog("Cannot read nodes, as there is no 'nodes' tag on this WorldSavedData");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||||
|
int toWrite = all().size();
|
||||||
|
|
||||||
|
RSUtils.debugLog("Writing " + toWrite + " nodes...");
|
||||||
|
|
||||||
NBTTagList list = new NBTTagList();
|
NBTTagList list = new NBTTagList();
|
||||||
|
|
||||||
|
int written = 0;
|
||||||
|
|
||||||
for (INetworkNode node : all()) {
|
for (INetworkNode node : all()) {
|
||||||
NBTTagCompound nodeTag = new NBTTagCompound();
|
NBTTagCompound nodeTag = new NBTTagCompound();
|
||||||
|
|
||||||
@@ -67,11 +84,15 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
|||||||
nodeTag.setLong(NBT_NODE_POS, node.getPos().toLong());
|
nodeTag.setLong(NBT_NODE_POS, node.getPos().toLong());
|
||||||
nodeTag.setTag(NBT_NODE_DATA, node.write(new NBTTagCompound()));
|
nodeTag.setTag(NBT_NODE_DATA, node.write(new NBTTagCompound()));
|
||||||
|
|
||||||
|
RSUtils.debugLog("Node at " + node.getPos() + " written... (" + (++written) + "/" + toWrite + ")");
|
||||||
|
|
||||||
list.appendTag(nodeTag);
|
list.appendTag(nodeTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setTag(NBT_NODES, list);
|
tag.setTag(NBT_NODES, list);
|
||||||
|
|
||||||
|
RSUtils.debugLog("Wrote " + written + " nodes out of " + toWrite + " to write");
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +119,8 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
RSUtils.debugLog("Clearing all nodes!");
|
||||||
|
|
||||||
nodes.clear();
|
nodes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.block;
|
package com.raoulvdberge.refinedstorage.block;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
@@ -30,6 +31,18 @@ public abstract class BlockNode extends BlockBase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
|
||||||
|
super.onBlockAdded(world, pos, state);
|
||||||
|
|
||||||
|
RSUtils.debugLog("Node block placed at " + pos + "!");
|
||||||
|
|
||||||
|
INetworkNodeManager manager = API.instance().getNetworkNodeManager(world);
|
||||||
|
|
||||||
|
manager.setNode(pos, ((TileNode) createTileEntity(world, state)).createNode());
|
||||||
|
manager.markForSaving();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||||
@@ -39,6 +52,8 @@ public abstract class BlockNode extends BlockBase {
|
|||||||
TileEntity tile = world.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
if (tile instanceof TileNode) {
|
if (tile instanceof TileNode) {
|
||||||
|
RSUtils.debugLog("Reading configuration from wrench at " + pos + "!");
|
||||||
|
|
||||||
((TileNode) tile).getNode().readConfiguration(stack.getTagCompound().getCompoundTag(NBT_REFINED_STORAGE_DATA));
|
((TileNode) tile).getNode().readConfiguration(stack.getTagCompound().getCompoundTag(NBT_REFINED_STORAGE_DATA));
|
||||||
((TileNode) tile).getNode().markDirty();
|
((TileNode) tile).getNode().markDirty();
|
||||||
}
|
}
|
||||||
@@ -58,6 +73,8 @@ public abstract class BlockNode extends BlockBase {
|
|||||||
|
|
||||||
removeTile(world, pos, state);
|
removeTile(world, pos, state);
|
||||||
|
|
||||||
|
RSUtils.debugLog("Node block broken at " + pos + "!");
|
||||||
|
|
||||||
manager.removeNode(pos);
|
manager.removeNode(pos);
|
||||||
manager.markForSaving();
|
manager.markForSaving();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.tile;
|
package com.raoulvdberge.refinedstorage.tile;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
|
import com.raoulvdberge.refinedstorage.api.util.IWrenchable;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
@@ -102,13 +102,10 @@ public abstract class TileNode<N extends NetworkNode> extends TileBase implement
|
|||||||
return clientNode;
|
return clientNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
INetworkNodeManager manager = API.instance().getNetworkNodeManager(getWorld());
|
NetworkNode node = (NetworkNode) API.instance().getNetworkNodeManager(getWorld()).getNode(pos);
|
||||||
|
|
||||||
NetworkNode node = (NetworkNode) manager.getNode(pos);
|
|
||||||
|
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
manager.setNode(pos, node = createNode());
|
throw new IllegalStateException("Node cannot be null!");
|
||||||
manager.markForSaving();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getContainer().world() == null) {
|
if (node.getContainer().world() == null) {
|
||||||
@@ -136,6 +133,8 @@ public abstract class TileNode<N extends NetworkNode> extends TileBase implement
|
|||||||
} else if (legacyTag.getSize() == 6 + 1 && hasMeta && hasForgeData && hasForgeCaps) {
|
} else if (legacyTag.getSize() == 6 + 1 && hasMeta && hasForgeData && hasForgeCaps) {
|
||||||
// NO OP
|
// NO OP
|
||||||
} else {
|
} else {
|
||||||
|
RSUtils.debugLog("Reading legacy tag data at " + pos + "!");
|
||||||
|
|
||||||
node.read(legacyTag);
|
node.read(legacyTag);
|
||||||
node.markDirty();
|
node.markDirty();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user