Advertisement
Rain_Effect

Stair-Chair[1.12.2] v0.1

Sep 28th, 2019
1,584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var chairs = [
  2.     "minecraft:oak_stairs",
  3.     "minecraft:stone_stairs",
  4.     "minecraft:brick_stairs",
  5.     "minecraft:stone_brick_stairs",
  6.     "minecraft:nether_brick_stairs",
  7.     "minecraft:sandstone_stairs",
  8.     "minecraft:spruce_stairs",
  9.     "minecraft:birch_stairs",
  10.     "minecraft:jjungle_stairs",
  11.     "minecraft:quartz_stairs",
  12.     "minecraft:acacia_stairs",
  13.     "minecraft:dark_oak_stairs",
  14.     "minecraft:red_sandstone_stairs",
  15.     "minecraft:purpur_stairs"
  16. ];
  17.  
  18. var chairs_msg = {
  19.     blocked: "You can't sit on it when it was getting blocked.",
  20.     sitting: "Maybe someone is sitting on it before than you.",
  21.     higher: "You can't sit on it because your leg is too short."
  22. }
  23.  
  24. function interact(e){
  25.     if(e.type == 2 &&
  26.        chairs.indexOf(e.target.name) != -1 &&
  27.        e.target.metadata < 4 &&
  28.        e.player.mainhandItem.name == "minecraft:air" &&
  29.        e.player.offhandItem.name == "minecraft:air" &&
  30.        ! e.player.isSneaking()
  31.       ){
  32.         e.setCanceled(true);
  33.         if(!e.target.world.getBlock(e.target.x, e.target.y+1, e.target.z).isAir()) {
  34.             e.API.executeCommand(e.target.world, "/title " + e.player.name + " actionbar {\"text\":\"" + chairs_msg.blocked + "\"}");
  35.             return;
  36.         }
  37.         if(e.player.world.getNearbyEntities(e.target.pos, 0, -1).length != 0) {
  38.             e.API.executeCommand(e.target.world, "/title " + e.player.name + " actionbar {\"text\":\"" + chairs_msg.sitting + "\"}");
  39.             return;
  40.         }
  41.         if(e.player.y < e.target.y-1) {
  42.             e.API.executeCommand(e.target.world, "/title " + e.player.name + " actionbar {\"text\":\"" + chairs_msg.higher + "\"}");
  43.             return;
  44.         }
  45.         var chair = e.player.world.createEntity("armor_stand");
  46.         chair.setPosition(e.target.x+0.5, e.target.y+0.35, e.target.z+0.5);
  47.         chair.spawn();
  48.         var nbt = chair.getEntityNbt();
  49.         nbt.setByte("Small", 1);
  50.         nbt.setByte("NoBasePlate", 1);
  51.         nbt.setByte("Invulnerable", 1);
  52.         nbt.setByte("FallFlying", 1);
  53.         nbt.setByte("Marker", 1);
  54.         nbt.setByte("NoGravity", 1);
  55.         nbt.setByte("Invisible", 1);
  56.         chair.setEntityNbt(nbt);
  57.         chair.addRider(e.player);
  58.         if(e.player.tempdata.has("chair")) e.player.tempdata.get("chair").despawn();
  59.         e.player.tempdata.put("chair", chair);
  60.     }
  61. }
  62.  
  63. function tick(e){
  64.     if(e.player.tempdata.has("chair")){
  65.         var temp = e.player.tempdata.get("chair");
  66.         if(temp.getRiders().length == 0 ||
  67.            chairs.indexOf(e.player.world.getBlock(temp.blockX, temp.blockY, temp.blockZ).name)==-1
  68.           ){
  69.             temp.despawn();
  70.             e.player.tempdata.remove("chair");
  71.         }
  72.     }
  73. }
  74.  
  75. function logout(e){
  76.     if(e.player.tempdata.has("chair")){
  77.         e.player.tempdata.get("chair").despawn();
  78.         e.player.tempdata.remove("chair");
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement