Last active
January 14, 2017 04:23
-
-
Save hugmanrique/7d5d9824f648b652a4d5d66abbc1a5ea to your computer and use it in GitHub Desktop.
Apply gravity to your placed blocks in Minecraft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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