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;
}
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);
}
}
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;
}
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;
}
}
}
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);
}
Aggregations