Skip to content

Instantly share code, notes, and snippets.

@hugmanrique
Last active January 14, 2017 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugmanrique/7d5d9824f648b652a4d5d66abbc1a5ea to your computer and use it in GitHub Desktop.
Save hugmanrique/7d5d9824f648b652a4d5d66abbc1a5ea to your computer and use it in GitHub Desktop.
Apply gravity to your placed blocks in Minecraft
public class Gravity implements Listener {
private static final Vector GRAVITY = new Vector(0, -9.81F, 0);
private JavaPlugin plugin;
public Gravity(JavaPlugin plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onPlace(BlockPlaceEvent e) {
if (e.isCancelled() || !e.canBuild()) {
return;
}
e.setCancelled(true);
Block block = e.getBlockPlaced();
Location loc = e.getBlock().getLocation();
MaterialData data = new MaterialData(block.getType(), block.getData());
FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, data);
entity.setVelocity(GRAVITY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment