allow modules in pipes connected to terminals

This commit is contained in:
Ellpeck 2020-05-17 15:29:10 +02:00
parent 8046081653
commit f2ebe8af90
4 changed files with 20 additions and 4 deletions

View file

@ -19,4 +19,8 @@ public interface IPipeConnectable {
default ItemStack insertItem(World world, BlockPos pipePos, Direction direction, PipeItem item) { default ItemStack insertItem(World world, BlockPos pipePos, Direction direction, PipeItem item) {
return item.stack; return item.stack;
} }
default boolean allowsModules(World world, BlockPos pipePos, Direction direction) {
return false;
}
} }

View file

@ -72,7 +72,7 @@ public class PipeBlock extends ContainerBlock implements IPipeConnectable {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos);
if (tile == null) if (tile == null)
return ActionResultType.PASS; return ActionResultType.PASS;
if (!tile.isConnectedInventory()) if (!tile.canHaveModules())
return ActionResultType.PASS; return ActionResultType.PASS;
if (!worldIn.isRemote) if (!worldIn.isRemote)
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos); NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
@ -185,7 +185,7 @@ public class PipeBlock extends ContainerBlock implements IPipeConnectable {
public static void onStateChanged(World world, BlockPos pos, BlockState newState) { public static void onStateChanged(World world, BlockPos pos, BlockState newState) {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos); PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos);
if (tile != null && !tile.isConnectedInventory()) if (tile != null && !tile.canHaveModules())
Utility.dropInventory(tile, tile.modules); Utility.dropInventory(tile, tile.modules);
PipeNetwork network = PipeNetwork.get(world); PipeNetwork network = PipeNetwork.get(world);

View file

@ -228,8 +228,15 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
return this.getItemHandler(dir, null) != null; return this.getItemHandler(dir, null) != null;
} }
public boolean isConnectedInventory() { public boolean canHaveModules() {
return Arrays.stream(Direction.values()).anyMatch(this::isConnectedInventory); for (Direction dir : Direction.values()) {
if (this.isConnectedInventory(dir))
return true;
IPipeConnectable connectable = this.getPipeConnectable(dir);
if (connectable != null && connectable.allowsModules(this.world, this.pos, dir))
return true;
}
return false;
} }
public boolean canNetworkSee() { public boolean canNetworkSee() {

View file

@ -77,6 +77,11 @@ public class ItemTerminalBlock extends ContainerBlock implements IPipeConnectabl
return item.stack; return item.stack;
} }
@Override
public boolean allowsModules(World world, BlockPos pipePos, Direction direction) {
return true;
}
@Override @Override
public BlockRenderType getRenderType(BlockState state) { public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL; return BlockRenderType.MODEL;