@Override public DataView update(DataView content) { if (!content.contains(Home.WORLD_QUERY, Home.POSITION_QUERY)) { throw new InvalidDataException("Invalid data for a home!"); } UUID uuid = content.getObject(Home.WORLD_QUERY, UUID.class).get(); Vector3d pos = content.getObject(Home.POSITION_QUERY, Vector3d.class).get(); String name = Sponge.getServer().getWorldProperties(uuid) .map(WorldProperties::getWorldName) .orElse(uuid.toString().substring(0, 9)); name = String.format("%s-%d,%d,%d", name, pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()); content.set(Home.NAME_QUERY, name); return content; } }
public static Collection<Entity> getNearbyEntities(Location<World> location, Vector3d radius) { int chunkRadiusX = radius.getFloorX() < 16 ? 1 : radius.getFloorX() / 16; int chunkRadiusZ = radius.getFloorZ() < 16 ? 1 : radius.getFloorZ() / 16; HashSet<Entity> radiusEntities = new HashSet<>(); for (int chX = 0 - chunkRadiusX; chX <= chunkRadiusX; chX++) { for (int chZ = 0 - chunkRadiusZ; chZ <= chunkRadiusZ; chZ++) { int offChunkX = location.getChunkPosition().getX() + chX; int offChunkZ = location.getChunkPosition().getZ() + chZ; location.getExtent().getChunk(offChunkX, 0, offChunkZ).ifPresent(chunk -> { for (Entity e : chunk.getEntities()) { if (e == null || e.isRemoved()) { continue; } if (isWithinRadius(location, e.getLocation(), radius)) { radiusEntities.add(e); } } }); } } return radiusEntities; }
@Listener public void onVehicleMove(MoveEntityEvent event, @Getter("getTargetEntity") Minecart minecart) { if (event.getFromTransform().getPosition().distanceSquared(event.getToTransform().getPosition()) > 2 * 2) { return; } CartMechanismBlocks.findByRail(minecart.getLocation()).filter(this::isValid).ifPresent(cartMechanismBlocks -> { Vector3d from = event.getFromTransform().getPosition(); Vector3d to = event.getToTransform().getPosition(); boolean minor = from.getFloorX() == to.getFloorX() && from.getFloorY() == to.getFloorY() && from.getFloorZ() == to.getFloorZ(); impact(minecart, cartMechanismBlocks, minor); }); }
@Override public String getLink() { return Constants.BASE_PATH + "/tile-entity/" + location.getWorld().getUUID() + "/" + location.getPosition().getFloorX() + "/" + location.getPosition().getFloorY() + "/" + location.getPosition().getFloorZ(); } }
public static Location<World> parseBlockLocation(Sign sign, String line, LocationCheckType relative) { Location<World> target = SignUtil.getBackBlock(sign.getLocation()); if (line.contains("!")) relative = LocationCheckType.getTypeFromChar('!'); else if (line.contains("^")) relative = LocationCheckType.getTypeFromChar('^'); else if (line.contains("&")) relative = LocationCheckType.getTypeFromChar('&'); Vector3d offsets = new Vector3d(0,0,0); try { offsets = parseUnsafeBlockLocation(line); } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) { } if(offsets.getFloorX() == 0 && offsets.getFloorY() == 0 && offsets.getFloorZ() == 0) return target; switch (relative) { case RELATIVE: target = LocationUtil.getRelativeOffset(sign.getLocation(), offsets.getFloorX(), offsets.getFloorY(), offsets.getFloorZ()); break; case OFFSET: target = LocationUtil.getOffset(target, offsets.getFloorX(), offsets.getFloorY(), offsets.getFloorZ()); break; case ABSOLUTE: target = target.getExtent().getLocation(offsets.getX(), offsets.getY(), offsets.getZ()); break; } return target; }
@Override public void trigger() { if (getPinSet().getInput(0, this)) { for (int x = -radius.getFloorX() + 1; x < radius.getFloorX(); x++) { for (int y = -radius.getFloorY() + 1; y < radius.getFloorY(); y++) { for (int z = -radius.getFloorZ() + 1; z < radius.getFloorZ(); z++) { int rx = center.getBlockX() - x; int ry = center.getBlockY() - y; int rz = center.getBlockZ() - z; Location<World> b = getBlock().getExtent().getLocation(rx, ry, rz); if(b.getBlockType() != BlockTypes.AIR && ThreadLocalRandom.current().nextInt(100) <= chance) { Lightning lightning = (Lightning) b.getExtent().createEntity(EntityTypes.LIGHTNING, b.getPosition()); b.getExtent().spawnEntity(lightning); } } } } } }
public static boolean isWithinRadius(Location<World> location1, Location<World> location2, Vector3d radius) { return radius.getX() == radius.getZ() && radius.getX() == radius.getY() && isWithinSphericalRadius(location1, location2, radius.getFloorX()) || (radius.getX() != radius.getY() || radius.getY() != radius.getZ() || radius.getX() != radius.getZ()) && isWithinRadiusPolygon(location1, location2, radius); }
private void linePowder(final SnipeData v) { Vector3d target = this.targetBlock.getBlockPosition().toDouble().add(0.5, 0.5, 0.5); Vector3d dir = target.sub(this.origin); double dist = target.distance(this.origin); this.undo = new Undo((int) (dist + 2)); BlockRay<World> ray = BlockRay.from(this.world, this.origin).distanceLimit(dist).direction(dir).build(); perform(v, this.origin.getFloorX(), this.origin.getFloorY(), this.origin.getFloorZ()); while (ray.hasNext()) { Vector3i pos = ray.next().getBlockPosition(); perform(v, pos.getX(), pos.getY(), pos.getZ()); } if (this.continuous) { this.origin = target; } v.owner().storeUndo(this.undo); this.undo = null; }
buffer.set(x + rot.getFloorX(), y + rot.getFloorY(), z + rot.getFloorZ(), this.world.getBlock(x0, y0, z0));