-
Notifications
You must be signed in to change notification settings - Fork 2
/
lockable_door.js
40 lines (36 loc) · 1.26 KB
/
lockable_door.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Lockable Door Script by AnnikenYT
var key_name = "Anniken's key" // Name of the key.
var door_name = "Door" // This name will be displayed in information messages.
var locked = true; // Standart value. True means locked by default, false means open.
// DONT CHANGE!
function init(event) {
event.block.setBlockModel("minecraft:iron_door");
}
function interact(event) {
//Lock
if (!locked) {
if (event.player.getMainhandItem().getDisplayName() == key_name) {
locked = true
event.block.setBlockModel("minecraft:iron_door");
event.player.message("<" + door_name + "> This door is now locked");
event.player.playSound("minecraft:block.enchantment_table.use", 1, 1);
event.setCanceled(true);
}
}
//Unlock
else {
if (event.player.getMainhandItem().getDisplayName() == key_name) {
locked = false
event.block.setBlockModel("minecraft:wooden_door");
event.player.message("<" + door_name + "> This door is now unlocked");
event.player.playSound("minecraft:block.enchantment_table.use", 1, 1);
event.setCanceled(true);
}
//Tell player that door is locked
if (locked) {
event.setCanceled(true);
event.player.message("<" + door_name + "> This door is locked");
event.player.playSound("minecraft:block.enchantment_table.use", 1, 1);
}
}
}