doors.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. event.load("block_click");
  2. doors = list.new();
  3. orig_value_map = map.new();
  4. auto_door_tag = block.getTag("km:auto_door");
  5. doors_tag = block.getTag("minecraft:wooden_doors");
  6. trapdoors_tag = block.getTag("minecraft:wooden_trapdoors");
  7. fencegates_tag = block.getTag("minecraft:fence_gates");
  8. half_prop = block.getProperty("double_block_half");
  9. open_prop = block.getProperty("open");
  10. block_sound_category = sound.getCategory("block");
  11. open_door_sound = sound.get("block.wooden_door.open");
  12. close_door_sound = sound.get("block.wooden_door.close");
  13. open_trapdoor_sound = sound.get("block.wooden_trapdoor.open");
  14. close_trapdoor_sound = sound.get("block.wooden_trapdoor.close");
  15. open_fencegate_sound = sound.get("block.fence_gate.open");
  16. close_fencegate_sound = sound.get("block.fence_gate.close");
  17. msg("dev", "§bDoors §rloaded.");
  18. @wait
  19. wait();
  20. loc = entity.getLocation(player);
  21. world_name = world.getName(loc.getWorld(loc));
  22. if(word.isSurvName(world_name) || world.isStoryName(world_name)) {
  23. ignoreGoto(event);
  24. }
  25. goto("wait");
  26. @block_click
  27. if(block.hasTag(auto_door_tag, block) && action == "right") {
  28. player_spec = player.getAutoCloseDoor(player);
  29. open_value = door.isOpen(block_loc);
  30. if(block.hasTag(doors_tag, block)) {
  31. if(!open_value) {
  32. if(player_spec) {
  33. list.add(doors, block_loc);
  34. sgoto(60, "closedoor");
  35. }
  36. }
  37. //Double door
  38. door_loc_2 = block.getSecondDoor(block_loc);
  39. if(door_loc_2 == null) {
  40. goto("wait");
  41. }
  42. open_value_2 = door.isOpen(door_loc_2);
  43. if(open_value && open_value_2) {
  44. door.close(door_loc_2);
  45. } elseif(!open_value && !open_value_2) {
  46. door.open(door_loc_2);
  47. if(player_spec) {
  48. list.add(doors, door_loc_2);
  49. sgoto(60, "closedoor");
  50. }
  51. }
  52. goto("wait");
  53. }
  54. if(player_spec) {
  55. if(!map.contains(orig_value_map, block_loc)) {
  56. map.add(orig_value_map, block_loc, open_value);
  57. }
  58. list.add(doors, block_loc);
  59. sgoto(60, "closedoor");
  60. }
  61. }
  62. goto("wait");
  63. @closedoor
  64. door_loc = list.getIndex(doors, 0);
  65. list.removeIndex(doors, 0);
  66. if(block.hasTag(auto_door_tag, block.get(door_loc))) {
  67. //close door
  68. open_value = door.isOpen(door_loc);
  69. if(block.hasTag(doors_tag, block)) {
  70. if(open_value) {
  71. door.close(door_loc);
  72. }
  73. goto("wait");
  74. }
  75. //toggle door
  76. orig_value = map.get(orig_value_map, door_loc);
  77. if(orig_value == null) {
  78. goto("wait");
  79. }
  80. map.remove(orig_value_map, door_loc);
  81. if(orig_value == open_value) {
  82. goto("wait");
  83. }
  84. if(open_value) {
  85. door.close(door_loc);
  86. goto("wait");
  87. }
  88. door.open(door_loc);
  89. }
  90. goto("wait");
  91. function door.isOpen(location) {
  92. return block.property.getValue(location, $open_prop);
  93. }
  94. function door.open(location) {
  95. block.property.setBool(location, $open_prop, true);
  96. //half
  97. half_value = block.property.getValue(location, $half_prop);
  98. if(half_value != null) {
  99. if(half_value == "upper") {
  100. half_loc = loc.mod(location, 0, -1, 0);
  101. } else {
  102. half_loc = loc.mod(location, 0, 1, 0);
  103. }
  104. block.property.setBool(half_loc, $open_prop, true);
  105. }
  106. //sound
  107. block = block.get(location);
  108. if(block.hasTag($doors_tag, block)) {
  109. sound.spawn(location, $open_door_sound, $block_sound_category);
  110. } elseif(block.hasTag($trapdoors_tag, block)) {
  111. sound.spawn(location, $open_trapdoor_sound, $block_sound_category);
  112. } elseif(block.hasTag($fencegates_tag, block)) {
  113. sound.spawn(location, $open_fencegate_sound, $block_sound_category);
  114. }
  115. }
  116. function door.close(location) {
  117. block.property.setBool(location, $open_prop, false);
  118. //half
  119. half_value = block.property.getValue(location, $half_prop);
  120. if(half_value != null) {
  121. if(half_value == "upper") {
  122. half_loc = loc.mod(location, 0, -1, 0);
  123. } else {
  124. half_loc = loc.mod(location, 0, 1, 0);
  125. }
  126. block.property.setBool(half_loc, $open_prop, false);
  127. }
  128. //sound
  129. block = block.get(location);
  130. if(block.hasTag($doors_tag, block)) {
  131. sound.spawn(location, $close_door_sound, $block_sound_category);
  132. } elseif(block.hasTag($trapdoors_tag, block)) {
  133. sound.spawn(location, $close_trapdoor_sound, $block_sound_category);
  134. } elseif(block.hasTag($fencegates_tag, block)) {
  135. sound.spawn(location, $close_fencegate_sound, $block_sound_category);
  136. }
  137. }