Search in sources :

Example 91 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_11_R1 method eyeTrace.

@Override
public Location eyeTrace(LivingEntity from, double range) {
    Location start = from.getEyeLocation();
    double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180));
    double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180));
    double ny = Math.sin(start.getPitch() * (Math.PI / 180));
    double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180));
    return rayTrace(start, new Vector(nx, -ny, nz), range);
}
Also used : Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 92 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_11_R1 method mapTrace.

@Override
public MapTraceResult mapTrace(LivingEntity from, double range) {
    Location start = from.getEyeLocation();
    Vector startVec = start.toVector();
    double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180));
    double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180));
    double ny = Math.sin(start.getPitch() * (Math.PI / 180));
    double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180));
    Vector endVec = startVec.clone().add(new Vector(nx, -ny, nz).multiply(range));
    MovingObjectPosition l = rayTrace(start.getWorld(), startVec, endVec);
    if (l == null || l.pos == null) {
        return null;
    }
    Vector finalVec = new Vector(l.pos.x, l.pos.y, l.pos.z);
    MapTraceResult mtr = new MapTraceResult();
    switch(l.direction) {
        case NORTH:
            mtr.angle = BlockFace.NORTH;
            break;
        case SOUTH:
            mtr.angle = BlockFace.SOUTH;
            break;
        case EAST:
            mtr.angle = BlockFace.EAST;
            break;
        case WEST:
            mtr.angle = BlockFace.WEST;
            break;
    }
    // wallPosition - ((end - start).normalize() * 0.072)
    Vector hit = finalVec.clone().subtract((endVec.clone().subtract(startVec)).normalize().multiply(0.072));
    mtr.hitLocation = new Location(start.getWorld(), hit.getX(), hit.getY(), hit.getZ());
    return mtr;
}
Also used : Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 93 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_11_R1 method rayTrace.

@Override
public Location rayTrace(Location start, Vector direction, double range) {
    Vector startVec = start.toVector();
    MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
    if (l != null && l.pos != null) {
        return new Location(start.getWorld(), l.pos.x, l.pos.y, l.pos.z);
    }
    return null;
}
Also used : Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 94 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_11_R1 method getImpactNormal.

@Override
public Location getImpactNormal(Location start, Vector direction, double range) {
    Vector startVec = start.toVector();
    MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
    if (l != null && l.direction != null) {
        return new Location(start.getWorld(), l.direction.getAdjacentX(), l.direction.getAdjacentY(), l.direction.getAdjacentZ());
    }
    return null;
}
Also used : Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 95 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class CopyBlockCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation copy_location = (dLocation) scriptEntry.getObject("location");
    dLocation destination = (dLocation) scriptEntry.getObject("destination");
    dCuboid copy_cuboid = (dCuboid) scriptEntry.getObject("cuboid");
    Element remove_original = (Element) scriptEntry.getObject("remove");
    dB.report(scriptEntry, getName(), (copy_location != null ? copy_location.debug() : "") + (copy_cuboid != null ? copy_cuboid.debug() : "") + destination.debug() + remove_original.debug());
    List<Location> locations = new ArrayList<Location>();
    if (copy_location != null) {
        locations.add(copy_location);
    } else if (copy_cuboid != null) {
        // TODO: make this work?...
        locations.addAll(copy_cuboid.getBlockLocations());
    }
    for (Location loc : locations) {
        Block source = loc.getBlock();
        BlockState sourceState = source.getState();
        Block update = destination.getBlock();
        update.setTypeIdAndData(source.getTypeId(), source.getData(), false);
        BlockState updateState = update.getState();
        // of InventoryHolder
        if (sourceState instanceof InventoryHolder) {
            ((InventoryHolder) updateState).getInventory().setContents(((InventoryHolder) sourceState).getInventory().getContents());
        } else if (sourceState instanceof Sign) {
            int n = 0;
            for (String line : ((Sign) sourceState).getLines()) {
                ((Sign) updateState).setLine(n, line);
                n++;
            }
        } else if (sourceState instanceof NoteBlock) {
            ((NoteBlock) updateState).setNote(((NoteBlock) sourceState).getNote());
        } else if (sourceState instanceof Skull) {
            ((Skull) updateState).setSkullType(((Skull) sourceState).getSkullType());
            ((Skull) updateState).setOwner(((Skull) sourceState).getOwner());
            ((Skull) updateState).setRotation(((Skull) sourceState).getRotation());
        } else if (sourceState instanceof Jukebox) {
            ((Jukebox) updateState).setPlaying(((Jukebox) sourceState).getPlaying());
        } else if (sourceState instanceof Banner) {
            ((Banner) updateState).setBaseColor(((Banner) sourceState).getBaseColor());
            ((Banner) updateState).setPatterns(((Banner) sourceState).getPatterns());
        } else if (sourceState instanceof CommandBlock) {
            ((CommandBlock) updateState).setName(((CommandBlock) sourceState).getName());
            ((CommandBlock) updateState).setCommand(((CommandBlock) sourceState).getCommand());
        } else if (sourceState instanceof CreatureSpawner) {
            ((CreatureSpawner) updateState).setCreatureTypeByName(((CreatureSpawner) sourceState).getCreatureTypeName());
            ((CreatureSpawner) updateState).setDelay(((CreatureSpawner) sourceState).getDelay());
        }
        updateState.update();
        if (remove_original.asBoolean()) {
            loc.getBlock().setType(Material.AIR);
        }
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dCuboid(net.aufdemrand.denizen.objects.dCuboid) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

Location (org.bukkit.Location)470 Player (org.bukkit.entity.Player)120 World (org.bukkit.World)63 EventHandler (org.bukkit.event.EventHandler)54 Vector (org.bukkit.util.Vector)45 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)36 Block (org.bukkit.block.Block)31 Entity (org.bukkit.entity.Entity)28 UUID (java.util.UUID)27 ItemStack (org.bukkit.inventory.ItemStack)22 LivingEntity (org.bukkit.entity.LivingEntity)20 PotionEffect (org.bukkit.potion.PotionEffect)17 User (com.earth2me.essentials.User)16 List (java.util.List)16 IOException (java.io.IOException)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 Island (com.wasteofplastic.acidisland.Island)12