|
@@ -1,14 +1,24 @@
|
|
|
event.load("block_click");
|
|
|
|
|
|
doors = list.new();
|
|
|
-trapdoors = list.new();
|
|
|
-fencegates = list.new();
|
|
|
-orig_state = map.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();
|
|
@@ -20,93 +30,118 @@ if(word.isSurvName(world_name) || world.isStoryName(world_name)) {
|
|
|
goto("wait");
|
|
|
|
|
|
@block_click
|
|
|
-if(block.hasTag(doors_tag, block) && action == "right") {
|
|
|
+if(block.hasTag(auto_door_tag, block) && action == "right") {
|
|
|
player_spec = player.getAutoCloseDoor(player);
|
|
|
- door_state_1 = block.getDoorStatus(block_loc);
|
|
|
- if(!door_state_1) {
|
|
|
- if(player_spec) {
|
|
|
- list.add(doors, block_loc);
|
|
|
- sgoto(60, "closedoor");
|
|
|
+ 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");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //Nach Doppeltür suchen
|
|
|
- door_loc_2 = block.getSecondDoor(block_loc);
|
|
|
- if(door_loc_2 != null) {
|
|
|
- door_state_2 = block.getDoorStatus(door_loc_2);
|
|
|
- if(door_state_1 && door_state_2) {
|
|
|
- block.setDoorStatus(door_loc_2, false);
|
|
|
- } elseif(!door_state_1 && !door_state_2) {
|
|
|
- block.setDoorStatus(door_loc_2, true);
|
|
|
+ //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");
|
|
|
}
|
|
|
- goto("wait");
|
|
|
-}
|
|
|
-if(block.hasTag(trapdoors_tag, block) && action == "right") {
|
|
|
- player_spec = player.getAutoCloseDoor(player);
|
|
|
- if(player_spec) {
|
|
|
- if(!map.contains(orig_state, block_loc)) {
|
|
|
- state = block.getTrapdoorStatus(block_loc);
|
|
|
- map.add(orig_state, block_loc, state);
|
|
|
- }
|
|
|
- list.add(trapdoors, block_loc);
|
|
|
- sgoto(60, "toggletrapdoor");
|
|
|
- }
|
|
|
- goto("wait");
|
|
|
-}
|
|
|
-if(block.hasTag(fencegates_tag, block) && action == "right") {
|
|
|
- player_spec = player.getAutoCloseDoor(player);
|
|
|
if(player_spec) {
|
|
|
- if(!map.contains(orig_state, block_loc)) {
|
|
|
- state = block.property.getValue(block_loc, open_prop);
|
|
|
- map.add(orig_state, block_loc, state);
|
|
|
+ if(!map.contains(orig_value_map, block_loc)) {
|
|
|
+ map.add(orig_value_map, block_loc, open_value);
|
|
|
}
|
|
|
- list.add(fencegates, block_loc);
|
|
|
- sgoto(60, "togglefencegate");
|
|
|
+ list.add(doors, block_loc);
|
|
|
+ sgoto(60, "closedoor");
|
|
|
}
|
|
|
- goto("wait");
|
|
|
}
|
|
|
goto("wait");
|
|
|
|
|
|
@closedoor
|
|
|
-doorloc = list.getIndex(doors, 0);
|
|
|
+door_loc = list.getIndex(doors, 0);
|
|
|
list.removeIndex(doors, 0);
|
|
|
-if(block.hasTag(doors_tag, block.get(doorloc))) {
|
|
|
- if(block.getDoorStatus(doorloc)) {
|
|
|
- block.setDoorStatus(doorloc, false);
|
|
|
+if(block.hasTag(auto_door_tag, block.get(door_loc))) {
|
|
|
+ //close door
|
|
|
+ open_value = door.isOpen(door_loc);
|
|
|
+ if(block.hasTag(doors_tag, block)) {
|
|
|
+ if(open_value) {
|
|
|
+ door.close(door_loc);
|
|
|
+ }
|
|
|
+ goto("wait");
|
|
|
}
|
|
|
-}
|
|
|
-goto("wait");
|
|
|
-
|
|
|
-@toggletrapdoor
|
|
|
-doorloc = list.getIndex(trapdoors, 0);
|
|
|
-list.removeIndex(trapdoors, 0);
|
|
|
-if(block.hasTag(trapdoors_tag, block.get(doorloc))) {
|
|
|
- state = map.get(orig_state, doorloc);
|
|
|
- if(state == null) {
|
|
|
+ //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");
|
|
|
}
|
|
|
- map.remove(orig_state, doorloc);
|
|
|
- if(block.getTrapdoorStatus(doorloc) != state) {
|
|
|
- block.setTrapdoorStatus(doorloc, state);
|
|
|
+ if(open_value) {
|
|
|
+ door.close(door_loc);
|
|
|
+ goto("wait");
|
|
|
}
|
|
|
+ door.open(door_loc);
|
|
|
}
|
|
|
goto("wait");
|
|
|
|
|
|
-@togglefencegate
|
|
|
-doorloc = list.getIndex(fencegates, 0);
|
|
|
-list.removeIndex(fencegates, 0);
|
|
|
-if(block.hasTag(fencegates_tag, block.get(doorloc))) {
|
|
|
- state = map.get(orig_state, doorloc);
|
|
|
- if(state == null) {
|
|
|
- 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);
|
|
|
}
|
|
|
- map.remove(orig_state, doorloc);
|
|
|
- if(block.property.getValue(doorloc, open_prop) != state) {
|
|
|
- //TODO
|
|
|
+ //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);
|
|
|
}
|
|
|
}
|
|
|
-goto("wait");
|
|
|
+
|
|
|
+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);
|
|
|
+ }
|
|
|
+}
|