diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index 4b4fb2e..4b4c84d 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -393,6 +393,7 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL } public int getItemsOnTheWay(BlockPos goalInv, ItemStack type, ItemEqualityType... equalityTypes) { + // TODO pending auto-crafting requests should be marked as "on the way" here to allow over-sending prevention return this.getPipeItemsOnTheWay(goalInv) .filter(i -> type == null || ItemEqualityType.compareItems(i.stack, type, equalityTypes)) .mapToInt(i -> i.stack.getCount()).sum(); diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 65d3aaf..0914c6a 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -191,9 +191,10 @@ public class PipeBlock extends ContainerBlock implements IPipeConnectable { } public static void onStateChanged(World world, BlockPos pos, BlockState newState) { + // wait a few ticks before checking if we have to drop our modules, so that things like iron -> gold chest work PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos); - if (tile != null && !tile.canHaveModules()) - Utility.dropInventory(tile, tile.modules); + if (tile != null) + tile.moduleDropCheck = 5; PipeNetwork network = PipeNetwork.get(world); int connections = 0; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java index b9cba8b..830c1cb 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeTileEntity.java @@ -1,6 +1,5 @@ package de.ellpeck.prettypipes.pipe; -import com.google.common.base.Predicates; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.Utility; @@ -8,7 +7,6 @@ import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.network.PipeItem; import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer; -import de.ellpeck.prettypipes.pressurizer.PressurizerBlock; import de.ellpeck.prettypipes.pressurizer.PressurizerTileEntity; import net.minecraft.block.BlockState; import net.minecraft.block.ChestBlock; @@ -28,7 +26,6 @@ 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.util.Constants; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -60,6 +57,7 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide } }; public PressurizerTileEntity pressurizer; + public int moduleDropCheck; protected List items; private int lastItemAmount; private int priority; @@ -75,12 +73,14 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide @Override public CompoundNBT write(CompoundNBT compound) { compound.put("modules", this.modules.serializeNBT()); + compound.putInt("module_drop_check", this.moduleDropCheck); return super.write(compound); } @Override public void read(BlockState state, CompoundNBT compound) { this.modules.deserializeNBT(compound.getCompound("modules")); + this.moduleDropCheck = compound.getInt("module_drop_check"); super.read(state, compound); } @@ -103,7 +103,7 @@ 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()) + if (this.pressurizer != null && this.pressurizer.isRemoved()) this.pressurizer = null; if (!this.world.isAreaLoaded(this.pos, 1)) @@ -111,6 +111,13 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide IProfiler profiler = this.world.getProfiler(); if (!this.world.isRemote) { + // drop modules here to give a bit of time for blocks to update (iron -> gold chest etc.) + if (this.moduleDropCheck > 0) { + this.moduleDropCheck--; + if (this.moduleDropCheck <= 0 && !this.canHaveModules()) + Utility.dropInventory(this, this.modules); + } + profiler.startSection("ticking_modules"); int prio = 0; Iterator> modules = this.streamModules().iterator();