Java Code Examples for org.bukkit.Location#toVector()

The following examples show how to use org.bukkit.Location#toVector() . 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: ServerUtils.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
public static AABB[] getBlockCollisionBoxesAsyncClientSide(Location loc, HawkPlayer pp) {
    if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4)) {
        ClientBlock cb = pp.getClientBlocks().get(loc);
        if (cb == null) {
            return WrappedBlock.getWrappedBlock(loc.getBlock(), pp.getClientVersion()).getCollisionBoxes();
        }

        AABB[] result = {null};
        if (cb.getMaterial().isSolid()) {
            //It would be nice if I can manage to get the correct bounding boxes for a hypothetical block.
            //Bounding boxes depend on the data of the block. Unfortunately, data isn't stored in NMS
            //Block; it's stored in NMS World. So, I'd need to "set" the block on the main thread, but
            //that literally defeats the purpose of this method. My checks NEED this utility on the
            //network thread WHILE the player is placing blocks.
            result[0] = new AABB(loc.toVector(), loc.toVector().clone().add(new Vector(1, 1, 1)));
            return result;
        }
        result[0] = new AABB(new Vector(0, 0, 0), new Vector(0, 0, 0));
        return result;
    }
    return null;
}
 
Example 2
Source File: BlockInteractDirection.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void check(InteractWorldEvent e) {
    Player p = e.getPlayer();
    HawkPlayer pp = e.getHawkPlayer();
    Location bLoc = e.getTargetedBlockLocation();
    Vector pos;
    if(pp.isInVehicle()) {
        pos = hawk.getLagCompensator().getHistoryLocation(ServerUtils.getPing(p), p).toVector();
        pos.setY(pos.getY() + p.getEyeHeight());
    }
    else {
        pos = pp.getHeadPosition();
    }
    Vector dir = MathPlus.getDirection(pp.getYaw(), pp.getPitch());
    Vector extraDir = MathPlus.getDirection(pp.getYaw() + pp.getDeltaYaw(), pp.getPitch() + pp.getDeltaPitch());

    Vector min = bLoc.toVector();
    Vector max = bLoc.toVector().add(new Vector(1, 1, 1));
    AABB targetAABB = new AABB(min, max);
    targetAABB.expand(BOX_EXPAND, BOX_EXPAND, BOX_EXPAND);

    if (DEBUG_HITBOX)
        targetAABB.highlight(hawk, p.getWorld(), 0.25);
    if (DEBUG_RAY)
        new Ray(pos, extraDir).highlight(hawk, p.getWorld(), 6F, 0.3);

    if(targetAABB.betweenRays(pos, dir, extraDir)) {
        reward(pp);
    }
    else {
        punish(pp, true, e);
    }
}
 
Example 3
Source File: BlockBreakReach.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void check(BlockDigEvent e) {
    Player p = e.getPlayer();
    HawkPlayer pp = e.getHawkPlayer();

    Location bLoc = e.getBlock().getLocation();
    Vector min = bLoc.toVector();
    Vector max = bLoc.toVector().add(new Vector(1, 1, 1));
    AABB targetAABB = new AABB(min, max);

    Vector ppPos;
    if(pp.isInVehicle()) {
        ppPos = hawk.getLagCompensator().getHistoryLocation(ServerUtils.getPing(p), p).toVector();
        ppPos.setY(ppPos.getY() + p.getEyeHeight());
    }
    else {
        ppPos = pp.getHeadPosition();
    }

    double maxReach = pp.getPlayer().getGameMode() == GameMode.CREATIVE ? MAX_REACH_CREATIVE : MAX_REACH;
    double dist = targetAABB.distanceToPosition(ppPos);

    if (dist > maxReach) {
        punish(pp, 1, true, e, new Placeholder("distance", MathPlus.round(dist, 2)));
    } else {
        reward(pp);
    }
}
 
Example 4
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 5
Source File: WrappedBlock7.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
private AABB[] getCollisionBoxes(net.minecraft.server.v1_7_R4.Block b, Location loc) {

        //define boxes for funny blocks
        if (b instanceof BlockCarpet) {
            AABB[] aabbarr = new AABB[1];
            if(clientVersion == 7) {
                aabbarr[0] = new AABB(loc.toVector(), loc.toVector().add(new Vector(1, 0, 1)));
            }
            else {
                aabbarr[0] = new AABB(loc.toVector(), loc.toVector().add(new Vector(1, 0.0625, 1)));
            }
            return aabbarr;
        }

        List<AxisAlignedBB> bbs = new ArrayList<>();
        AxisAlignedBB cube = AxisAlignedBB.a(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getBlockX() + 1, loc.getBlockY() + 1, loc.getBlockZ() + 1);
        b.a(((CraftWorld) loc.getWorld()).getHandle(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), cube, bbs, null);

        AABB[] collisionBoxes = new AABB[bbs.size()];
        for (int i = 0; i < bbs.size(); i++) {
            AxisAlignedBB bb = bbs.get(i);
            AABB collisionBox = new AABB(new Vector(bb.a, bb.b, bb.c), new Vector(bb.d, bb.e, bb.f));
            collisionBoxes[i] = collisionBox;
        }

        return collisionBoxes;
    }
 
Example 6
Source File: Swapper.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@Override
protected boolean performSpecialAction(Player player, AnniPlayer p)
{
	if(p.getTeam() != null)
	{
		Player e = instance.getPlayerInSightTest(player, 15);
		if(e != null)
		{
			AnniPlayer pl = AnniPlayer.getPlayer(e.getUniqueId());
			if(pl != null && !pl.getTeam().equals(p.getTeam()))
			{
				Location playerLoc = player.getLocation().clone();
				Location entityLoc = e.getLocation().clone();
				
				Vector playerLook = playerLoc.getDirection();
				Vector playerVec = playerLoc.toVector();
				Vector entityVec = entityLoc.toVector();
				Vector toVec = playerVec.subtract(entityVec).normalize();
				
				e.teleport(playerLoc.setDirection(playerLook.normalize()));
				player.teleport(entityLoc.setDirection(toVec));
				e.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 1));
				return true;
			}
		}	
	}
	return false;
}
 
Example 7
Source File: SentinelTargetingHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Returns a direction to run in, avoiding threatening entities as best as possible.
 * Returns a location of the spot to run to.
 * Returns null if nowhere to run.
 */
public Location runDirection(Location center) {
    for (int i = 0; i < 36; i++) {
        threatDists[i] = 1000 * 1000;
    }
    double range = sentinel.avoidRange;
    Vector centerVec = center.toVector();
    for (LivingEntity entity : avoidanceList) {
        Vector relative = entity.getLocation().toVector().subtract(centerVec);
        for (int i = 0; i < 36; i++) {
            double dist = relative.distanceSquared(directionReferenceVectors[i].clone().multiply(range));
            if (dist < threatDists[i]) {
                threatDists[i] = dist;
            }
        }
    }
    double longestDistance = 0;
    Location runTo = null;
    for (int i = 0; i < 36; i++) {
        if (threatDists[i] > longestDistance) {
            Location newRunTo = findSpotForRunDirection(center, range, directionReferenceVectors[i].clone());
            if (newRunTo != null) {
                runTo = newRunTo;
                longestDistance = threatDists[i];
            }
        }
    }
    if (SentinelPlugin.debugMe) {
        SentinelPlugin.instance.getLogger().info("(TEMP) Run to get threat distance: " + longestDistance + " to " + runTo + " from " + center.toVector());
    }
    return runTo;
}
 
Example 8
Source File: BlockLineIterator.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
private static Vector fitInWorld(final Location l, final Vector dir) {
	if (0 <= l.getBlockY() && l.getBlockY() < l.getWorld().getMaxHeight())
		return l.toVector();
	final double y = Math2.fit(0, l.getY(), l.getWorld().getMaxHeight());
	if (Math.abs(dir.getY()) < Skript.EPSILON)
		return new Vector(l.getX(), y, l.getZ());
	final double dy = y - l.getY();
	final double n = dy / dir.getY();
	return l.toVector().add(dir.clone().multiply(n));
}
 
Example 9
Source File: VectorUtils.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get to know where the {@link Vector} intersects with a {@link org.bukkit.block.Block}.
 * Non-Occluding {@link Block}s as defined in {@link BlockUtils#isReallyOccluding(Material)} are ignored.
 *
 * @param start     the starting {@link Location}
 * @param direction the {@link Vector} which should be checked
 *
 * @return The length when the {@link Vector} intersects or 0 if no intersection was found
 */
public static double getDistanceToFirstIntersectionWithBlock(final Location start, final Vector direction)
{
    final int length = (int) Math.floor(direction.length());
    Preconditions.checkNotNull(start.getWorld(), "RayTrace: Unknown start world.");

    if (length >= 1) {
        if (RAY_TRACING) {
            RayTraceResult result = start.getWorld().rayTraceBlocks(start, direction, length, FluidCollisionMode.NEVER, true);
            // Hit nothing or the other player
            if (result == null || result.getHitBlock() == null) {
                return 0;
            }

            return start.toVector().distance(result.getHitPosition());
        } else {
            try {
                final BlockIterator blockIterator = new BlockIterator(start.getWorld(), start.toVector(), direction, 0, length);
                Block block;
                while (blockIterator.hasNext()) {
                    block = blockIterator.next();
                    // Account for a Spigot bug: BARRIER and MOB_SPAWNER are not occluding blocks
                    if (BlockUtils.isReallyOccluding(block.getType())) {
                        // Use the middle location of the Block instead of the simple location.
                        return block.getLocation().clone().add(0.5, 0.5, 0.5).distance(start);
                    }
                }
            } catch (IllegalStateException exception) {
                // Just in case the start block could not be found for some reason or a chunk is loaded async.
                return 0;
            }
        }
    }
    return 0;
}
 
Example 10
Source File: LoseCheckerTask.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
	for (Game game : gameManager.getGames()) {
		if (game.getGameState() != GameState.INGAME) {
			continue;
		}
		
		Set<SpleefPlayer> deathCandidates = null;
		final boolean isLiquidDeathzone = game.getPropertyValue(GameProperty.USE_LIQUID_DEATHZONE);
		
		for (SpleefPlayer player : game.getPlayers()) {
			Location playerLoc = player.getBukkitPlayer().getLocation();
			
			boolean isDeathCandidate = isInsideDeathzone(playerLoc, game, isLiquidDeathzone);
			if (!isDeathCandidate && recentLocations.containsKey(player)) {
				//Try to check every block the player has passed between the recent location and his location now
				Location recent = recentLocations.get(player);
				org.bukkit.util.Vector direction = playerLoc.clone().subtract(recent).toVector();
				int directionLength = (int) direction.length();
				
				if (directionLength > 0) {
					BlockIterator iterator = new BlockIterator(game.getWorld(), recent.toVector(), direction, 0D, directionLength);
					while (iterator.hasNext()) {
						Block passedBlock = iterator.next();
						
						if (isInsideDeathzone(passedBlock.getLocation(), game, isLiquidDeathzone)) {
							isDeathCandidate = true;
							break;
						}
					}
				}
			}
			
			if (isDeathCandidate) {
				//Lazy initialization for performance optimization
				if (deathCandidates == null) {
					deathCandidates = Sets.newHashSet();
				}
				
				deathCandidates.add(player);
			}
			
			recentLocations.put(player, playerLoc);
		}
		
		if (deathCandidates != null) {
			for (SpleefPlayer deathCandidate : deathCandidates) {
				game.requestLose(deathCandidate, QuitCause.LOSE);
			}
		}
	}
}
 
Example 11
Source File: Util.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
public static List<Location> getTargetsPathBlocked(Location tLoc, Location dLoc, boolean useOnlyMaterialListing, boolean ignoreFirstZone) {
    final ArrayList<Location> targetsInPath = new ArrayList<Location>();

    // check world
    if (!dLoc.getWorld().getName().equalsIgnoreCase(tLoc.getWorld().getName())) {
        return targetsInPath;
    }

    // if the distance is too close... the path is not blocked ;)
    if (dLoc.distance(tLoc) <= 0.9) {
        return targetsInPath;
    }

    // try to iterate through blocks between dLoc and tLoc
    try {
        // Create a vector block trace from the detonator location to damaged block's location
        final Location tarLoc = tLoc.clone().add(0, 0.25, 0);
        final BlockIterator blocksInPath = new BlockIterator(tarLoc.getWorld(), dLoc.toVector(), tarLoc.toVector().subtract(dLoc.toVector()).normalize(), 0.5, (int) dLoc.distance(tarLoc));

        // iterate through the blocks in the path
        int i = ConfigManager.getInstance().getRadius() + 1;
        int over = 0; // prevents rare case of infinite loop and server crash
        while (blocksInPath.hasNext() && over < 128) {
            if (i > 0) {
                i--;
            } else {
                break;
            }
            over++;

            // the next block
            final Block block = blocksInPath.next();
            if (block == null) {
                continue;
            }
            // check if next block is the target block
            if (tarLoc.getWorld().getName().equals(block.getWorld().getName()) &&
                    tarLoc.getBlockX() == block.getX() &&
                    tarLoc.getBlockY() == block.getY() &&
                    tarLoc.getBlockZ() == block.getZ()) {
                // ignore target block
                continue;
            }
            // Ignore first blocks next to explosion
            if (ignoreFirstZone && ((i >= ConfigManager.getInstance().getRadius() - 1) || (dLoc.distance(tarLoc) <= 1.5))) {
                if (i >= ConfigManager.getInstance().getRadius() - 1 && MaterialManager.getInstance().contains(block.getType().name(), block.getData())) {
                    targetsInPath.add(block.getLocation());
                }
                continue;
            }

            // check if the block material is being handled
            if (useOnlyMaterialListing) {
                // only handle for certain case as to not interfere with all explosions
                if (MaterialManager.getInstance().contains(block.getType().name(), block.getData())) {
                    targetsInPath.add(block.getLocation());
                    continue;
                } else {
                    continue;
                }
            }
            // check if the block material is a solid
            if (!isNonSolid(block.getType())) {
                targetsInPath.add(block.getLocation());
                if (targetsInPath.size() > 3) {
                    break;
                }
            }
        }
    } catch (Exception e) {
        // ignore the error and return no targets in path
    }
    return targetsInPath;
}
 
Example 12
Source File: Util.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isTargetsPathBlocked(Location tLoc, Location dLoc, boolean useOnlyMaterialListing) {

        // check world
        if (!dLoc.getWorld().getName().equalsIgnoreCase(tLoc.getWorld().getName())) {
            return false;
        }

        // if the distance is too close... the path is not blocked ;)
        if (dLoc.distance(tLoc) <= 0.9) {
            return false;
        }

        // try to iterate through blocks between dLoc and tLoc
        try {
            // Create a vector block trace from the detonator location to damaged block's location
            final BlockIterator blocksInPath = new BlockIterator(tLoc.getWorld(), dLoc.toVector(), tLoc.toVector().subtract(dLoc.toVector()).normalize(), 0.5, (int) dLoc.distance(tLoc));

            // iterate through the blocks in the path
            int over = 0; // prevents rare case of infinite loop and server crash
            while (blocksInPath.hasNext() && over < 128) {
                over++;
                // the next block
                final Block block = blocksInPath.next();
                if (block == null) {
                    continue;
                }
                // check if next block is the target block
                if (tLoc.getWorld().getName().equals(block.getWorld().getName()) &&
                        tLoc.getBlockX() == block.getX() &&
                        tLoc.getBlockY() == block.getY() &&
                        tLoc.getBlockZ() == block.getZ()) {
                    // ignore target block
                    continue;
                }

                // check if the block material is being handled
                if (useOnlyMaterialListing) {
                    // only handle for certain case as to not interfere with all explosions
                    if (MaterialManager.getInstance().contains(block.getType().name(), block.getData())) {
                        return true;
                    } else {
                        continue;
                    }
                }
                // check if the block material is a solid
                if (!isNonSolid(block.getType())) {
                    return true;
                }
            }
        } catch (Exception e) {
            // ignore the error and return no targets in path
        }
        return false;
    }
 
Example 13
Source File: VectorUtils.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return an array of {@link Vector}s which represent the 3 different camera modes in minecraft, 1st person and the two
 * 3rd person views with the following indices: <br>
 * [0] = normal (eyeposition vector) <br>
 * [1] = front <br>
 * [2] = behind <br>
 */
public static Vector[] getCameraVectors(final Player player)
{
    /*
        All the vectors
        [0] = normal (eyeposition vector)
        [1] = front
        [2] = behind
    */
    final Vector[] vectors = new Vector[3];

    // Front vector : The 3rd person perspective in front of the player
    // Use THIRD_PERSON_OFFSET to get the maximum positions
    // No cloning or normalizing as a new unit-vector instance is returned.
    vectors[1] = player.getLocation().getDirection().multiply(THIRD_PERSON_OFFSET);

    // Behind vector : The 3rd person perspective behind the player
    vectors[2] = vectors[1].clone().multiply(-1);

    final Location eyeLocation = player.getEyeLocation();

    // Normal
    vectors[0] = eyeLocation.toVector();

    // Do the Cameras intersect with Blocks
    // Get the length of the first intersection or 0 if there is none

    // [0] = frontIntersection
    // [1] = behindIntersection
    final double[] intersections = new double[]{
            VectorUtils.getDistanceToFirstIntersectionWithBlock(eyeLocation, vectors[1]),
            VectorUtils.getDistanceToFirstIntersectionWithBlock(eyeLocation, vectors[2])
    };

    for (int i = 0; i < intersections.length; i++) {
        // There is an intersection
        if (intersections[i] != 0) {
            // Now we need to make sure the vectors are not inside of blocks as the method above returns.
            // The 0.05 factor makes sure that we are outside of the block and not on the edge.
            intersections[i] -= 0.05 +
                                // Calculate the distance to the middle of the block
                                (0.5 / Math.sin(vectors[i + 1].angle(vectors[i + 1].clone().setY(0))));

            // Add the correct position.
            vectors[i + 1].normalize().multiply(intersections[i]);
        }

        // Add the eye location for a correct starting point.
        vectors[i + 1].add(vectors[0]);
    }
    return vectors;
}
 
Example 14
Source File: PacketSignPromptFactory.java    From helper with MIT License 4 votes vote down vote up
@Override
public void openPrompt(@Nonnull Player player, @Nonnull List<String> lines, @Nonnull ResponseHandler responseHandler) {
    Location location = player.getLocation().clone();
    location.setY(255);
    Players.sendBlockChange(player, location, Material.WALL_SIGN);

    BlockPosition position = new BlockPosition(location.toVector());
    PacketContainer writeToSign = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
    writeToSign.getBlockPositionModifier().write(0, position);
    writeToSign.getIntegers().write(0, 9);
    NbtCompound compound = NbtFactory.ofCompound("");

    for (int i = 0; i < 4; i++) {
        compound.put("Text" + (i + 1), "{\"text\":\"" + (lines.size() > i ? lines.get(i) : "") + "\"}");
    }

    compound.put("id", "minecraft:sign");
    compound.put("x", position.getX());
    compound.put("y", position.getY());
    compound.put("z", position.getZ());

    writeToSign.getNbtModifier().write(0, compound);
    Protocol.sendPacket(player, writeToSign);

    PacketContainer openSign = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR);
    openSign.getBlockPositionModifier().write(0, position);
    Protocol.sendPacket(player, openSign);

    // we need to ensure that the callback is only called once.
    final AtomicBoolean active = new AtomicBoolean(true);

    Protocol.subscribe(PacketType.Play.Client.UPDATE_SIGN)
            .filter(e -> e.getPlayer().getUniqueId().equals(player.getUniqueId()))
            .biHandler((sub, event) -> {
                if (!active.getAndSet(false)) {
                    return;
                }

                PacketContainer container = event.getPacket();

                List<String> input = new ArrayList<>(Arrays.asList(container.getStringArrays().read(0)));
                Response response = responseHandler.handleResponse(input);

                if (response == Response.TRY_AGAIN) {
                    // didn't pass, re-send the sign and request another input
                    Schedulers.sync().runLater(() -> {
                        if (player.isOnline()) {
                            openPrompt(player, lines, responseHandler);
                        }
                    }, 1L);
                }

                // cleanup this instance
                sub.close();
                Players.sendBlockChange(player, location, Material.AIR);
            });
}
 
Example 15
Source File: FlagSnowballs.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
	Projectile projectile = event.getEntity();
	if (!(projectile instanceof Snowball)) {
		return;
	}
	
	ProjectileSource shooter = projectile.getShooter();
	if (!(shooter instanceof Player)) {
		return;
	}
	
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(shooter);
	GameManager manager = getHeavySpleef().getGameManager();
	Game game;
	
	if ((game = manager.getGame(player)) == null) {
		return;
	}

	Location location = projectile.getLocation();
	Vector start = location.toVector();
	Vector dir = projectile.getVelocity().normalize();
	
	BlockIterator iterator = new BlockIterator(projectile.getWorld(), start, dir, 0, 4);
	
	Block blockHit = null;
	
	while (iterator.hasNext()) {
		blockHit = iterator.next();
		
		if (blockHit.getType() != Material.AIR) {
			break;
		}
	}
	
	if (!game.canSpleef(blockHit)) {
		//Cannot remove this block
		return;
	}
	
	projectile.remove();
	game.addBlockBroken(player, blockHit);
	
	blockHit.setType(Material.AIR);
	if (game.getPropertyValue(GameProperty.PLAY_BLOCK_BREAK)) {
		blockHit.getWorld().playEffect(blockHit.getLocation(), Effect.STEP_SOUND, blockHit.getTypeId());
	}
}
 
Example 16
Source File: BlockBreakDirection.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void check(BlockDigEvent e) {
    Player p = e.getPlayer();
    HawkPlayer pp = e.getHawkPlayer();
    Location bLoc = e.getBlock().getLocation();
    Vector pos;
    if(pp.isInVehicle()) {
        pos = hawk.getLagCompensator().getHistoryLocation(ServerUtils.getPing(p), p).toVector();
        pos.setY(pos.getY() + p.getEyeHeight());
    }
    else {
        pos = pp.getHeadPosition();
    }
    Vector dir = MathPlus.getDirection(pp.getYaw(), pp.getPitch());
    Vector extraDir = MathPlus.getDirection(pp.getYaw() + pp.getDeltaYaw(), pp.getPitch() + pp.getDeltaPitch());

    switch (e.getDigAction()) {
        case START:
            if(CHECK_DIG_START || (p.getGameMode() == GameMode.CREATIVE && CHECK_DIG_COMPLETE))
                break;
            return;
        case CANCEL:
            if(CHECK_DIG_CANCEL)
                break;
            return;
        case COMPLETE:
            if(CHECK_DIG_COMPLETE)
                break;
            return;
    }

    Vector min = bLoc.toVector();
    Vector max = bLoc.toVector().add(new Vector(1, 1, 1));
    AABB targetAABB = new AABB(min, max);

    if (DEBUG_HITBOX)
        targetAABB.highlight(hawk, p.getWorld(), 0.25);
    if (DEBUG_RAY)
        new Ray(pos, extraDir).highlight(hawk, p.getWorld(), 6F, 0.3);

    if(targetAABB.betweenRays(pos, dir, extraDir)) {
        reward(pp);
    }
    else {
        punish(pp, true, e);
    }
}
 
Example 17
Source File: Vector3D.java    From Civs with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Construct an immutable floating point 3D vector from a location object.
 * @param location - the location to copy.
 */
public Vector3D(Location location) {
    this(location.toVector());
}
 
Example 18
Source File: Vector3D.java    From AnnihilationPro with MIT License 2 votes vote down vote up
/**
 * Construct an immutable floating point 3D vector from a location object.
 * @param location - the location to copy.
 */
public Vector3D(Location location) {
    this(location.toVector());
}
 
Example 19
Source File: BlockIterator.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs the BlockIterator.
 *
 * @param loc     The location for the start of the ray trace
 * @param yOffset The trace begins vertically offset from the start vector
 *                by this value
 */

public BlockIterator(Location loc, double yOffset) {
    this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, 0);
}
 
Example 20
Source File: BlockIterator.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs the BlockIterator
 *
 * @param loc         The location for the start of the ray trace
 * @param yOffset     The trace begins vertically offset from the start vector
 *                    by this value
 * @param maxDistance This is the maximum distance in blocks for the
 *                    trace. Setting this value above 140 may lead to problems with
 *                    unloaded chunks. A value of 0 indicates no limit
 */
public BlockIterator(Location loc, double yOffset, int maxDistance) {
    this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, maxDistance);
}