mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-25 21:18:34 +01:00
added some commands to log debug information about pretty pipes and clear invalid caches
This commit is contained in:
parent
33f4d47889
commit
d04dd4054a
4 changed files with 69 additions and 1 deletions
|
@ -2,12 +2,20 @@ package de.ellpeck.prettypipes.misc;
|
|||
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public final class Events {
|
||||
|
||||
|
@ -15,4 +23,34 @@ public final class Events {
|
|||
public static void onWorldCaps(AttachCapabilitiesEvent<Level> event) {
|
||||
event.addCapability(new ResourceLocation(PrettyPipes.ID, "network"), new PipeNetwork(event.getObject()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStarting(ServerStartingEvent event) {
|
||||
event.getServer().getCommands().getDispatcher().register(Commands.literal(PrettyPipes.ID).requires(s -> s.hasPermission(2))
|
||||
.then(Commands.literal("dump").executes(c -> {
|
||||
var source = c.getSource();
|
||||
var file = Paths.get('_' + PrettyPipes.ID + "dump.txt");
|
||||
var dump = PipeNetwork.get(source.getLevel()).toString();
|
||||
try {
|
||||
Files.writeString(file, dump, StandardCharsets.UTF_8);
|
||||
source.sendSuccess(new TextComponent("Wrote network dump to file " + file.toAbsolutePath()), true);
|
||||
} catch (IOException e) {
|
||||
source.sendFailure(new TextComponent("Failed to write network dump to file " + file.toAbsolutePath()));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}))
|
||||
.then(Commands.literal("uncache").executes(c -> {
|
||||
var source = c.getSource();
|
||||
PipeNetwork.get(source.getLevel()).clearCaches();
|
||||
source.sendSuccess(new TextComponent("Cleared all pipe caches in the world"), true);
|
||||
return 0;
|
||||
}))
|
||||
.then(Commands.literal("unlock").executes(c -> {
|
||||
var source = c.getSource();
|
||||
PipeNetwork.get(source.getLevel()).unlock();
|
||||
source.sendSuccess(new TextComponent("Resolved all network locks in the world"), true);
|
||||
return 0;
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,9 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
|
|||
public int hashCode() {
|
||||
return Objects.hash(this.lockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NetworkLock{" + "location=" + this.location.pipePos + ", stack=" + this.stack + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -317,6 +317,11 @@ public class PipeItem implements IPipeItem {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PipeItem{" + "stack=" + this.stack + ", x=" + this.x + ", y=" + this.y + ", z=" + this.z + ", startInventory=" + this.startInventory + ", destInventory=" + this.destInventory + '}';
|
||||
}
|
||||
|
||||
protected int getModelCount() {
|
||||
var i = 1;
|
||||
if (this.stack.getCount() > 48) {
|
||||
|
|
|
@ -245,6 +245,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
var tile = this.tileCache.get(pos);
|
||||
if (tile == null || tile.isRemoved()) {
|
||||
tile = Utility.getBlockEntity(PipeBlockEntity.class, this.world, pos);
|
||||
if (tile != null)
|
||||
this.tileCache.put(pos, tile);
|
||||
}
|
||||
return tile;
|
||||
|
@ -387,6 +388,15 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return null;
|
||||
}
|
||||
|
||||
public void clearCaches() {
|
||||
this.nodeToConnectedNodes.clear();
|
||||
this.tileCache.clear();
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
this.networkLocks.clear();
|
||||
}
|
||||
|
||||
private List<NetworkEdge> createAllEdges(BlockPos pos, BlockState state, boolean ignoreCurrBlocked) {
|
||||
this.startProfile("create_all_edges");
|
||||
List<NetworkEdge> edges = new ArrayList<>();
|
||||
|
@ -506,6 +516,16 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public void vertexRemoved(GraphVertexChangeEvent<BlockPos> e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PipeNetwork{" +
|
||||
"\ngraph=" + this.graph +
|
||||
",\nnodeToConnectedNodes=" + this.nodeToConnectedNodes +
|
||||
",\ntileCache=" + this.tileCache.keySet() +
|
||||
",\npipeItems=" + this.pipeItems +
|
||||
",\nnetworkLocks=" + this.networkLocks + '}';
|
||||
}
|
||||
|
||||
public void startProfile(String name) {
|
||||
this.world.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue