SmushyTaco

Untitled

Nov 12th, 2025
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1.     protected boolean canPushLine(World world, int x, int y, int z, Direction direction, int maxPushedBlocks) {
  2.         int xo = x + direction.getOffsetX();
  3.         int yo = y + direction.getOffsetY();
  4.         int zo = z + direction.getOffsetZ();
  5.         int blocks = 0;
  6.         boolean didCrush = false;
  7.  
  8.         while(true) {
  9.             if (blocks < maxPushedBlocks + 1) {
  10.                 if (yo < 0 || yo >= world.getHeightBlocks()) {
  11.                     return false;
  12.                 }
  13.  
  14.                 int id = world.getBlockId(xo, yo, zo);
  15.                 if (id != 0) {
  16.                     if (!this.isPushable(id, world, xo, yo, zo, true)) {
  17.                         if (blocks != 1 || !BlockTags.PISTON_CRUSHING.appliesTo(Blocks.getBlock(id)) || !this.tryCrush(world, x, y, z, direction)) {
  18.                             return false;
  19.                         }
  20.  
  21.                         didCrush = true;
  22.                     } else if (Blocks.blocksList[id].getPistonPushReaction(world, xo, yo, zo) != 1) {
  23.                         if (blocks == maxPushedBlocks) {
  24.                             return false;
  25.                         }
  26.  
  27.                         xo += direction.getOffsetX();
  28.                         yo += direction.getOffsetY();
  29.                         zo += direction.getOffsetZ();
  30.                         ++blocks;
  31.                         continue;
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             if (!didCrush && blocks == 1) {
  37.                 xo = x + direction.getOffsetX();
  38.                 yo = y + direction.getOffsetY();
  39.                 zo = z + direction.getOffsetZ();
  40.                 Block<?> block = world.getBlock(xo, yo, zo);
  41.                 if (block == null) {
  42.                     return true;
  43.                 }
  44.  
  45.                 int blockMeta = world.getBlockMetadata(xo, yo, zo);
  46.                 TileEntity tileEntity = world.getTileEntity(xo, yo, zo);
  47.                 world.removeBlockTileEntity(xo, yo, zo);
  48.                 world.setBlockWithNotify(xo, yo, zo, 0);
  49.                 if (!world.isClientSide) {
  50.                     EntityFallingBlock entityFallingBlock = new EntityFallingBlock(world, (double)xo + (double)0.5F, (double)yo + (double)0.5F, (double)zo + (double)0.5F, block.id(), blockMeta, tileEntity);
  51.                     entityFallingBlock.hasRemovedBlock = true;
  52.                     if (tileEntity instanceof IVehicle) {
  53.                         Entity rider = ((IVehicle)tileEntity).getPassenger();
  54.                         ((IVehicle)tileEntity).ejectRider();
  55.                         if (rider != null) {
  56.                             rider.startRiding(entityFallingBlock);
  57.                         }
  58.                     }
  59.  
  60.                     world.entityJoinedWorld(entityFallingBlock);
  61.                     double speed = (double)2.0F;
  62.                     entityFallingBlock.fling((double)direction.getOffsetX() * (double)2.0F, (double)direction.getOffsetY() * (double)2.0F, (double)direction.getOffsetZ() * (double)2.0F, 1.0F);
  63.                     this.flungBlock = entityFallingBlock;
  64.                 }
  65.             }
  66.  
  67.             return true;
  68.         }
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment