diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index fdfe148..b9cba8b 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -59,8 +59,8 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide return 1; } }; + public PressurizerTileEntity pressurizer; protected List items; - private PressurizerTileEntity pressurizer; private int lastItemAmount; private int priority; @@ -102,6 +102,10 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide @Override public void tick() { + // invalidate our pressurizer reference if it was removed + if(this.pressurizer != null && this.pressurizer.isRemoved()) + this.pressurizer = null; + if (!this.world.isAreaLoaded(this.pos, 1)) return; IProfiler profiler = this.world.getProfiler(); @@ -121,13 +125,6 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide PipeNetwork.get(this.world).clearDestinationCache(this.pos); } profiler.endSection(); - - if (this.world.getGameTime() % 40 == 0) { - profiler.startSection("caching_data"); - // figure out if we're pressurized - this.pressurizer = this.findPressurizer(); - profiler.endSection(); - } } profiler.startSection("ticking_items"); @@ -151,7 +148,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide // an item might be re-routed from a previous location, but it should still count as a new item then if (!this.getItems().contains(item)) this.getItems().add(item); - if (this.pressurizer != null && !this.pressurizer.isRemoved()) + if (this.pressurizer != null) this.pressurizer.pressurizeItem(item.stack, false); } @@ -219,7 +216,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide public float getItemSpeed(ItemStack stack) { float moduleSpeed = (float) this.streamModules().mapToDouble(m -> m.getRight().getItemSpeedIncrease(m.getLeft(), this)).sum(); - float pressureSpeed = this.pressurizer != null && !this.pressurizer.isRemoved() && this.pressurizer.pressurizeItem(stack, true) ? 0.45F : 0; + float pressureSpeed = this.pressurizer != null && this.pressurizer.pressurizeItem(stack, true) ? 0.45F : 0; return 0.05F + moduleSpeed + pressureSpeed; } @@ -302,17 +299,4 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) { return new MainPipeContainer(Registry.pipeContainer, window, player, PipeTileEntity.this.pos); } - - private PressurizerTileEntity findPressurizer() { - PipeNetwork network = PipeNetwork.get(this.world); - for (BlockPos node : network.getOrderedNetworkNodes(this.pos)) { - PipeTileEntity pipe = network.getPipe(node); - for (Direction dir : Direction.values()) { - IPipeConnectable connectable = pipe.getPipeConnectable(dir); - if (connectable instanceof PressurizerBlock) - return Utility.getTileEntity(PressurizerTileEntity.class, this.world, node.offset(dir)); - } - } - return null; - } } diff --git a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java index 1942a26..c91e8a7 100644 --- a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java @@ -3,6 +3,8 @@ package de.ellpeck.prettypipes.pressurizer; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; +import de.ellpeck.prettypipes.network.PipeNetwork; +import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; @@ -17,6 +19,7 @@ import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.common.capabilities.Capability; @@ -109,6 +112,20 @@ public class PressurizerTileEntity extends TileEntity implements INamedContainer public void tick() { if (this.world.isRemote) return; + // notify pipes in network about us + if (this.world.getGameTime() % 10 == 0) { + PipeNetwork network = PipeNetwork.get(this.world); + for (Direction dir : Direction.values()) { + BlockPos offset = this.pos.offset(dir); + for (BlockPos node : network.getOrderedNetworkNodes(offset)) { + PipeTileEntity pipe = network.getPipe(node); + if (pipe != null) + pipe.pressurizer = this; + } + } + } + + // send energy update if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) { this.lastEnergy = this.storage.getEnergyStored(); Utility.sendTileEntityToClients(this);