2012-07-24 15.36.56

Two doors and two keys

This is a pretty simple idea. Basically you have a block that removes itself and 1 other block when you right click it with the correct key.

First, you need to create at least 1 key.


id = config.getItemId("keyGoldId");
name = "keyGold";
displayName = "Gold Key";
textureFile = "keyGold.jpg";
addToCreative = true;
creativeTab = "misc";
maxStack = 64;
full3d = false;

Second, you need the actual "door", which is actually a normal block with scripting for now. This might be possible on "door" types but is untested.


id = config.getBlockId("doorId");
name = "doorLocked";
displayName[0] = "Locked Door";
material = "wood";
stepSound ="wood";
hardness[0] = 1.0;
drop[0] = config.getBlockId("doorId") + ":0 0"; //drops nothing
addToCreative[0] = true;
creativeTab = "buildingBlocks";
textureFileXP[0] = "doorLockedKeyhole.jpg";
textureFileXN[0] = "doorLockedKeyhole.jpg";
textureFileYP[0] = "doorLockedTop.jpg";
textureFileYN[0] = "doorLockedTop.jpg";
textureFileZP[0] = "doorLockedKeyhole.jpg";
textureFileZN[0] = "doorLockedKeyhole.jpg";
onActivated[0] = "var currentItem = player.getItemId(player.getCurrentSlot());\
if(currentItem == config.getItemId('keyGoldId')) {world.setBlockId(position, 0);\
position.y--; world.setBlockId(position, 0);\
player.sendMessage('The door is open!'); player.remove(currentItem, 1, 0);\
} else { player.sendMessage('This door requires a gold key.');}";

if you want to have multiple keys open the same door, you need to add extra conditions like so:

if(currentItem == config.getItemId('keyGoldId')) || currentItem = 323) {//etc}

This makes the door open when using a gold key OR a vanilla sign (323).

Finally, add it all to your mod.js file to add it to the game.


config.addBlockIdProperty("doorId", 205);
config.addItemIdProperty("keyGoldId", 5000);

mod.addBlock("doorLocked.js", "normal");
mod.addItem("keyGold.js", "normal");

Here is a video showing the result of this example:

Keys and Doors

Keys and Doors

CS1 Custom Stuff 1

Information presented below this line is outdated syntax or information used for Custom Stuff 1. It will not work with Custom Stuff 2.

Here is the script of the door

name = "Door 1";
id = 170;
texturefile = "Mod.png";
textureindex = 0;
type = "normal";
maxstack = 1;
rightclicked="if(player.getItemId(player.getCurrentSlot()) != 1010){player.sendMessage('You need a gold key!');};if(player.getItemId(player.getCurrentSlot()) == 1010){world.setBlockId(origin, 0);origin.y--;world.setBlockId(origin, 0);player.sendMessage('The door is open!');player.removeFromInventory(player.getItemId(player.getCurrentSlot()), 1, 0)};";

Here is the script of the Key

name = "Key";
id = 1010;
iconfile = "Mod.png";
iconindex = 16;
type = "normal";

I hope that helped youlower

Community content is available under CC-BY-SA unless otherwise noted.