Skip to content

Commit

Permalink
Cleanup debug log, update forge and implement missingoreexception on …
Browse files Browse the repository at this point in the history
…client properly.
  • Loading branch information
darkevilmac committed Sep 7, 2017
1 parent b6eb450 commit e978a24
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
modGroup=com.elytradev
modVersion=5
modBaseName=teckle
forgeVersion=1.12.1-14.22.0.2456
forgeVersion=1.12.1-14.22.0.2473
mcpVersion=snapshot_20170806

#JEI Stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
public class MissingOreExceptionClient extends CustomModLoadingErrorDisplayException {

private String title;
private String message;
private String[] message;

public MissingOreExceptionClient(String message, Throwable cause) {
super(message, cause);
this.title = "Teckle is missing ores!";
this.message = message;
this.message = new String[4];
for (int i = 0; i < message.split("\n").length; i++) {
// Split new lines for rendering.
this.message[i] = message.split("\n")[i];
}
}

@Override
Expand All @@ -22,6 +26,9 @@ public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
@Override
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
errorScreen.drawCenteredString(errorScreen.mc.fontRenderer, this.title, errorScreen.width / 2, 90, 16777215);
errorScreen.drawCenteredString(errorScreen.mc.fontRenderer, this.message, errorScreen.width / 2, 110, 16777215);
for (int i = 0; i < this.message.length; i++) {
String m = this.message[i];
errorScreen.drawCenteredString(errorScreen.mc.fontRenderer, m, errorScreen.width / 2, 110 + (i * 10), 16777215);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ public void registerHandlers() {
@Override
public void handleMissingOres(String m) {
// FML doesn't seem to work properly but this will still cause the game to exit for now.
throw new MissingOreExceptionClient(m, new MissingOreException(m));
throw new MissingOreExceptionClient(m, new MissingOreException(m.replaceAll("\n", "")));
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/elytradev/teckle/common/TeckleObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ public void init(FMLInitializationEvent e) {

boolean foundMatchingOres = foundSilver && foundTin && foundCopper;
if (!foundMatchingOres && !TeckleMod.INDEV && !TeckleMod.CONFIG.skipOreChecks) {
String additionalData = (foundSilver ? "Found " : "Couldn't find ") + "silver ingots. ";
additionalData += (foundTin ? "Found " : "Couldn't find ") + "tin ingots. ";
additionalData += (foundCopper ? "Found " : "Couldn't find ") + "copper ingots.";
TeckleMod.PROXY.handleMissingOres("Teckle is missing ores, Tin, Silver, and Copper must be present to run. " + additionalData);
String additionalData = "\n" + "Silver ingots " + (foundSilver ? "✔" : "✘");
additionalData += "\n" + "Tin ingots " + (foundTin ? "✔" : "✘");
additionalData += "\n" + "Copper ingots " + (foundCopper ? "✔" : "✘");
TeckleMod.PROXY.handleMissingOres("Tin, Silver, and Copper must be present to run. " + additionalData);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class MissingOreException extends RuntimeException {
public MissingOreException(String data) {
super(data);
super("Teckle is missing ores, " + data.replaceAll("\n", ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.util.Objects;


public class CommonProxy {

public void registerRenderers(LoaderState.ModState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AdvancedStackHandlerPool extends WorldSavedData {
private static final HashMap<Integer, AdvancedStackHandlerPool> FALLBACK_POOLS = Maps.newHashMap();

private Map<UUID, AdvancedStackHandlerEntry> registeredHandlers = Maps.newHashMap();
private int dimension = 0;

public AdvancedStackHandlerPool(String name) {
super(name);
Expand Down Expand Up @@ -59,12 +60,14 @@ public static AdvancedStackHandlerPool getPool(@Nonnull World world) {
public static AdvancedStackHandlerPool getPool(Integer dim) {
if (!DIMENSION_POOLS.containsKey(dim)) {
DIMENSION_POOLS.put(dim, new AdvancedStackHandlerPool());
DIMENSION_POOLS.get(dim).dimension = dim;
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
getSavedPool(DimensionManager.getWorld(dim));
}
}
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
FALLBACK_POOLS.put(dim, new AdvancedStackHandlerPool());
FALLBACK_POOLS.get(dim).dimension = dim;
return FALLBACK_POOLS.get(dim);
}
return DIMENSION_POOLS.get(dim);
Expand Down Expand Up @@ -170,7 +173,8 @@ public NBTTagCompound writeToNBT(NBTTagCompound tag) {
for (int i = 0; i < entries.size(); i++) {
tag.setTag("e" + i, entries.get(i));
}
TeckleMod.LOG.debug("Serialized {} stack handlers, skipped {}", entries.size(), skipped);
if (entries.size() != 0)
TeckleMod.LOG.debug("Serialized {} stack handlers in {}, skipped {}", entries.size(), this.dimension, skipped);
return tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -111,13 +112,25 @@ public void unregisterNodeAtPosition(BlockPos nodePosition, EnumFacing face) {
List<NodeContainer> removedNodeContainers = positionData.getNodeContainers(this.getNetworkID()).stream()
.filter(nodeContainer -> faceMatches(face, nodeContainer.getFacing()) && nodeContainer.getPos().equals(nodePosition))
.collect(Collectors.toList());

// Tell the removed node that everything else was removed.
removedNodeContainers.stream().filter(nC -> nC.getNetworkTile() != null && nC.getNetworkTile().listenToNetworkChange())
.forEach(removedContainer -> networkNodes.values().stream()
.flatMap((Function<PositionData, Stream<NodeContainer>>) posData -> posData.getNodeContainers(getNetworkID()).stream())
.forEach(nodeContainer -> {
if (!Objects.equals(removedContainer, nodeContainer))
removedContainer.getNetworkTile().onNodeRemoved(nodeContainer.getNode());
}));
// Clean position data of any garbage data just in case.
positionData.removeIf(getNetworkID(), nodeContainer -> faceMatches(face, nodeContainer.getFacing()) && nodeContainer.getPos().equals(nodePosition));
// Notify listeners of the removed node.
removedNodeContainers.forEach(removedContainer -> listenerNodePositions.stream().map(networkNodes::get).flatMap(pD -> pD.getNodeContainers(getNetworkID()).stream())
.filter(nodeContainer -> nodeContainer.getNode() != null && nodeContainer.getNode().getNetworkTile().listenToNetworkChange())
.forEach(nodeContainer -> nodeContainer.getNode().getNetworkTile().onNodeRemoved(removedContainer.getNode())));
//Actually remove the nodes from the position data.
removedNodeContainers.forEach(removed -> positionData.removeNodeContainer(getNetworkID(), removed));

// Clean position data of any old stuff.
// Clean positiondata map of empty positions.
networkNodes.values().removeIf(posData -> posData.getNodeContainers(getNetworkID()).isEmpty());
checkListeners();
}
Expand Down Expand Up @@ -237,6 +250,11 @@ public WorldNetwork merge(IWorldNetwork otherNetwork) {
WorldNetwork mergedNetwork = new WorldNetwork(this.world, null);
this.transferNetworkData(mergedNetwork);
otherNetwork.transferNetworkData(mergedNetwork);
mergedNetwork.listenerNodePositions.stream().flatMap((Function<BlockPos, Stream<NodeContainer>>)
blockPos -> mergedNetwork.getNodeContainersAtPosition(blockPos).stream()
.filter(nC -> nC.hasNetworkTile() && nC.getNetworkTile().listenToNetworkChange())).forEach(nodeContainer ->
mergedNetwork.nodeStream().filter(streamedContainer -> streamedContainer != nodeContainer)
.forEach(streamedContainer -> nodeContainer.getNetworkTile().onNodeAdded(streamedContainer.getNode())));
TeckleMod.LOG.debug("Completed merge, resulted in " + mergedNetwork);
return mergedNetwork;
}
Expand All @@ -256,7 +274,7 @@ public void transferNetworkData(IWorldNetwork to) {
any.ifPresent(blockPosEnumFacingPair -> networkDB.getRemappedNodes().remove(blockPosEnumFacingPair));
if (!node.isLoaded()) {
networkDB.getRemappedNodes().put(new MutablePair<>(node.getPosition(), node.getCapabilityFace()), to.getNetworkID());
TeckleMod.LOG.debug("marking node as remapped " + node.getPosition());
TeckleMod.LOG.debug("Marking node as remapped " + node.getPosition());
}

this.unregisterNode(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private NBTTagCompound saveDatabase(NBTTagCompound databaseCompound) {
databaseCompound.setUniqueId("rNN" + i, remappedNodes.get(i).getValue());
}

TeckleMod.LOG.debug("Serialized networks in {}, total is {}", world.provider.getDimension(), networks.size());
if (!networks.isEmpty())
TeckleMod.LOG.debug("Serialized networks in {}, total is {}", world.provider.getDimension(), networks.size());
return databaseCompound;
}

Expand Down

0 comments on commit e978a24

Please sign in to comment.