mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-25 04:58:34 +01:00
Compare commits
4 commits
bdd507885e
...
b637998938
Author | SHA1 | Date | |
---|---|---|---|
b637998938 | |||
d04dd4054a | |||
33f4d47889 | |||
bf7760c5fb |
7 changed files with 80 additions and 8 deletions
|
@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
|
|||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
version = '1.10.5'
|
||||
version = '1.11.0'
|
||||
group = 'de.ellpeck.prettypipes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = 'PrettyPipes'
|
||||
|
||||
|
|
|
@ -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,7 +245,8 @@ 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);
|
||||
this.tileCache.put(pos, tile);
|
||||
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<>();
|
||||
|
@ -461,13 +471,13 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return ret;
|
||||
}
|
||||
|
||||
public void clearDestinationCache(BlockPos... nodes) {
|
||||
public void clearDestinationCache(List<BlockPos> nodes) {
|
||||
this.startProfile("clear_node_cache");
|
||||
// remove caches for the nodes
|
||||
for (var node : nodes)
|
||||
this.nodeToConnectedNodes.keySet().remove(node);
|
||||
// remove caches that contain the nodes as a destination
|
||||
this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).anyMatch(cached::contains));
|
||||
this.nodeToConnectedNodes.values().removeIf(cached -> nodes.stream().anyMatch(cached::contains));
|
||||
this.endProfile();
|
||||
}
|
||||
|
||||
|
@ -490,12 +500,12 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
|
||||
@Override
|
||||
public void edgeAdded(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
if (prio != pipe.priority) {
|
||||
pipe.priority = prio;
|
||||
// clear the cache so that it's reevaluated based on priority
|
||||
PipeNetwork.get(pipe.level).clearDestinationCache(pipe.worldPosition);
|
||||
PipeNetwork.get(pipe.level).clearDestinationCache(Collections.singletonList(pipe.worldPosition));
|
||||
}
|
||||
profiler.pop();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
" R ",
|
||||
"IGI"
|
||||
"IGI",
|
||||
" C "
|
||||
],
|
||||
"key": {
|
||||
"R": {
|
||||
|
@ -13,6 +14,9 @@
|
|||
},
|
||||
"G": {
|
||||
"tag": "forge:glass"
|
||||
},
|
||||
"C": {
|
||||
"item": "minecraft:copper_ingot"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
|
|
Loading…
Reference in a new issue