mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-22 23:39:22 +01:00
added priority modules
This commit is contained in:
parent
dc5ce8a26c
commit
9682636103
11 changed files with 79 additions and 12 deletions
|
@ -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))
|
||||
|
|
|
@ -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<CompoundNBT>, 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<BlockPos, NetworkEdge> e) {
|
||||
this.edgeModified(e);
|
||||
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.edgeModified(e);
|
||||
}
|
||||
|
||||
private void edgeModified(GraphEdgeChangeEvent<BlockPos, NetworkEdge> 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
|
||||
|
|
|
@ -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<PipeItem> 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<Pair<ItemStack, IModule>> modules = this.streamModules().iterator();
|
||||
while (modules.hasNext()) {
|
||||
Pair<ItemStack, IModule> 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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "prettypipes:item/high_low_priority_module"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "prettypipes:item/low_low_priority_module"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "prettypipes:item/medium_low_priority_module"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 320 B |
Binary file not shown.
After Width: | Height: | Size: 319 B |
Binary file not shown.
After Width: | Height: | Size: 334 B |
Loading…
Reference in a new issue