Java Code Examples for org.bukkit.util.Vector#subtract()

The following examples show how to use org.bukkit.util.Vector#subtract() . 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: DuctListener.java    From Transport-Pipes with MIT License 6 votes vote down vote up
private void setDirectionalBlockFace(Location b, BlockData bd, Player p) {
    if (bd instanceof Directional) {
        Vector dir = new Vector(b.getX() + 0.5d, b.getY() + 0.5d, b.getZ() + 0.5d);
        dir.subtract(p.getEyeLocation().toVector());
        double absX = Math.abs(dir.getX());
        double absY = Math.abs(dir.getY());
        double absZ = Math.abs(dir.getZ());
        if (((Directional) bd).getFaces().contains(BlockFace.UP) && ((Directional) bd).getFaces().contains(BlockFace.DOWN)) {
            if (absX >= absY && absX >= absZ) {
                ((Directional) bd).setFacing(dir.getX() > 0 ? BlockFace.WEST : BlockFace.EAST);
            } else if (absY >= absX && absY >= absZ) {
                ((Directional) bd).setFacing(dir.getY() > 0 ? BlockFace.DOWN : BlockFace.UP);
            } else {
                ((Directional) bd).setFacing(dir.getZ() > 0 ? BlockFace.NORTH : BlockFace.SOUTH);
            }
        } else {
            if (absX >= absZ) {
                ((Directional) bd).setFacing(dir.getX() > 0 ? BlockFace.WEST : BlockFace.EAST);
            } else {
                ((Directional) bd).setFacing(dir.getZ() > 0 ? BlockFace.NORTH : BlockFace.SOUTH);
            }
        }
    }
}
 
Example 2
Source File: AABB.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public boolean overlaps(AABB other) {		
	if (other == null) {
		return false;
	}
	
	//this.showDebugBlocks(ItemManager.getId(Material.DIAMOND_BLOCK), ItemManager.getId(Material.DIAMOND_BLOCK));
	//other.showDebugBlocks(ItemManager.getId(Material.GOLD_BLOCK), ItemManager.getId(Material.GOLD_BLOCK));

	Vector t = new Vector();
	t.copy(other.getPosition());
	t.subtract(getPosition());
			
	return (Math.abs(t.getX()) < (getExtents().getX() + other.getExtents().getX()) &&
			Math.abs(t.getY()) < (getExtents().getY() + other.getExtents().getY()) &&
			Math.abs(t.getZ()) < (getExtents().getZ() + other.getExtents().getZ()));
}
 
Example 3
Source File: NoEntryExpansion.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Vector getVector(Location fromLoc, Location toLoc) {
    if(fromLoc == null || toLoc == null) return null;

    Vector fromVec = fromLoc.toVector();
    Vector toVec = toLoc.toVector();

    Vector subtract = fromVec.subtract(toVec);
    Vector normal = subtract.normalize();

    NoEntryHandler handler = getNoEntryHandler();
    double strength = handler.getNoEntryKnockbackStrength();
    Vector multiply = normal.multiply(strength);

    return makeFinite(multiply);
}
 
Example 4
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (event == null || !terraformEnabled) {
        return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();
    if (!plugin.getWorldManager().isSkyNether(block.getWorld()) || !plugin.getWorldManager().isSkyNether(player.getWorld())) {
        return; // Bail out, not our problem
    }
    if (player.getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    if (!plugin.playerIsOnIsland(player)) {
        return;
    }
    if (!terraFormMap.containsKey(block.getType())) {
        return; // Not a block we terra-form on.
    }
    // TODO: 10/07/2016 - R4zorax: Handle dual-wielding (would break 1.8 compatibility)
    ItemStack tool = event.getPlayer().getItemInHand();
    if (event.getBlock().getDrops(tool).isEmpty()) {
        return; // Only terra-form when stuff is mined correctly
    }
    double toolWeight = getToolWeight(tool);
    Location playerLocation = player.getEyeLocation();
    Location blockLocation = LocationUtil.centerInBlock(block.getLocation());
    Vector v = new Vector(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ());
    v.subtract(new Vector(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()));
    v.normalize();
    // Disable spawning above the player... enabling the player to clear a region
    if (playerLocation.getPitch() >= minPitch && playerLocation.getPitch() <= maxPitch) {
        ProtectedCuboidRegion islandRegion = WorldGuardHandler.getIslandRegion(playerLocation);
        List<Material> yield = getYield(block.getType(), toolWeight);
        for (Material mat : yield) {
            spawnBlock(mat, blockLocation, v, islandRegion);
        }
    }
}