Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1.     public void translate(Vector3i vector) {
  2.         synchronized (blockList) {
  3.             Location<?> obstructingBlock;
  4.             if ((obstructingBlock = isObstructed(vector)) != null) {
  5.                 pilot.sendMessage(Text.of("Path is obstructed at " + obstructingBlock.getPosition() + " by "
  6.                         + obstructingBlock.getBlockType()));
  7.             }
  8.             for (StarshipLocation location : blockList) {
  9.                 Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
  10.                         location.getZ());
  11.                 BlockState block = blockLocation.getBlock().copy();
  12.                 if (block.getType() == BlockTypes.AIR) {
  13.                     blockList.remove(location);
  14.                     continue;
  15.                 }
  16.                 blockList.remove(location);
  17.                 location.setX(location.getX() + vector.getX());
  18.                 location.setY(location.getY() + vector.getY());
  19.                 location.setZ(location.getZ() + vector.getZ());
  20.                 newStates.put(location, block);
  21.                 if (SignUtil.isSign(block)) {
  22.                     signs.put(location, blockLocation.get(SignData.class).get());
  23.                 }
  24.                 Optional<TileEntity> tileEntity = blockLocation.getTileEntity();
  25.                 if (tileEntity.isPresent()) {
  26.                     TileEntity entity = tileEntity.get();
  27.                     if (entity instanceof TileEntityCarrier) {
  28.                         TileEntityCarrier carrier = (TileEntityCarrier) entity;
  29.                         inventories.put(location, carrier.copy());
  30.                     }
  31.                 }
  32.                 StarshipLocation oldLocation = new StarshipLocation(blockLocation);
  33.                 pilot.getWorld().setBlockType(oldLocation.getX(), oldLocation.getY(), oldLocation.getZ(),
  34.                         BlockTypes.AIR, BlockChangeFlag.NONE,
  35.                         Cause.of(NamedCause.owner(StarshipsPlugin.getInstance().getContainer())));
  36.             }
  37.             for (StarshipLocation location : newStates.keySet()) {
  38.                 Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
  39.                         location.getZ());
  40.                 blockList.add(location);
  41.                 blockLocation.setBlock(newStates.get(location), BlockChangeFlag.NONE,
  42.                         Cause.of(NamedCause.owner(StarshipsPlugin.getInstance().getContainer())));
  43.             }
  44.             for (StarshipLocation location : signs.keySet()) {
  45.                 Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
  46.                         location.getZ());
  47.                 if (SignUtil.isSign(blockLocation.getBlock())) {
  48.                     SignData newData = signs.get(location);
  49.                     blockLocation.offer(newData);
  50.                 }
  51.             }
  52.             for (StarshipLocation location : inventories.keySet()) {
  53.                 Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
  54.                         location.getZ());
  55.                 Optional<TileEntity> tileEntity = blockLocation.getTileEntity();
  56.                 if (tileEntity.isPresent()) {
  57.                     TileEntity entity = tileEntity.get();
  58.                     entity.copyFrom(inventories.get(location));
  59.                 }
  60.             }
  61.             Vector3d velocity = pilot.getVelocity();
  62.             pilot.setLocation(pilot.getLocation().add(vector));
  63.             pilot.setVelocity(velocity);
  64.             newStates.clear();
  65.             signs.clear();
  66.             inventories.clear();
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement