Java Code Examples for com.sk89q.worldedit.math.BlockVector3#getBlockX()

The following examples show how to use com.sk89q.worldedit.math.BlockVector3#getBlockX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionCommand.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
private void showRegion(Player player, int y, BlockVector3 minP, BlockVector3 maxP) {
    World world = player.getWorld();
    List<Location> points = new ArrayList<>();
    for (int x = minP.getBlockX(); x <= maxP.getBlockX(); x+=dash) {
        points.add(new Location(world, x+0.5d, y, minP.getBlockZ()+0.5d));
    }
    for (int z = minP.getBlockZ(); z <= maxP.getBlockZ(); z+=dash) {
        points.add(new Location(world, maxP.getBlockX()+0.5d, y, z+0.5d));
    }
    for (int x = maxP.getBlockX(); x >= minP.getBlockX(); x-=dash) {
        points.add(new Location(world, x+0.5d, y, maxP.getBlockZ()+0.5d));
    }
    for (int z = maxP.getBlockZ(); z >= minP.getBlockZ(); z-=dash) {
        points.add(new Location(world, minP.getBlockX()+0.5d, y, z+0.5d));
    }
    addAnimation(player, points);
}
 
Example 2
Source File: WorldGuardSevenCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public void doUnloadChunkFlagCheck(org.bukkit.World world)
{
	for (ProtectedRegion region : this.getRegionContainer().get(world).getRegions().values())
	{
		if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY)
		{
			System.out.println("Loading chunks for region " + region.getId() + " located in " + world.getName() + " due to chunk-unload flag being deny");
			
			BlockVector3 min = region.getMinimumPoint();
			BlockVector3 max = region.getMaximumPoint();

			for(int x = min.getBlockX() >> 4; x <= max.getBlockX() >> 4; x++)
			{
				for(int z = min.getBlockZ() >> 4; z <= max.getBlockZ() >> 4; z++)
				{
					world.getChunkAt(x, z).load(true);
					
					if (WorldGuardSevenCommunicator.supportsForceLoad)
					{
						world.getChunkAt(x, z).setForceLoaded(true);
					}
				}
			}
		}
	}
}
 
Example 3
Source File: Spigot_v1_16_R1.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) {
    CraftWorld craftWorld = (CraftWorld) world;
    WorldServer worldServer = craftWorld.getHandle();
    ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack
            ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1)));
    stack.setTag((NBTTagCompound) fromNative(item.getNbtData()));

    FakePlayer_v1_16_R1 fakePlayer;
    try {
        fakePlayer = fakePlayers.get(worldServer);
    } catch (ExecutionException ignored) {
        return false;
    }
    fakePlayer.a(EnumHand.MAIN_HAND, stack);
    fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(),
            (float) face.toVector().toYaw(), (float) face.toVector().toPitch());

    final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    final Vec3D blockVec = Vec3D.b(blockPos);
    final EnumDirection enumFacing = adapt(face);
    MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false);
    ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace);
    EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND);
    if (result != EnumInteractionResult.SUCCESS) {
        if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace).a()) {
            result = EnumInteractionResult.SUCCESS;
        } else {
            result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a();
        }
    }

    return result == EnumInteractionResult.SUCCESS;
}
 
Example 4
Source File: Spigot_v1_15_R2.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) {
    CraftWorld craftWorld = (CraftWorld) world;
    WorldServer worldServer = craftWorld.getHandle();
    ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack
            ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1)));
    stack.setTag((NBTTagCompound) fromNative(item.getNbtData()));

    FakePlayer_v1_15_R2 fakePlayer;
    try {
        fakePlayer = fakePlayers.get(worldServer);
    } catch (ExecutionException ignored) {
        return false;
    }
    fakePlayer.a(EnumHand.MAIN_HAND, stack);
    fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(),
            (float) face.toVector().toYaw(), (float) face.toVector().toPitch());

    final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    final Vec3D blockVec = new Vec3D(blockPos);
    final EnumDirection enumFacing = adapt(face);
    MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false);
    ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace);
    EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND);
    if (result != EnumInteractionResult.SUCCESS) {
        if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace).a()) {
            result = EnumInteractionResult.SUCCESS;
        } else {
            result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a();
        }
    }

    return result == EnumInteractionResult.SUCCESS;
}
 
Example 5
Source File: Spigot_v1_14_R4.java    From worldedit-adapters with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) {
    CraftWorld craftWorld = (CraftWorld) world;
    WorldServer worldServer = craftWorld.getHandle();
    ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack
            ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1)));
    stack.setTag((NBTTagCompound) fromNative(item.getNbtData()));

    FakePlayer_v1_14_R4 fakePlayer;
    try {
        fakePlayer = fakePlayers.get(worldServer);
    } catch (ExecutionException ignored) {
        return false;
    }
    fakePlayer.a(EnumHand.MAIN_HAND, stack);
    fakePlayer.setLocation(position.getBlockX(), position.getBlockY(), position.getBlockZ(),
            (float) face.toVector().toYaw(), (float) face.toVector().toPitch());

    final BlockPosition blockPos = new BlockPosition(position.getBlockX(), position.getBlockY(), position.getBlockZ());
    final Vec3D blockVec = new Vec3D(blockPos);
    final EnumDirection enumFacing = adapt(face);
    MovingObjectPositionBlock rayTrace = new MovingObjectPositionBlock(blockVec, enumFacing, blockPos, false);
    ItemActionContext context = new ItemActionContext(fakePlayer, EnumHand.MAIN_HAND, rayTrace);
    EnumInteractionResult result = stack.placeItem(context, EnumHand.MAIN_HAND);
    if (result != EnumInteractionResult.SUCCESS) {
        if (worldServer.getType(blockPos).interact(worldServer, fakePlayer, EnumHand.MAIN_HAND, rayTrace)) {
            result = EnumInteractionResult.SUCCESS;
        } else {
            result = stack.getItem().a(worldServer, fakePlayer, EnumHand.MAIN_HAND).a();
        }
    }

    return result == EnumInteractionResult.SUCCESS;
}
 
Example 6
Source File: WorldEditHandler.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of regions covering the borders of the original region.
 * <b>Note:</b> complements the #getInnerChunks
 *
 * <pre>
 *     ^
 *     |           +---+---+---+---+---+---+
 *     |           |   |   |   |   |   |   |
 *     |           |   |   |   |   |   |   |
 *     |           +---+---+---+---+---+---+
 *     |         l |   | D=======C |   |   |
 *     |           |   | I |   | I |   |   |
 *     |         k +---+-I-R---Q-I-+---+---+
 *     |           |   | I |   | I |   |   |
 *     |           |   | I |   | I |   |   |
 *     |         j +---+-I-O---P-I-+---+---+
 *     |           |   | I |   | I |   |   |
 *     |         i |   | A=======B |   |   |
 *     |           +---+---+---+---+---+---+
 *     |                 a b   c d
 *     +----------------------------------------->
 *
 * Points:
 *     A = (a,i)
 *     B = (d,i)
 *     C = (d,l)
 *     D = (a,l)
 *
 *     M(x) = X mod 16, i.e. Mc = C mod 16.
 *
 * Borders:
 *     O = A + 16 - Ma   | A > 0
 *       = A - Ma        | A <= 0
 *
 *     Q = C - Mc - 1    | C > 0 && Mc != 15
 *       = C + Mc - 16   | C < 0 && Mc != -1
 * </pre>
 */
public static Set<Region> getBorderRegions(Region region) {
    Set<Region> borders = new HashSet<>();
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 max = region.getMaximumPoint();
    int minY = min.getBlockY();
    int maxY = max.getBlockY();
    int minX = min.getBlockX();
    int maxX = max.getBlockX();
    int minZ = min.getBlockZ();
    int maxZ = max.getBlockZ();

    int minModX = minX % 16;
    int maxModX = maxX % 16;
    int minModZ = minZ % 16;
    int maxModZ = maxZ % 16;
    // Negative values are aligned differently than positive values
    int minChunkX = minModX > 0 ? minX + 16 - minModX : minX - minModX;
    int maxChunkX = maxModX >= 0 && maxModX != 15 ? maxX - maxModX - 1 : maxModX < 0 && maxModX != -1 ? maxX - 16 + maxModX : maxX;
    int minChunkZ = minModZ > 0 ? minZ + 16 - minModZ : minZ - minModZ;
    int maxChunkZ = maxModZ >= 0 && maxModZ != 15 ? maxZ - maxModZ - 1 : maxModZ < 0 && maxModZ != -1 ? maxZ - 16 + maxModZ : maxZ;
    // min < minChunk < maxChunk < max
    if (minModX != 0) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(minX, minY, minZ),
                BlockVector3.at(minChunkX - 1, maxY, maxZ)));
    }
    if (maxModZ != 15 && maxModZ != -1) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(minChunkX, minY, maxChunkZ + 1),
                BlockVector3.at(maxChunkX, maxY, maxZ)));
    }
    if (maxModX != 15 && maxModX != -1) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(maxChunkX + 1, minY, minZ),
                BlockVector3.at(maxX, maxY, maxZ)));
    }
    if (minModZ != 0) {
        borders.add(new CuboidRegion(region.getWorld(),
                BlockVector3.at(minChunkX, minY, minZ),
                BlockVector3.at(maxChunkX, maxY, minChunkZ - 1)));
    }
    return borders;
}