Skip to content

Commit

Permalink
Added an ignore powered rail option to ConstantSpeed.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Feb 6, 2018
1 parent 0ca398f commit 9e1f49f
Showing 1 changed file with 10 additions and 0 deletions.
@@ -1,5 +1,6 @@
package com.sk89q.craftbook.mechanics.minecart;

import org.bukkit.Material;
import org.bukkit.entity.Minecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -21,17 +22,26 @@ public void onVehicleMove(VehicleMoveEvent event) {
if (!(event.getVehicle() instanceof Minecart)) return;

if (RailUtil.isTrack(event.getTo().getBlock().getType()) && event.getVehicle().getVelocity().lengthSquared() > 0) {
if (event.getTo().getBlock().getType() == Material.POWERED_RAIL && !ignorePoweredRail) {
if ((event.getTo().getBlock().getData() & 8) == 0) {
return;
}
}
Vector vel = event.getVehicle().getVelocity();
event.getVehicle().setVelocity(vel.normalize().multiply(speed));
}
}

private double speed;
private boolean ignorePoweredRail;

@Override
public void loadConfiguration (YAMLProcessor config, String path) {

config.setComment(path + "speed", "Sets the speed to move at constantly.");
speed = config.getDouble(path + "speed", 0.5);

config.setComment(path + "ignore-powered-rail", "Whether or not powered rails should be ignored.");
ignorePoweredRail = config.getBoolean(path + "ignore-powered-rail", false);
}
}

0 comments on commit 9e1f49f

Please sign in to comment.