Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added better handling for limits on Bounce BetterPiston.
  • Loading branch information
me4502 committed Feb 19, 2017
1 parent 7eb9405 commit b44901c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/sk89q/craftbook/mechanics/BetterPistons.java
Expand Up @@ -81,6 +81,12 @@ public void onSignChange(SignChangeEvent event) {
} else if (event.getLine(1).equalsIgnoreCase("[Bounce]") && Types.isEnabled(Types.BOUNCE)) {
event.setLine(1, "[Bounce]");
type = Types.BOUNCE;
double velocity = 1.0d;
try {
velocity = Double.parseDouble(event.getLine(2));
} catch (Exception e) {}
velocity = Math.min(Math.max(velocity, -pistonBounceMaxVelocity), pistonBounceMaxVelocity);
event.setLine(2, String.valueOf(velocity));
} else if (event.getLine(1).equalsIgnoreCase("[SuperPush]") && Types.isEnabled(Types.SUPERPUSH)) {
event.setLine(1, "[SuperPush]");
type = Types.SUPERPUSH;
Expand Down Expand Up @@ -191,6 +197,8 @@ public void bounce(Block trigger, PistonBaseMaterial piston, ChangedSign signSta
mult = 1;
}

mult = Math.min(Math.max(mult, -pistonBounceMaxVelocity), pistonBounceMaxVelocity);

Vector vel = new Vector(piston.getFacing().getModX(), piston.getFacing().getModY(), piston.getFacing().getModZ()).multiply(mult);
if (trigger.getRelative(piston.getFacing()).getType() == Material.AIR || trigger.getRelative(piston.getFacing()).getState() != null && InventoryUtil.doesBlockHaveInventory(trigger.getRelative(piston.getFacing())) || trigger.getRelative(piston.getFacing()).getType() == Material.PISTON_MOVING_PIECE || trigger.getRelative(piston.getFacing()).getType() == Material.PISTON_EXTENSION || pistonsBounceBlacklist.contains(new ItemInfo(trigger.getRelative(piston.getFacing())))) {
for (Entity ent : trigger.getRelative(piston.getFacing()).getChunk().getEntities()) {
Expand Down Expand Up @@ -389,6 +397,7 @@ public static boolean isEnabled(Types type) {
private List<ItemInfo> pistonsMovementBlacklist;
private boolean pistonsBounce;
private List<ItemInfo> pistonsBounceBlacklist;
private double pistonBounceMaxVelocity;

@Override
public void loadConfiguration (YAMLProcessor config, String path) {
Expand Down Expand Up @@ -419,5 +428,8 @@ public void loadConfiguration (YAMLProcessor config, String path) {

config.setComment(path + "max-distance", "The maximum distance a BetterPiston can interact with blocks from.");
pistonMaxDistance = config.getInt(path + "max-distance", 12);

config.setComment(path + "bounce-max-velocity", "The maximum velocity bounce pistons can provide.");
pistonBounceMaxVelocity = config.getDouble(path + "bounce-max-velocity", 5.0);
}
}

0 comments on commit b44901c

Please sign in to comment.