From 96826361037f24a3ebcda3f7839a093a19ba858e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 17 Apr 2020 17:18:25 +0200 Subject: [PATCH] added priority modules --- .../java/de/ellpeck/prettypipes/Registry.java | 2 ++ .../prettypipes/network/PipeNetwork.java | 19 +++++------ .../prettypipes/pipe/PipeTileEntity.java | 17 ++++++++-- .../pipe/modules/LowPriorityModuleItem.java | 31 ++++++++++++++++++ .../assets/prettypipes/lang/en_us.json | 4 +++ .../models/item/high_low_priority_module.json | 6 ++++ .../models/item/low_low_priority_module.json | 6 ++++ .../item/medium_low_priority_module.json | 6 ++++ .../item/high_low_priority_module.png | Bin 0 -> 320 bytes .../textures/item/low_low_priority_module.png | Bin 0 -> 319 bytes .../item/medium_low_priority_module.png | Bin 0 -> 334 bytes 11 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 src/main/java/de/ellpeck/prettypipes/pipe/modules/LowPriorityModuleItem.java create mode 100644 src/main/resources/assets/prettypipes/models/item/high_low_priority_module.json create mode 100644 src/main/resources/assets/prettypipes/models/item/low_low_priority_module.json create mode 100644 src/main/resources/assets/prettypipes/models/item/medium_low_priority_module.json create mode 100644 src/main/resources/assets/prettypipes/textures/item/high_low_priority_module.png create mode 100644 src/main/resources/assets/prettypipes/textures/item/low_low_priority_module.png create mode 100644 src/main/resources/assets/prettypipes/textures/item/medium_low_priority_module.png 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 0000000000000000000000000000000000000000..b2314212edc2a87631f5884653219b929014c1c3 GIT binary patch literal 320 zcmV-G0l)rPx#`bk7VR5*>LQ!Nj|FciFz4fb=uV$cu-j_@01K#(ASG-Lu-wckK+6C~&vERtjz zMIb>Ax&Z3E6x#6-PW4^xZtuDj_!ABt)~opbi?P}6I2^EE#rMPUWQaW10|2O8!E-&R zTrr=fDa0&vToT{HJ{v0{!bJqQyvz&{@sR^|*^SBS7c;@AKx^xu)%9vrp=9f9GZlrq z`k-G{B^|t+fh-L$m%D)K%!yI&I|v|U(_w}g zzNh;O9~epRW<257!YWa8$SIte`NNqj0pZR;X;~Rri7IQlI2agm=SG)UDOM%{1A)QQ L)z4*}Q$iB}YsrIA literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..5029ccfe11b5c8f2c35c7a07634585aadb5d8f87 GIT binary patch literal 334 zcmV-U0kQsxP)Px$2uVaiR5*>Lld*2XFcd{kP>k|9VP)yuszW!#H?Y8f)PYtO%8<=n5TAg$F(5Is zbZxgvnVG6qVhnWzo$NX|B|*KD-_w1^*R~A*RA3hC)$(}B;PvfYU;*pZ^7!%j<(Wh% z0MLa-gaTb?+t0ELIZcA_bm))_e+xNdF9!hZf!5^7+oS{#q2Mh)*g6K@-P%b}3DAWm zPUj^J=CUc z)71iWp{;Rz6Vb_^>38!I`0No}ZFf7bSCzs8n4K0c(O>LpfE&?Vn0b{dkCFXM@^Ny} gXOhz-sCPBc4?%5WkuGN`djJ3c07*qoM6N<$f;q~RRR910 literal 0 HcmV?d00001