Java Code Examples for com.flowpowered.math.vector.Vector3i#getZ()

The following examples show how to use com.flowpowered.math.vector.Vector3i#getZ() . 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: ChunkAnvil116.java    From BlueMap with MIT License 6 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	if (blocks.length == 0) return BlockState.AIR;
	
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockIndex = y * 256 + z * 16 + x;
	int longIndex = blockIndex / blocksPerLong;
	int bitIndex = (blockIndex % blocksPerLong) * bitsPerBlock;
	
	long value = blocks[longIndex] >>> bitIndex;

	value = value & (0xFFFFFFFFFFFFFFFFL >>> -bitsPerBlock);
	
	if (value >= palette.length) {
		Logger.global.noFloodWarning("palettewarning", "Got palette value " + value + " but palette has size of " + palette.length + "! (Future occasions of this error will not be logged)");
		return BlockState.MISSING;
	}
	
	return palette[(int) value];
}
 
Example 2
Source File: ChunkAnvil112.java    From BlueMap with MIT License 6 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0
	
	int blockId = this.blocks[blockByteIndex] & 0xFF;
	
	if (this.add.length > 0) {
		blockId = blockId | (getByteHalf(this.add[blockHalfByteIndex], largeHalf) << 8);
	}
	
	int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf);
	
	String forgeIdMapping = getWorld().getForgeBlockIdMapping(blockId);
	if (forgeIdMapping != null) {
		return blockIdMapper.get(forgeIdMapping, blockId, blockData);
	} else {
		return blockIdMapper.get(blockId, blockData);
	}
}
 
Example 3
Source File: BlockUtils.java    From GriefPrevention with MIT License 6 votes vote down vote up
public static boolean clickedClaimCorner(GPClaim claim, Vector3i clickedPos) {
    int clickedX = clickedPos.getX();
    int clickedY = clickedPos.getY();
    int clickedZ = clickedPos.getZ();
    int lesserX = claim.getLesserBoundaryCorner().getBlockX();
    int lesserY = claim.getLesserBoundaryCorner().getBlockY();
    int lesserZ = claim.getLesserBoundaryCorner().getBlockZ();
    int greaterX = claim.getGreaterBoundaryCorner().getBlockX();
    int greaterY = claim.getGreaterBoundaryCorner().getBlockY();
    int greaterZ = claim.getGreaterBoundaryCorner().getBlockZ();
    if ((clickedX == lesserX || clickedX == greaterX) && (clickedZ == lesserZ || clickedZ == greaterZ)
            && (!claim.isCuboid() || (clickedY == lesserY || clickedY == greaterY))) {
        return true;
    }

    return false;
}
 
Example 4
Source File: World.java    From BlueMap with MIT License 5 votes vote down vote up
/**
 * Returns the ChunkPosition for a BlockPosition 
 */
public default Vector2i blockPosToChunkPos(Vector3i block) {
	return new Vector2i(
		block.getX() >> 4,
		block.getZ() >> 4
	);
}
 
Example 5
Source File: ChunkAnvil113.java    From BlueMap with MIT License 5 votes vote down vote up
public LightData getLightData(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0

	int blockLight = getByteHalf(this.blockLight[blockHalfByteIndex], largeHalf);
	int skyLight = getByteHalf(this.skyLight[blockHalfByteIndex], largeHalf);
	
	return new LightData(skyLight, blockLight);
}
 
Example 6
Source File: ChunkAnvil116.java    From BlueMap with MIT License 5 votes vote down vote up
@Override
public Biome getBiome(Vector3i pos) {
	int x = (pos.getX() & 0xF) / 4; // Math.floorMod(pos.getX(), 16)
	int z = (pos.getZ() & 0xF) / 4;
	int y = pos.getY() / 4;
	int biomeIntIndex = y * 16 + z * 4 + x;
	
	return biomeIdMapper.get(biomes[biomeIntIndex]);
}
 
Example 7
Source File: ParticlesUtil.java    From EagleFactions with MIT License 5 votes vote down vote up
public static Vector3d getChunkCenter(final World world, final Vector3i chunkPosition)
{
	final double x = (chunkPosition.getX() << 4) + 8;
	final double z = (chunkPosition.getZ() << 4) + 8;
	final double y = world.getHighestYAt((int)x, (int)z);
	return new Vector3d(x, y, z);
}
 
Example 8
Source File: ChunkAnvil115.java    From BlueMap with MIT License 5 votes vote down vote up
@Override
public Biome getBiome(Vector3i pos) {
	int x = (pos.getX() & 0xF) / 4; // Math.floorMod(pos.getX(), 16)
	int z = (pos.getZ() & 0xF) / 4;
	int y = pos.getY() / 4;
	int biomeIntIndex = y * 16 + z * 4 + x;
	
	return biomeIdMapper.get(biomes[biomeIntIndex]);
}
 
Example 9
Source File: ChunkAnvil115.java    From BlueMap with MIT License 5 votes vote down vote up
public BlockState getBlockState(Vector3i pos) {
	if (blocks.length == 0) return BlockState.AIR;
	
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockIndex = y * 256 + z * 16 + x;
	int index = blockIndex * bitsPerBlock;
	int firstLong = index >> 6; // index / 64
	int bitoffset = index & 0x3F; // Math.floorMod(index, 64)
	
	long value = blocks[firstLong] >>> bitoffset;
	
	if (bitoffset > 0 && firstLong + 1 < blocks.length) {
		long value2 = blocks[firstLong + 1];
		value2 = value2 << -bitoffset;
		value = value | value2;
	}
	
	value = value & (0xFFFFFFFFFFFFFFFFL >>> -bitsPerBlock);
	
	if (value >= palette.length) {
		Logger.global.noFloodWarning("palettewarning", "Got palette value " + value + " but palette has size of " + palette.length + " (Future occasions of this error will not be logged)");
		return BlockState.MISSING;
	}
	
	return palette[(int) value];
}
 
Example 10
Source File: ChunkAnvil115.java    From BlueMap with MIT License 5 votes vote down vote up
public LightData getLightData(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0

	int blockLight = getByteHalf(this.blockLight[blockHalfByteIndex], largeHalf);
	int skyLight = getByteHalf(this.skyLight[blockHalfByteIndex], largeHalf);
	
	return new LightData(skyLight, blockLight);
}
 
Example 11
Source File: ChunkAnvil112.java    From BlueMap with MIT License 5 votes vote down vote up
@Override
public Biome getBiome(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int z = pos.getZ() & 0xF;
	int biomeByteIndex = z * 16 + x;
	
	return biomeIdMapper.get(biomes[biomeByteIndex] & 0xFF);
}
 
Example 12
Source File: ChunkAnvil112.java    From BlueMap with MIT License 5 votes vote down vote up
public LightData getLightData(Vector3i pos) {
	int x = pos.getX() & 0xF; // Math.floorMod(pos.getX(), 16)
	int y = pos.getY() & 0xF;
	int z = pos.getZ() & 0xF;
	int blockByteIndex = y * 256 + z * 16 + x;
	int blockHalfByteIndex = blockByteIndex >> 1; // blockByteIndex / 2 
	boolean largeHalf = (blockByteIndex & 0x1) != 0; // (blockByteIndex % 2) == 0

	int blockLight = getByteHalf(this.blockLight[blockHalfByteIndex], largeHalf);
	int skyLight = getByteHalf(this.skyLight[blockHalfByteIndex], largeHalf);
	
	return new LightData(skyLight, blockLight);
}
 
Example 13
Source File: DataHandler.java    From Nations with MIT License 5 votes vote down vote up
public static Point getSecondPoint(UUID uuid)
{
	if (ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true))
	{
		return secondPoints.get(uuid);
	}
	Optional<Player> player = Sponge.getServer().getPlayer(uuid);
	if (!player.isPresent())
	{
		return null;
	}
	Vector3i chunk = player.get().getLocation().getChunkPosition();
	return new Point(player.get().getWorld(), chunk.getX() * 16 + 15, chunk.getZ() * 16 + 15);
}
 
Example 14
Source File: CommandClaimSpawn.java    From GriefDefender with MIT License 4 votes vote down vote up
@CommandAlias("claimspawn")
@Description("Teleports you to claim spawn if available.")
@Syntax("[name] [user]")
@Subcommand("claim spawn")
public void execute(Player player, @Optional String claimName, @Optional OfflinePlayer targetPlayer) {
    final GDPlayerData srcPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GDPlayerData targetPlayerData = null;
    if (targetPlayer != null) {
        targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), targetPlayer.getUniqueId());
    } else {
        targetPlayerData = srcPlayerData;
    }

    GDClaim claim = null;
    if (claimName != null) {
        for (Claim playerClaim : targetPlayerData.getInternalClaims()) {
            String name = null;
            Component component = playerClaim.getName().orElse(null);
            if (component != null) {
                name = PlainComponentSerializer.INSTANCE.serialize(component);
                if (claimName.equalsIgnoreCase(name)) {
                    claim = (GDClaim) playerClaim;
                    break;
                }
            }
        }
        if (claim == null) {
            GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_CLAIMNAME_NOT_FOUND,
                    ImmutableMap.of("name", claimName)));
            return;
        }
    } else {
        claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(targetPlayerData, player.getLocation());
    }

    if (!srcPlayerData.canIgnoreClaim(claim) && !claim.isUserTrusted(player, TrustTypes.ACCESSOR) && !player.hasPermission(GDPermissions.COMMAND_DELETE_CLAIMS)) {
        GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ACCESS,
                ImmutableMap.of("player", claim.getOwnerDisplayName())));
        return;
    }

    final Vector3i spawnPos = claim.getData().getSpawnPos().orElse(null);
    if (spawnPos == null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().SPAWN_NOT_SET);
        return;
    }

    final Location spawnLocation = new Location(claim.getWorld(), spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
    int teleportDelay = 0;
    if (GDOptions.isOptionEnabled(Options.PLAYER_TELEPORT_DELAY)) {
        teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim);
    }
    if (teleportDelay > 0) {
        srcPlayerData.teleportDelay = teleportDelay + 1;
        srcPlayerData.teleportLocation = spawnLocation;
        return;
    }
    player.teleport(spawnLocation);
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.SPAWN_TELEPORT,
            ImmutableMap.of(
            "location", spawnPos));
    GriefDefenderPlugin.sendMessage(player, message);
}
 
Example 15
Source File: DynmapProvider.java    From GriefDefender with MIT License 4 votes vote down vote up
private void updateClaimMarker(Claim claim, Map<String, AreaMarker> markerMap) {
    final World world = Sponge.getServer().getWorld(claim.getWorldUniqueId()).orElse(null);
    if (world == null) {
        return;
    }
    final String worldName = world.getName();
    final String owner = ((GDClaim) claim).getOwnerName();
    if (isVisible((GDClaim) claim, owner, worldName)) {
        final Vector3i lesserPos = claim.getLesserBoundaryCorner();
        final Vector3i greaterPos = claim.getGreaterBoundaryCorner();
        final double[] x = new double[4];
        final double[] z = new double[4];
        x[0] = lesserPos.getX();
        z[0] = lesserPos.getZ();
        x[1] = lesserPos.getX();
        z[1] = greaterPos.getZ() + 1.0;
        x[2] = greaterPos.getX() + 1.0;
        z[2] = greaterPos.getZ() + 1.0;
        x[3] = greaterPos.getX() + 1.0;
        z[3] = lesserPos.getZ();
        final UUID id = claim.getUniqueId();
        final String markerid = "GD_" + id;
        AreaMarker marker = this.areaMarkers.remove(markerid);
        if (marker == null) {
            marker = this.set.createAreaMarker(markerid, owner, false, worldName, x, z, false);
            if (marker == null) {
                return;
            }
        } else {
            marker.setCornerLocations(x, z);
            marker.setLabel(owner);
        }
        if (this.cfg.use3dRegions) {
            marker.setRangeY(greaterPos.getY() + 1.0, lesserPos.getY());
        }

        addOwnerStyle(owner, worldName, marker, claim);
        String desc = getWindowInfo(claim, marker);
        marker.setDescription(desc);
        markerMap.put(markerid, marker);
    }
}
 
Example 16
Source File: DynmapProvider.java    From GriefDefender with MIT License 4 votes vote down vote up
private void updateClaimMarker(Claim claim, Map<String, AreaMarker> markerMap) {
    final World world = Bukkit.getWorld(claim.getWorldUniqueId());
    if (world == null) {
        return;
    }
    final String worldName = world.getName();
    final String owner = ((GDClaim) claim).getOwnerName();
    if (isVisible((GDClaim) claim, owner, worldName)) {
        final Vector3i lesserPos = claim.getLesserBoundaryCorner();
        final Vector3i greaterPos = claim.getGreaterBoundaryCorner();
        final double[] x = new double[4];
        final double[] z = new double[4];
        x[0] = lesserPos.getX();
        z[0] = lesserPos.getZ();
        x[1] = lesserPos.getX();
        z[1] = greaterPos.getZ() + 1.0;
        x[2] = greaterPos.getX() + 1.0;
        z[2] = greaterPos.getZ() + 1.0;
        x[3] = greaterPos.getX() + 1.0;
        z[3] = lesserPos.getZ();
        final UUID id = claim.getUniqueId();
        final String markerid = "GD_" + id;
        AreaMarker marker = this.areaMarkers.remove(markerid);
        if (marker == null) {
            marker = this.set.createAreaMarker(markerid, owner, false, worldName, x, z, false);
            if (marker == null) {
                return;
            }
        } else {
            marker.setCornerLocations(x, z);
            marker.setLabel(owner);
        }
        if (this.cfg.use3dRegions) {
            marker.setRangeY(greaterPos.getY() + 1.0, lesserPos.getY());
        }

        addOwnerStyle(owner, worldName, marker, claim);
        String desc = getWindowInfo(claim, marker);
        marker.setDescription(desc);
        markerMap.put(markerid, marker);
    }
}
 
Example 17
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onExplosionPrimeEvent(ExplosionPrimeEvent event) {
    final World world = event.getEntity().getLocation().getWorld();
    final Entity source = event.getEntity();
    if (!GDFlags.EXPLOSION_BLOCK && !GDFlags.EXPLOSION_ENTITY) {
        return;
    }
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }
    if (source instanceof Creeper || source instanceof EnderCrystal) {
        return;
    }

    GDCauseStackManager.getInstance().pushCause(source);
    GDTimings.ENTITY_EXPLOSION_PRE_EVENT.startTiming();
    final GDEntity gdEntity = EntityTracker.getCachedEntity(source.getEntityId());
    GDPermissionUser user = null;
    if (gdEntity != null) {
        user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
    }

    final Location location = event.getEntity().getLocation();
    final GDClaim radiusClaim = NMSUtil.getInstance().createClaimFromCenter(location, event.getRadius());
    final GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
    final Set<Claim> surroundingClaims = claimManager.findOverlappingClaims(radiusClaim);
    if (surroundingClaims.size() == 0) {
        GDTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTiming();
        return;
    }
    for (Claim claim : surroundingClaims) {
        // Use any location for permission check
        final Vector3i pos = claim.getLesserBoundaryCorner();
        Location targetLocation = new Location(location.getWorld(), pos.getX(), pos.getY(), pos.getZ());
        Tristate blockResult = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.EXPLOSION_BLOCK, source, targetLocation, user, true);
        if (blockResult == Tristate.FALSE) {
            // Check explosion entity
            if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.EXPLOSION_ENTITY, source, targetLocation, user, true) == Tristate.FALSE) {
                event.setCancelled(true);
                break;
            }
        }
    }
    GDTimings.ENTITY_EXPLOSION_PRE_EVENT.stopTiming();
}
 
Example 18
Source File: Vector3iParamConverter.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public String toString(Vector3i value) {
    return value.getX() + "|" + value.getY() + "|" + value.getZ();
}
 
Example 19
Source File: WorldEditApiProvider.java    From GriefPrevention with MIT License 4 votes vote down vote up
public Vector createVector(Vector3i point) {
    return new Vector(point.getX(), point.getY(), point.getZ());
}
 
Example 20
Source File: CommandClaimSpawn.java    From GriefDefender with MIT License 4 votes vote down vote up
@CommandAlias("claimspawn")
@Description("Teleports you to claim spawn if available.")
@Syntax("[name] [user]")
@Subcommand("claim spawn")
public void execute(Player player, @Optional String claimName, @Optional User targetPlayer) {
    final GDPlayerData srcPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GDPlayerData targetPlayerData = null;
    if (targetPlayer != null) {
        targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), targetPlayer.getUniqueId());
    } else {
        targetPlayerData = srcPlayerData;
    }

    GDClaim claim = null;
    if (claimName != null) {
        for (Claim playerClaim : targetPlayerData.getInternalClaims()) {
            String name = null;
            Component component = playerClaim.getName().orElse(null);
            if (component != null) {
                name = PlainComponentSerializer.INSTANCE.serialize(component);
                if (claimName.equalsIgnoreCase(name)) {
                    claim = (GDClaim) playerClaim;
                    break;
                }
            }
        }
        if (claim == null) {
            GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.COMMAND_CLAIMNAME_NOT_FOUND,
                    ImmutableMap.of("name", claimName)));
            return;
        }
    } else {
        claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(targetPlayerData, player.getLocation());
    }

    if (!srcPlayerData.canIgnoreClaim(claim) && !claim.isUserTrusted(player, TrustTypes.ACCESSOR) && !player.hasPermission(GDPermissions.COMMAND_DELETE_CLAIMS)) {
        GriefDefenderPlugin.sendMessage(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ACCESS,
                ImmutableMap.of("player", claim.getOwnerDisplayName())));
        return;
    }

    final Vector3i spawnPos = claim.getData().getSpawnPos().orElse(null);
    if (spawnPos == null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().SPAWN_NOT_SET);
        return;
    }

    final Location<World> spawnLocation = new Location<>(claim.getWorld(), spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
    int teleportDelay = 0;
    if (GDOptions.isOptionEnabled(Options.PLAYER_TELEPORT_DELAY)) {
        teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim);
    }
    if (teleportDelay > 0) {
        srcPlayerData.teleportDelay = teleportDelay + 1;
        srcPlayerData.teleportLocation = spawnLocation;
        return;
    }
    player.setLocation(spawnLocation);
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.SPAWN_TELEPORT,
            ImmutableMap.of(
            "location", spawnPos));
    GriefDefenderPlugin.sendMessage(player, message);
}