Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. root.setOnMousePressed(event -> {
  2.             for (Node n : root.getChildren()) {
  3.                 if (n instanceof Block) {
  4.                     Block block = (Block) n;
  5.  
  6.                     block.setOnMouseClicked(e -> {
  7.  
  8.                         if (event.getButton() == MouseButton.PRIMARY) {
  9.                             Object obj = e.getSource();
  10.  
  11.                             if (obj instanceof Block) {
  12.                                 Block b = (Block) obj;
  13.  
  14.                                 Block newB = new Block("minecraft_cobblestone.png", true);
  15.                                 newB.setTranslateX(b.getTranslateX());
  16.                                 newB.setTranslateY(b.getTranslateY());
  17.                                 newB.setDepth(20);
  18.                                 newB.setTranslateZ(b.getTranslateZ() - 20);
  19.                                 newB.setHeight(20);
  20.                                 newB.setWidth(20);
  21.  
  22.                                 root.getChildren().add(newB);
  23.                             }
  24.                         }
  25.  
  26.                         if (event.getButton() == MouseButton.SECONDARY) {
  27.                             Object obj = e.getSource();
  28.  
  29.                             if (obj instanceof Block) {
  30.                                 Block b = (Block) obj;
  31.  
  32.                                 if (b.isBreakable()) {
  33.                                     root.getChildren().remove(b);
  34.                                 }
  35.                             }
  36.                         }
  37.                     });
  38.                 }
  39.             }
  40.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement