Search in sources :

Example 6 with CoreMultiBlockPipe

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);
}
Also used : Explosion(net.minecraft.world.Explosion) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) List(java.util.List)

Example 7 with CoreMultiBlockPipe

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;
        }
    }
}
Also used : SoundType(net.minecraft.block.SoundType) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) Getter(lombok.Getter) LogisticsPipes(logisticspipes.LogisticsPipes) EnumHand(net.minecraft.util.EnumHand) Level(org.apache.logging.log4j.Level) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) Side(net.minecraftforge.fml.relauncher.Side) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) SoundCategory(net.minecraft.util.SoundCategory) SoundType(net.minecraft.block.SoundType) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) LogisticsBlockGenericPipe(logisticspipes.pipes.basic.LogisticsBlockGenericPipe) World(net.minecraft.world.World) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) IBlockState(net.minecraft.block.state.IBlockState) LPBlocks(logisticspipes.LPBlocks) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) IIconProvider(logisticspipes.renderer.IIconProvider) TileEntity(net.minecraft.tileentity.TileEntity) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) IBlockState(net.minecraft.block.state.IBlockState) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ITubeOrientation(logisticspipes.interfaces.ITubeOrientation) TileEntity(net.minecraft.tileentity.TileEntity) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) CoreMultiBlockPipe(logisticspipes.pipes.basic.CoreMultiBlockPipe) LPPositionSet(logisticspipes.utils.LPPositionSet) Block(net.minecraft.block.Block) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

CoreMultiBlockPipe (logisticspipes.pipes.basic.CoreMultiBlockPipe)7 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)7 List (java.util.List)5 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 Explosion (net.minecraft.world.Explosion)4 ITubeOrientation (logisticspipes.interfaces.ITubeOrientation)3 CoreUnroutedPipe (logisticspipes.pipes.basic.CoreUnroutedPipe)3 LPPositionSet (logisticspipes.utils.LPPositionSet)3 Block (net.minecraft.block.Block)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 World (net.minecraft.world.World)3 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)3 DoubleCoordinatesType (network.rs485.logisticspipes.world.DoubleCoordinatesType)3 LPBlocks (logisticspipes.LPBlocks)2 LogisticsPipes (logisticspipes.LogisticsPipes)2 LogisticsBlockGenericPipe (logisticspipes.pipes.basic.LogisticsBlockGenericPipe)2 IIconProvider (logisticspipes.renderer.IIconProvider)2 Getter (lombok.Getter)2