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);
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations