use of org.bukkit.material.Rails in project Glowstone by GlowstoneMC.
the class ItemMinecart method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
if (target == null || target.getType() != Material.RAILS) {
return;
}
if (minecartType.getMinecartClass() == null) {
player.sendMessage(ChatColor.RED + "Minecart type '" + minecartType.getEntityType().getName() + "' is not implemented.");
return;
}
Rails rails = (Rails) target.getState().getData();
Location location = target.getLocation().clone().add(Math.abs(rails.getDirection().getModX()) * 0.5, 0.1, Math.abs(rails.getDirection().getModZ()) * 0.5);
location.setYaw(getYaw(rails.getDirection()));
target.getWorld().spawn(location, minecartType.getEntityClass());
if (player.getGameMode() != GameMode.CREATIVE) {
player.getInventory().remove(holding);
}
super.rightClickBlock(player, target, face, holding, clickedLoc);
}
use of org.bukkit.material.Rails in project BKCommonLib by bergerhealer.
the class BlockUtil method setRails.
/**
* Sets the alignment of Rails. Note that this only supports the rails that
* can curve.
*
* @param rails to set the alignment for
* @param direction alignment
*/
@SuppressWarnings("deprecation")
public static void setRails(org.bukkit.block.Block rails, BlockFace direction) {
Material type = rails.getType();
if (type == Material.RAILS) {
int olddata = getRawData(rails);
Rails r = (Rails) MaterialUtil.getData(type, olddata);
r.setDirection(FaceUtil.toRailsDirection(direction), r.isOnSlope());
// If changed, update the data
if (MaterialUtil.getRawData(r) != olddata) {
setData(rails, r);
}
}
}