Search in sources :

Example 81 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class HSTubeSpeedup method getConnectedEndTile.

@Override
public TileEntity getConnectedEndTile(EnumFacing output) {
    if (orientation.dir1 == output) {
        DoubleCoordinates pos = new DoubleCoordinates(0, 0, -3);
        LPPositionSet<DoubleCoordinates> set = new LPPositionSet<>(DoubleCoordinates.class);
        set.add(pos);
        orientation.rotatePositions(set);
        TileEntity subTile = pos.add(getLPPosition()).getTileEntity(getWorld());
        if (subTile instanceof LogisticsTileGenericSubMultiBlock) {
            return ((LogisticsTileGenericSubMultiBlock) subTile).getTile(output);
        }
    } else if (orientation.dir1.getOpposite() == output) {
        return container.getTile(output);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LPPositionSet(logisticspipes.utils.LPPositionSet) LogisticsTileGenericSubMultiBlock(logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 82 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class HSTubeSpeedup method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(List<AxisAlignedBB> arraylist, AxisAlignedBB axisalignedbb) {
    DoubleCoordinates pos = getLPPosition();
    DoubleCoordinates posMin = new DoubleCoordinates(LPConstants.PIPE_MIN_POS, LPConstants.PIPE_MIN_POS, LPConstants.PIPE_MIN_POS);
    DoubleCoordinates posMax = new DoubleCoordinates(LPConstants.PIPE_MAX_POS, LPConstants.PIPE_MAX_POS, -3);
    orientation.rotatePositions(posMin);
    orientation.rotatePositions(posMax);
    if (orientation == SpeedupDirection.EAST) {
        pos.add(new DoubleCoordinates(1, 0, 0));
    } else if (orientation == SpeedupDirection.SOUTH) {
        pos.add(new DoubleCoordinates(1, 0, 1));
    } else if (orientation == SpeedupDirection.WEST) {
        pos.add(new DoubleCoordinates(0, 0, 1));
    }
    posMin.add(pos);
    posMax.add(pos);
    LPPositionSet<DoubleCoordinates> set = new LPPositionSet<>(DoubleCoordinates.class);
    set.add(posMin);
    set.add(posMax);
    AxisAlignedBB box = set.toABB();
    if (box != null && (axisalignedbb == null || axisalignedbb.intersects(box))) {
        arraylist.add(box);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 83 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class HSTubeSpeedup method getItemRenderPos.

@Override
public DoubleCoordinates getItemRenderPos(float fPos, LPTravelingItem travelItem) {
    DoubleCoordinates pos = new DoubleCoordinates(0.5D, 0.5D, 0.5D);
    float pPos = fPos;
    if (travelItem.input.getOpposite() == orientation.dir1) {
        CoordinateUtils.add(pos, orientation.dir1, 3);
        pPos = this.getPipeLength() - fPos;
    }
    if (pPos < 0.5) {
        if (travelItem.input == null) {
            return null;
        }
        if (!container.renderState.pipeConnectionMatrix.isConnected(travelItem.input.getOpposite())) {
            return null;
        }
        CoordinateUtils.add(pos, travelItem.input.getOpposite(), 0.5 - fPos);
    } else {
        if (travelItem.output == null) {
            return null;
        }
        CoordinateUtils.add(pos, travelItem.output, fPos - 0.5);
    }
    return pos;
}
Also used : DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 84 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates 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)

Example 85 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method removePipe.

public static void removePipe(CoreUnroutedPipe pipe) {
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return;
    }
    if (pipe.canBeDestroyed() || pipe.destroyByPlayer()) {
        pipe.onBlockRemoval();
    } else if (pipe.preventRemove()) {
        LogisticsBlockGenericPipe.cacheTileToPreventRemoval(pipe);
    }
    World world = pipe.container.getWorld();
    if (LogisticsBlockGenericPipe.lastRemovedDate != world.getTotalWorldTime()) {
        LogisticsBlockGenericPipe.lastRemovedDate = world.getTotalWorldTime();
        LogisticsBlockGenericPipe.pipeRemoved.clear();
        LogisticsBlockGenericPipe.pipeSubMultiRemoved.clear();
    }
    if (pipe.isMultiBlock()) {
        if (pipe.preventRemove()) {
            throw new UnsupportedOperationException("A multi block can't be protected against removal.");
        }
        LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> list = ((CoreMultiBlockPipe) pipe).getRotatedSubBlocks();
        list.forEach(pos -> pos.add(new DoubleCoordinates(pipe)));
        for (DoubleCoordinates pos : pipe.container.subMultiBlock) {
            TileEntity tile = pos.getTileEntity(world);
            if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> equ = list.findClosest(pos);
                if (equ != null) {
                    ((LogisticsTileGenericSubMultiBlock) tile).removeSubType(equ.getType());
                }
                if (((LogisticsTileGenericSubMultiBlock) tile).removeMainPipe(new DoubleCoordinates(pipe))) {
                    LogisticsBlockGenericSubMultiBlock.redirectedToMainPipe = true;
                    pos.setBlockToAir(world);
                    LogisticsBlockGenericSubMultiBlock.redirectedToMainPipe = false;
                    LogisticsBlockGenericPipe.pipeSubMultiRemoved.put(new DoubleCoordinates(pos), pipe.container.getPos());
                } else {
                    MainProxy.sendPacketToAllWatchingChunk(tile, ((LogisticsTileGenericSubMultiBlock) tile).getLPDescriptionPacket());
                }
            }
        }
    }
    BlockPos pos = pipe.container.getPos();
    LogisticsBlockGenericPipe.pipeRemoved.put(new DoubleCoordinates(pos), pipe);
    world.removeTileEntity(pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Aggregations

DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)94 TileEntity (net.minecraft.tileentity.TileEntity)57 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)22 LPPositionSet (logisticspipes.utils.LPPositionSet)19 ArrayList (java.util.ArrayList)17 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)15 EnumFacing (net.minecraft.util.EnumFacing)14 ItemStack (net.minecraft.item.ItemStack)12 World (net.minecraft.world.World)12 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)11 Block (net.minecraft.block.Block)11 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)10 SideOnly (cpw.mods.fml.relauncher.SideOnly)7 List (java.util.List)7 DoubleCoordinatesType (network.rs485.logisticspipes.world.DoubleCoordinatesType)7 ILPTEInformation (logisticspipes.asm.te.ILPTEInformation)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 DockingStation (buildcraft.api.robots.DockingStation)5