Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void translate(Vector3i vector) {
- synchronized (blockList) {
- Location<?> obstructingBlock;
- if ((obstructingBlock = isObstructed(vector)) != null) {
- pilot.sendMessage(Text.of("Path is obstructed at " + obstructingBlock.getPosition() + " by "
- + obstructingBlock.getBlockType()));
- }
- for (StarshipLocation location : blockList) {
- Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
- location.getZ());
- BlockState block = blockLocation.getBlock().copy();
- if (block.getType() == BlockTypes.AIR) {
- blockList.remove(location);
- continue;
- }
- blockList.remove(location);
- location.setX(location.getX() + vector.getX());
- location.setY(location.getY() + vector.getY());
- location.setZ(location.getZ() + vector.getZ());
- newStates.put(location, block);
- if (SignUtil.isSign(block)) {
- signs.put(location, blockLocation.get(SignData.class).get());
- }
- Optional<TileEntity> tileEntity = blockLocation.getTileEntity();
- if (tileEntity.isPresent()) {
- TileEntity entity = tileEntity.get();
- if (entity instanceof TileEntityCarrier) {
- TileEntityCarrier carrier = (TileEntityCarrier) entity;
- inventories.put(location, carrier.copy());
- }
- }
- StarshipLocation oldLocation = new StarshipLocation(blockLocation);
- pilot.getWorld().setBlockType(oldLocation.getX(), oldLocation.getY(), oldLocation.getZ(),
- BlockTypes.AIR, BlockChangeFlag.NONE,
- Cause.of(NamedCause.owner(StarshipsPlugin.getInstance().getContainer())));
- }
- for (StarshipLocation location : newStates.keySet()) {
- Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
- location.getZ());
- blockList.add(location);
- blockLocation.setBlock(newStates.get(location), BlockChangeFlag.NONE,
- Cause.of(NamedCause.owner(StarshipsPlugin.getInstance().getContainer())));
- }
- for (StarshipLocation location : signs.keySet()) {
- Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
- location.getZ());
- if (SignUtil.isSign(blockLocation.getBlock())) {
- SignData newData = signs.get(location);
- blockLocation.offer(newData);
- }
- }
- for (StarshipLocation location : inventories.keySet()) {
- Location<?> blockLocation = pilot.getWorld().getLocation(location.getX(), location.getY(),
- location.getZ());
- Optional<TileEntity> tileEntity = blockLocation.getTileEntity();
- if (tileEntity.isPresent()) {
- TileEntity entity = tileEntity.get();
- entity.copyFrom(inventories.get(location));
- }
- }
- Vector3d velocity = pilot.getVelocity();
- pilot.setLocation(pilot.getLocation().add(vector));
- pilot.setVelocity(velocity);
- newStates.clear();
- signs.clear();
- inventories.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement