mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
added a utility method for the crafting module's required destination algorithm
This commit is contained in:
parent
bb62acf45f
commit
42e91287a8
2 changed files with 20 additions and 27 deletions
|
@ -5,7 +5,6 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.network.NetworkLock;
|
||||
import de.ellpeck.prettypipes.network.PipeItem;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerTileEntity;
|
||||
|
@ -13,8 +12,6 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.ISidedInventoryProvider;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -208,6 +205,25 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
|
|||
return this.getBlockState().get(PipeBlock.DIRECTIONS.get(dir)).isConnected();
|
||||
}
|
||||
|
||||
public Pair<BlockPos, ItemStack> getAvailableDestinationOrConnectable(ItemStack stack, boolean force, boolean preventOversending) {
|
||||
Pair<BlockPos, ItemStack> dest = this.getAvailableDestination(stack, force, preventOversending);
|
||||
if (dest != null)
|
||||
return dest;
|
||||
// if there's no available destination, try inserting into terminals etc.
|
||||
for (Direction dir : Direction.values()) {
|
||||
IPipeConnectable connectable = this.getPipeConnectable(dir);
|
||||
if (connectable == null)
|
||||
continue;
|
||||
ItemStack connectableRemain = connectable.insertItem(this.getPos(), dir, stack, true);
|
||||
if (connectableRemain.getCount() != stack.getCount()) {
|
||||
ItemStack inserted = stack.copy();
|
||||
inserted.shrink(connectableRemain.getCount());
|
||||
return Pair.of(this.getPos().offset(dir), inserted);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Pair<BlockPos, ItemStack> getAvailableDestination(ItemStack stack, boolean force, boolean preventOversending) {
|
||||
if (!this.canWork())
|
||||
return null;
|
||||
|
|
|
@ -8,9 +8,7 @@ import de.ellpeck.prettypipes.misc.ItemEqualityType;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.NetworkLock;
|
||||
import de.ellpeck.prettypipes.network.PipeItem;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
|
@ -19,16 +17,10 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -108,22 +100,7 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
ItemStack remain = request.getRight().copy();
|
||||
PipeTileEntity destPipe = network.getPipe(request.getLeft());
|
||||
if (destPipe != null) {
|
||||
Pair<BlockPos, ItemStack> dest = destPipe.getAvailableDestination(remain, true, true);
|
||||
if (dest == null) {
|
||||
// if there's no available destination, try inserting into terminals etc.
|
||||
for (Direction dir : Direction.values()) {
|
||||
IPipeConnectable connectable = destPipe.getPipeConnectable(dir);
|
||||
if (connectable == null)
|
||||
continue;
|
||||
ItemStack connectableRemain = connectable.insertItem(destPipe.getPos(), dir, remain, true);
|
||||
if (connectableRemain.getCount() != remain.getCount()) {
|
||||
ItemStack inserted = remain.copy();
|
||||
inserted.shrink(connectableRemain.getCount());
|
||||
dest = Pair.of(destPipe.getPos().offset(dir), inserted);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Pair<BlockPos, ItemStack> dest = destPipe.getAvailableDestinationOrConnectable(remain, true, true);
|
||||
if (dest == null)
|
||||
continue;
|
||||
for (NetworkLocation item : items) {
|
||||
|
|
Loading…
Reference in a new issue