// Place a TrainCart/Minecart on top of the rails, and handles permissions
return handleMinecartPlacement(player, clickedBlock, type);
} else if (type == heldItem.getType() && MaterialUtil.ISRAILS.get(type) && TrainCarts.allowRailEditing && clickInterval >= MAX_INTERACT_INTERVAL) {
if (BlockUtil.canBuildBlock(clickedBlock, type)) {
// Edit the rails to make a connection/face the direction the player clicked
BlockFace direction = FaceUtil.getDirection(player.getLocation().getDirection(), false);
BlockFace lastDirection = LogicUtil.fixNull(lastClickedDirection.get(player), direction);
Rails rails = BlockUtil.getRails(clickedBlock);
// First check whether we are clicking towards an up-slope block
if (MaterialUtil.ISSOLID.get(clickedBlock.getRelative(direction))) {
// Sloped logic
if (rails.isOnSlope()) {
if (rails.getDirection() == direction) {
// Switch between sloped and flat
rails.setDirection(direction, false);
} else {
// Other direction slope
rails.setDirection(direction, true);
}
} else {
// Set to slope
rails.setDirection(direction, true);
}
} else if (type == Material.RAILS) {
// This needs advanced logic for curves and everything!
BlockFace[] faces = FaceUtil.getFaces(rails.getDirection());
if (!LogicUtil.contains(direction.getOppositeFace(), faces)) {
// Try to make a connection towards this point
// Which of the two faces do we sacrifice?
BlockFace otherFace = faces[0] == lastDirection.getOppositeFace() ? faces[0] : faces[1];
rails.setDirection(FaceUtil.combine(otherFace, direction.getOppositeFace()), false);
}
} else {
// Simple switching (straight tracks)
rails.setDirection(direction, false);