123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- event.load("block_click");
- doors = list.new();
- orig_value_map = map.new();
- auto_door_tag = block.getTag("km:auto_door");
- doors_tag = block.getTag("minecraft:wooden_doors");
- trapdoors_tag = block.getTag("minecraft:wooden_trapdoors");
- fencegates_tag = block.getTag("minecraft:fence_gates");
- half_prop = block.getProperty("double_block_half");
- open_prop = block.getProperty("open");
- block_sound_category = sound.getCategory("block");
- open_door_sound = sound.get("block.wooden_door.open");
- close_door_sound = sound.get("block.wooden_door.close");
- open_trapdoor_sound = sound.get("block.wooden_trapdoor.open");
- close_trapdoor_sound = sound.get("block.wooden_trapdoor.close");
- open_fencegate_sound = sound.get("block.fence_gate.open");
- close_fencegate_sound = sound.get("block.fence_gate.close");
- msg("dev", "§bDoors §rloaded.");
- @wait
- wait();
- loc = entity.getLocation(player);
- world_name = world.getName(loc.getWorld(loc));
- if(world.isSurvName(world_name) || world.isStoryName(world_name)) {
- ignoreGoto(event);
- }
- goto("wait");
- @block_click
- if(block.hasTag(auto_door_tag, block) && action == "right") {
- player_spec = player.getAutoCloseDoor(player);
- open_value = door.isOpen(block_loc);
- if(block.hasTag(doors_tag, block)) {
- if(!open_value) {
- if(player_spec) {
- list.add(doors, block_loc);
- sgoto(60, "closedoor");
- }
- }
- //Double door
- door_loc_2 = block.getSecondDoor(block_loc);
- if(door_loc_2 == null) {
- goto("wait");
- }
- open_value_2 = door.isOpen(door_loc_2);
- if(open_value && open_value_2) {
- door.close(door_loc_2);
- } elseif(!open_value && !open_value_2) {
- door.open(door_loc_2);
- if(player_spec) {
- list.add(doors, door_loc_2);
- sgoto(60, "closedoor");
- }
- }
- goto("wait");
- }
- if(player_spec) {
- if(!map.contains(orig_value_map, block_loc)) {
- map.add(orig_value_map, block_loc, open_value);
- }
- list.add(doors, block_loc);
- sgoto(60, "closedoor");
- }
- }
- goto("wait");
- @closedoor
- door_loc = list.getIndex(doors, 0);
- list.removeIndex(doors, 0);
- block = block.get(door_loc);
- if(block.hasTag(auto_door_tag, block)) {
- //close door
- open_value = door.isOpen(door_loc);
- if(block.hasTag(doors_tag, block)) {
- if(open_value) {
- door.close(door_loc);
- }
- goto("wait");
- }
- //toggle door
- orig_value = map.get(orig_value_map, door_loc);
- if(orig_value == null) {
- goto("wait");
- }
- map.remove(orig_value_map, door_loc);
- if(orig_value == open_value) {
- goto("wait");
- }
- if(open_value) {
- door.close(door_loc);
- goto("wait");
- }
- door.open(door_loc);
- }
- goto("wait");
- function door.isOpen(location) {
- return block.property.getValue(location, $open_prop);
- }
-
- function door.open(location) {
- block.property.setBool(location, $open_prop, true);
- //half
- half_value = block.property.getValue(location, $half_prop);
- if(half_value != null) {
- if(half_value == "upper") {
- half_loc = loc.mod(location, 0, -1, 0);
- } else {
- half_loc = loc.mod(location, 0, 1, 0);
- }
- block.property.setBool(half_loc, $open_prop, true);
- }
- //sound
- block = block.get(location);
- if(block.hasTag($doors_tag, block)) {
- sound.spawn(location, $open_door_sound, $block_sound_category);
- } elseif(block.hasTag($trapdoors_tag, block)) {
- sound.spawn(location, $open_trapdoor_sound, $block_sound_category);
- } elseif(block.hasTag($fencegates_tag, block)) {
- sound.spawn(location, $open_fencegate_sound, $block_sound_category);
- }
- }
- function door.close(location) {
- block.property.setBool(location, $open_prop, false);
- //half
- half_value = block.property.getValue(location, $half_prop);
- if(half_value != null) {
- if(half_value == "upper") {
- half_loc = loc.mod(location, 0, -1, 0);
- } else {
- half_loc = loc.mod(location, 0, 1, 0);
- }
- block.property.setBool(half_loc, $open_prop, false);
- }
- //sound
- block = block.get(location);
- if(block.hasTag($doors_tag, block)) {
- sound.spawn(location, $close_door_sound, $block_sound_category);
- } elseif(block.hasTag($trapdoors_tag, block)) {
- sound.spawn(location, $close_trapdoor_sound, $block_sound_category);
- } elseif(block.hasTag($fencegates_tag, block)) {
- sound.spawn(location, $close_fencegate_sound, $block_sound_category);
- }
- }
|