@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; } }
@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); } } } } } }
@Listener public void onEntityMove(MoveEntityEvent event) { Vector3d fromPosition = event.getFromTransform().getPosition(); Vector3d toPosition = event.getToTransform().getPosition(); if(Math.abs(toPosition.getY() - fromPosition.getY()) > sensitivity.getValue() && fromPosition.getY() - fromPosition.getFloorY() < 0.25) { Location<World> block = event.getFromTransform().getLocation().getRelative(Direction.DOWN); if (BlockUtil.doesStatePassFilters(allowedBlocks.getValue(), block.getBlock())) { Location<World> signBlock = block.getRelative(Direction.DOWN); if (SignUtil.isSign(signBlock)) { Sign sign = (Sign) signBlock.getTileEntity().get(); if (isMechanicSign(sign)) { doAction(event.getTargetEntity(), SignUtil.getTextRaw(sign, 2), event.getToTransform().getRotation()); } } } else { for (Map.Entry<SpongeBlockFilter, String> blockFilterStringEntry : autoBlocks.getValue().entrySet()) { if (blockFilterStringEntry.getKey().getApplicableBlocks().contains(block.getBlock())) { doAction(event.getTargetEntity(), blockFilterStringEntry.getValue(), event.getToTransform().getRotation()); } } } } }
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));