diff --git a/src/main/java/de/ellpeck/prettypipes/Registry.java b/src/main/java/de/ellpeck/prettypipes/Registry.java index 462576c..b6331b7 100644 --- a/src/main/java/de/ellpeck/prettypipes/Registry.java +++ b/src/main/java/de/ellpeck/prettypipes/Registry.java @@ -1,6 +1,7 @@ package de.ellpeck.prettypipes; import de.ellpeck.prettypipes.items.ModuleItem; +import de.ellpeck.prettypipes.pipe.modules.LowPriorityModuleItem; import de.ellpeck.prettypipes.pipe.modules.SpeedModuleItem; import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleContainer; import de.ellpeck.prettypipes.pipe.modules.extraction.ExtractionModuleGui; @@ -84,6 +85,7 @@ public final class Registry { registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new)); registry.registerAll(createTieredModule("filter_module", FilterModuleItem::new)); registry.registerAll(createTieredModule("speed_module", SpeedModuleItem::new)); + registry.registerAll(createTieredModule("low_priority_module", LowPriorityModuleItem::new)); ForgeRegistries.BLOCKS.getValues().stream() .filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID)) diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index d72aa5c..98619e3 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -1,5 +1,6 @@ package de.ellpeck.prettypipes.network; +import com.google.common.collect.Lists; import com.google.common.collect.Streams; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; @@ -255,22 +256,20 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return ret; } + public void clearDestinationCache(BlockPos... nodes) { + this.startProfile("clear_node_cache"); + this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).anyMatch(cached::contains)); + this.endProfile(); + } + @Override public void edgeAdded(GraphEdgeChangeEvent e) { - this.edgeModified(e); + this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget()); } @Override public void edgeRemoved(GraphEdgeChangeEvent e) { - this.edgeModified(e); - } - - private void edgeModified(GraphEdgeChangeEvent e) { - // uncache all connection infos that contain the removed edge's vertices - this.startProfile("clear_node_cache"); - this.nodeToConnectedNodes.values().removeIf( - nodes -> nodes.stream().anyMatch(n -> n.equals(e.getEdgeSource()) || n.equals(e.getEdgeTarget()))); - this.endProfile(); + this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget()); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index c779750..a1ac00f 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.network.PipeItem; +import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.modules.containers.MainPipeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -50,6 +51,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide } }; public final List items = new ArrayList<>(); + private int priority; public PipeTileEntity() { super(Registry.pipeTileEntity); @@ -89,7 +91,18 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide IProfiler profiler = this.world.getProfiler(); profiler.startSection("ticking_modules"); - this.streamModules().forEach(m -> m.getRight().tick(m.getLeft(), this)); + int prio = 0; + Iterator> modules = this.streamModules().iterator(); + while (modules.hasNext()) { + Pair module = modules.next(); + module.getRight().tick(module.getLeft(), this); + prio += module.getRight().getPriority(module.getLeft(), this); + } + if (prio != this.priority) { + this.priority = prio; + // clear the cache so that it's reevaluated based on priority + PipeNetwork.get(this.world).clearDestinationCache(this.pos); + } profiler.endSection(); profiler.startSection("ticking_items"); @@ -119,7 +132,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide } public int getPriority() { - return this.streamModules().mapToInt(m -> m.getRight().getPriority(m.getLeft(), this)).max().orElse(0); + return this.priority; } public float getItemSpeed() { diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java b/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java new file mode 100644 index 0000000..e058ec7 --- /dev/null +++ b/src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java @@ -0,0 +1,31 @@ +package de.ellpeck.prettypipes.pipe.modules; + +import de.ellpeck.prettypipes.items.IModule; +import de.ellpeck.prettypipes.items.ModuleItem; +import de.ellpeck.prettypipes.items.ModuleTier; +import de.ellpeck.prettypipes.pipe.PipeTileEntity; +import net.minecraft.item.ItemStack; + +public class LowPriorityModuleItem extends ModuleItem { + private final int priority; + + public LowPriorityModuleItem(String name, ModuleTier tier) { + super(name); + this.priority = tier.forTier(-50, -100, -200); + } + + @Override + public int getPriority(ItemStack module, PipeTileEntity tile) { + return this.priority; + } + + @Override + public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) { + return !(other instanceof LowPriorityModuleItem); + } + + @Override + public boolean hasContainer(ItemStack module, PipeTileEntity tile) { + return false; + } +} diff --git a/src/main/resources/assets/prettypipes/lang/en_us.json b/src/main/resources/assets/prettypipes/lang/en_us.json index e7b675b..55d344d 100644 --- a/src/main/resources/assets/prettypipes/lang/en_us.json +++ b/src/main/resources/assets/prettypipes/lang/en_us.json @@ -9,9 +9,13 @@ "item.prettypipes.low_speed_module": "Low Speed Increase Module", "item.prettypipes.medium_speed_module": "Medium Speed Increase Module", "item.prettypipes.high_speed_module": "High Speed Increase Module", + "item.prettypipes.low_low_priority_module": "Low Priority Module", + "item.prettypipes.medium_low_priority_module": "Lower Priority Module", + "item.prettypipes.high_low_priority_module": "Lowest Priority Module", "info.prettypipes.extraction_module": "Pulls items from adjacent inventories\nFilters and pull rates vary by tier", "info.prettypipes.filter_module": "Restricts flow from pipes into adjacent inventories\nFilter amount varies by tier", "info.prettypipes.speed_module": "Increases speed of items exiting adjacent inventories\nSpeed varies by tier", + "info.prettypipes.low_priority_module": "Decreases the reception priority of adjacent inventories\nLower priority means items will prefer other inventories", "block.prettypipes.pipe": "Pipe", "itemGroup.prettypipes": "Pretty Pipes", "container.prettypipes.pipe": "Pipe", diff --git a/src/main/resources/assets/prettypipes/models/item/high_low_priority_module.json b/src/main/resources/assets/prettypipes/models/item/high_low_priority_module.json new file mode 100644 index 0000000..e0122aa --- /dev/null +++ b/src/main/resources/assets/prettypipes/models/item/high_low_priority_module.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "prettypipes:item/high_low_priority_module" + } +} diff --git a/src/main/resources/assets/prettypipes/models/item/low_low_priority_module.json b/src/main/resources/assets/prettypipes/models/item/low_low_priority_module.json new file mode 100644 index 0000000..edea702 --- /dev/null +++ b/src/main/resources/assets/prettypipes/models/item/low_low_priority_module.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "prettypipes:item/low_low_priority_module" + } +} diff --git a/src/main/resources/assets/prettypipes/models/item/medium_low_priority_module.json b/src/main/resources/assets/prettypipes/models/item/medium_low_priority_module.json new file mode 100644 index 0000000..087cbb8 --- /dev/null +++ b/src/main/resources/assets/prettypipes/models/item/medium_low_priority_module.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "prettypipes:item/medium_low_priority_module" + } +} diff --git a/src/main/resources/assets/prettypipes/textures/item/high_low_priority_module.png b/src/main/resources/assets/prettypipes/textures/item/high_low_priority_module.png new file mode 100644 index 0000000..b231421 Binary files /dev/null and b/src/main/resources/assets/prettypipes/textures/item/high_low_priority_module.png differ diff --git a/src/main/resources/assets/prettypipes/textures/item/low_low_priority_module.png b/src/main/resources/assets/prettypipes/textures/item/low_low_priority_module.png new file mode 100644 index 0000000..47bdb93 Binary files /dev/null and b/src/main/resources/assets/prettypipes/textures/item/low_low_priority_module.png differ diff --git a/src/main/resources/assets/prettypipes/textures/item/medium_low_priority_module.png b/src/main/resources/assets/prettypipes/textures/item/medium_low_priority_module.png new file mode 100644 index 0000000..5029ccf Binary files /dev/null and b/src/main/resources/assets/prettypipes/textures/item/medium_low_priority_module.png differ