use of logisticspipes.pipes.basic.CoreMultiBlockPipe in project LogisticsPipes by RS485.
the class PipeMultiBlockTransportLogistics method handleTileReachedClient.
@Override
protected void handleTileReachedClient(LPTravelingItemClient arrivingItem, TileEntity tile, EnumFacing dir) {
if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).pipe instanceof CoreMultiBlockPipe) {
passToNextPipe(arrivingItem, tile);
return;
} else if (tile instanceof LogisticsTileGenericSubMultiBlock) {
List<LogisticsTileGenericPipe> masterTile = ((LogisticsTileGenericSubMultiBlock) tile).getMainPipe();
if (!masterTile.isEmpty()) {
if (masterTile.size() > 1) {
throw new UnsupportedOperationException();
}
passToNextPipe(arrivingItem, masterTile.get(0));
return;
}
}
Explosion explosion = new Explosion(this.getWorld(), null, this.getPipe().getX(), this.getPipe().getY(), this.getPipe().getZ(), 4.0F, false, true);
explosion.doExplosionB(true);
}
use of logisticspipes.pipes.basic.CoreMultiBlockPipe in project LogisticsPipes by RS485.
the class ItemLogisticsPipe method onItemUse.
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
Block block = LPBlocks.pipe;
IBlockState iblockstate = worldIn.getBlockState(pos);
Block worldBlock = iblockstate.getBlock();
if (!worldBlock.isReplaceable(worldIn, pos)) {
pos = pos.offset(facing);
}
ItemStack itemstack = player.getHeldItem(hand);
if (itemstack.isEmpty()) {
return EnumActionResult.FAIL;
}
if (!dummyPipe.isMultiBlock()) {
if (player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(block, pos, false, facing, null)) {
CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(this);
if (pipe == null) {
LogisticsPipes.log.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[] { pos.getX(), pos.getY(), pos.getZ() });
return EnumActionResult.PASS;
}
if (LogisticsBlockGenericPipe.placePipe(pipe, worldIn, pos, block, null)) {
IBlockState state = worldIn.getBlockState(pos);
if (state.getBlock() == block) {
// setTileEntityNBT(world, player, pos, stack);
block.onBlockPlacedBy(worldIn, pos, state, player, itemstack);
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, itemstack);
IBlockState newBlockState = worldIn.getBlockState(pos);
SoundType soundtype = newBlockState.getBlock().getSoundType(newBlockState, worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
}
}
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
} else {
CoreMultiBlockPipe multiPipe = (CoreMultiBlockPipe) dummyPipe;
boolean isFreeSpace = true;
DoubleCoordinates placeAt = new DoubleCoordinates(pos);
LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> globalPos = new LPPositionSet<>(DoubleCoordinatesType.class);
globalPos.add(new DoubleCoordinatesType<>(placeAt, CoreMultiBlockPipe.SubBlockTypeForShare.NON_SHARE));
LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> positions = multiPipe.getSubBlocks();
ITubeOrientation orientation = multiPipe.getTubeOrientation(player, pos.getX(), pos.getZ());
if (orientation == null) {
return EnumActionResult.FAIL;
}
orientation.rotatePositions(positions);
positions.stream().map(iPos -> iPos.add(placeAt)).forEach(globalPos::add);
globalPos.addToAll(orientation.getOffset());
placeAt.add(orientation.getOffset());
for (DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> iPos : globalPos) {
if (!player.canPlayerEdit(iPos.getBlockPos(), facing, itemstack) || !worldIn.mayPlace(block, iPos.getBlockPos(), false, facing, null)) {
TileEntity tile = worldIn.getTileEntity(iPos.getBlockPos());
boolean canPlace = false;
if (tile instanceof LogisticsTileGenericSubMultiBlock) {
if (CoreMultiBlockPipe.canShare(((LogisticsTileGenericSubMultiBlock) tile).getSubTypes(), iPos.getType())) {
canPlace = true;
}
}
if (!canPlace) {
isFreeSpace = false;
break;
}
}
}
if (isFreeSpace) {
CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.createPipe(this);
if (pipe == null) {
LogisticsPipes.log.log(Level.WARN, "Pipe failed to create during placement at {0},{1},{2}", new Object[] { pos.getX(), pos.getY(), pos.getZ() });
return EnumActionResult.SUCCESS;
}
if (LogisticsBlockGenericPipe.placePipe(pipe, worldIn, placeAt.getBlockPos(), block, orientation)) {
IBlockState state = worldIn.getBlockState(placeAt.getBlockPos());
if (state.getBlock() == block) {
// setTileEntityNBT(world, player, pos, stack);
block.onBlockPlacedBy(worldIn, pos, state, player, itemstack);
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, placeAt.getBlockPos(), itemstack);
IBlockState newBlockState = worldIn.getBlockState(placeAt.getBlockPos());
SoundType soundtype = newBlockState.getBlock().getSoundType(newBlockState, worldIn, placeAt.getBlockPos(), player);
worldIn.playSound(player, placeAt.getBlockPos(), soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
}
}
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
}
Aggregations