Spout Max Height, RaiseEarth Config Options (#507)

* Fix NPE in OctopusForm

* Spouts now cannot be created above max height

* Improve RaiseEarth width config option
This commit is contained in:
Nathan Braun 2016-06-26 14:29:20 -07:00 committed by OmniCypher
parent 2907952ca2
commit 2d648641f1
4 changed files with 80 additions and 9 deletions

View file

@ -39,6 +39,11 @@ public class AirSpout extends AirAbility {
this.interval = getConfig().getLong("Abilities.Air.AirSpout.Interval"); this.interval = getConfig().getLong("Abilities.Air.AirSpout.Interval");
this.height = getConfig().getDouble("Abilities.Air.AirSpout.Height"); this.height = getConfig().getDouble("Abilities.Air.AirSpout.Height");
double heightRemoveThreshold = 2;
if (!isWithinMaxSpoutHeight(heightRemoveThreshold)) {
return;
}
new Flight(player); new Flight(player);
start(); start();
bPlayer.addCooldown(this); bPlayer.addCooldown(this);
@ -70,6 +75,18 @@ public class AirSpout extends AirAbility {
player.setFlying(true); player.setFlying(true);
} }
private boolean isWithinMaxSpoutHeight(double threshold) {
Block ground = getGround();
if (ground == null) {
return false;
}
double playerHeight = player.getLocation().getY();
if (playerHeight > ground.getLocation().getY() + height + threshold) {
return false;
}
return true;
}
private Block getGround() { private Block getGround() {
Block standingblock = player.getLocation().getBlock(); Block standingblock = player.getLocation().getBlock();
for (int i = 0; i <= height + 5; i++) { for (int i = 0; i <= height + 5; i++) {
@ -83,12 +100,16 @@ public class AirSpout extends AirAbility {
@Override @Override
public void progress() { public void progress() {
if (player.isDead() || !player.isOnline() || !bPlayer.canBendIgnoreBindsCooldowns(this)) { if (player.isDead()
|| !player.isOnline()
|| !bPlayer.canBendIgnoreBindsCooldowns(this)
|| !bPlayer.canBind(this)) {
remove(); remove();
return; return;
} }
if(!bPlayer.canBind(this)) { double heightRemoveThreshold = 2;
if (!isWithinMaxSpoutHeight(heightRemoveThreshold)) {
remove(); remove();
return; return;
} }

View file

@ -38,12 +38,14 @@ public class RaiseEarthWall extends EarthAbility {
Vector direction = player.getEyeLocation().getDirection().normalize(); Vector direction = player.getEyeLocation().getDirection().normalize();
double ox, oy, oz; double ox, oy, oz;
direction.setY(0);
ox = -direction.getZ(); ox = -direction.getZ();
oy = 0; oy = 0;
oz = direction.getX(); oz = direction.getX();
Vector orth = new Vector(ox, oy, oz); Vector orth = new Vector(ox, oy, oz);
orth = orth.normalize(); orth = orth.normalize();
orth = getDegreeRoundedVector(orth, 0.25);
Block sblock = BlockSource.getEarthSourceBlock(player, selectRange, ClickType.SHIFT_DOWN); Block sblock = BlockSource.getEarthSourceBlock(player, selectRange, ClickType.SHIFT_DOWN);
@ -56,8 +58,9 @@ public class RaiseEarthWall extends EarthAbility {
World world = location.getWorld(); World world = location.getWorld();
boolean shouldAddCooldown = false; boolean shouldAddCooldown = false;
for (int i = -width / 2; i <= width / 2; i++) { for (int i = 0; i < width; i++) {
Block block = world.getBlockAt(location.clone().add(orth.clone().multiply((double) i))); double adjustedI = i - width / 2.0;
Block block = world.getBlockAt(location.clone().add(orth.clone().multiply(adjustedI)));
if (isTransparent(block)) { if (isTransparent(block)) {
for (int j = 1; j < height; j++) { for (int j = 1; j < height; j++) {
@ -90,6 +93,30 @@ public class RaiseEarthWall extends EarthAbility {
} }
} }
private static Vector getDegreeRoundedVector(Vector vec, double degreeIncrement) {
if (vec == null) {
return null;
}
vec = vec.normalize();
double[] dims = {vec.getX(), vec.getY(), vec.getZ()};
for (int i = 0; i < dims.length; i++) {
double dim = dims[i];
int sign = dim >= 0 ? 1 : -1;
int dimDivIncr = (int)(dim / degreeIncrement);
double lowerBound = dimDivIncr * degreeIncrement;
double upperBound = (dimDivIncr + (1 * sign)) * degreeIncrement;
if (Math.abs(dim - lowerBound) < Math.abs(dim - upperBound)) {
dims[i] = lowerBound;
} else {
dims[i] = upperBound;
}
}
return new Vector(dims[0], dims[1], dims[2]);
}
@Override @Override
public String getName() { public String getName() {
return "RaiseEarth"; return "RaiseEarth";

View file

@ -53,7 +53,7 @@ public class TempBlock {
} }
public static boolean isTempBlock(Block block) { public static boolean isTempBlock(Block block) {
return instances.containsKey(block); return block != null ? instances.containsKey(block) : false;
} }
public static boolean isTouchingTempBlock(Block block) { public static boolean isTouchingTempBlock(Block block) {

View file

@ -68,6 +68,11 @@ public class WaterSpout extends WaterAbility {
return; return;
} }
double heightRemoveThreshold = 2;
if (!isWithinMaxSpoutHeight(topBlock.getLocation(), heightRemoveThreshold)) {
return;
}
new Flight(player); new Flight(player);
player.setAllowFlight(true); player.setAllowFlight(true);
start(); start();
@ -124,6 +129,12 @@ public class WaterSpout extends WaterAbility {
if (height != -1) { if (height != -1) {
location = base.getLocation(); location = base.getLocation();
double heightRemoveThreshold = 2;
if (!isWithinMaxSpoutHeight(location, heightRemoveThreshold)) {
remove();
return;
}
for (int i = 1; i <= height; i++) { for (int i = 1; i <= height; i++) {
block = location.clone().add(0, i, 0).getBlock(); block = location.clone().add(0, i, 0).getBlock();
@ -168,6 +179,18 @@ public class WaterSpout extends WaterAbility {
} }
} }
private boolean isWithinMaxSpoutHeight(Location baseBlockLocation, double threshold) {
if (baseBlockLocation == null) {
return false;
}
double playerHeight = player.getLocation().getY();
double maxHeight = isNight(player.getWorld()) ? getNightFactor(height) : height;
if (playerHeight > baseBlockLocation.getY() + maxHeight + threshold) {
return false;
}
return true;
}
public void rotateParticles(Block block) { public void rotateParticles(Block block) {
if (!useParticles) { if (!useParticles) {
return; return;