Fandom

Minecraft Mod Custom Stuff Wiki

Redstone Powered Light Block

175pages on
this wiki
Add New Page
Comments3 Share
RedstonePoweredLight

Someone left the lights on.

This is an example of medium complexity showing how to make a "Lamp" block that can be activated or deactivated via redstone current. It showcases the basics of the activated/deactivated attributes, as well as how to change a block via a simple script.

Also, it lights stuff up so you can control monster spawning better. No pistons required!

mod.js

config.addBlockIdProperty("lampBlockID");
mod.addBlock("lampBlock.js", "normal");

lampBlocks.js

name = "lampBlock";
id = config.getBlockId("lampBlockID");
displayName[0] = "Lamp Block";
material = "glass";
stepSound = "glass";
opacity = 0;
transparent = true;
tileTransparent = true;

creativeTab = "decorations";
addToCreative[0] = true;
addToCreative[1] = false;

hardness[0] = 1;
resistance[0] = 5;
light[0] = 0;
drop[0] = config.getBlockId("lampBlockID") + ":0 0";
onRedstoneSignal[0] = "if(redstoneSignal == true)\
  {world.setBlockMetadata(position, 1);}";

hardness[1] = 1;
resistance[1] = 5;
light[1] = 15;
drop[1] = config.getBlockId("lampBlockID") + ":0 0";
onRedstoneSignal[1] = "if(redstoneSignal == false)\
  {world.setBlockMetadata(position, 0);}";

texturefile = "example.png";
textureIndexXP[0] = 0;
textureIndexXN[0] = 0;
textureIndexYP[0] = 0;
textureIndexYN[0] = 0;
textureIndexZP[0] = 0;
textureIndexZN[0] = 0;
textureIndexXP[1] = 33;
textureIndexXN[1] = 33;
textureIndexYP[1] = 33;
textureIndexYN[1] = 33;
textureIndexZP[1] = 33;
textureIndexZN[1] = 33;

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.

Basics

To start with, you can set up the basics of the block like you would any other Normal block. You can adjust things to your liking including the name, the material the block is made of, and of course whether it is transparent or not. For this example, we'll be using the one shown in the image above which is made from glass and is transparent when not lit.

name="Lamp Block";
id=220;
texturefile="example.png";
textureindex=0;
type="normal";
material="glass";
stepsound="glass";
hardness=1;
resistance=5;
iddropped=220;
opacity=0;   //An opaque block will block its own light.
transparency=true;
light=0;     //This must be set for the block to be unlit when placed.

Damage Values

Creating a block like this using only a single block ID is a matter of best practice. As such, we'll be setting up this block to change itself to a different damage value. In order to do that, the following attributes must be added to the block file in order to define the non-default values.

damagevalues=1;   //This shows we have one value above the default.
name1="Lamp Block";
light1=13;        //This is the light value of the 'on' state of the block
textureindex1=33; //The 'on' state uses a different texture in this example
damagedropped1=0;  //This tells the block to always drop its 'off' state

Switch Attributes

Now that both the on and off states of the block are clearly defined, the only thing remaining is to add a mechanism for switching between them. For this, the "activated" and "deactivated" triggers are applied. Each is set to change the block to its opposite form.

activated="world.setBlockIdAndMetadata(origin, 220, 1);";

This is the version that the game looks for when the block is in its 'off' state. It tells the game that when the 'off' light block gets redstone current it needs to change the block at Origin (where the block itself is) to ID 220 (itself), damage value #1 (the 'on' state). The reason why setBlockIdAndMetadata is used in this example is because the only way to get the game to update lighting is to update the block. Simply changing the damage value won't alter the lighting. On the other hand, if you're adapting this concept to a block that merely changes textures when activated you can use setBlockMetadata without issue.

With the activated attribute in place, there needs to be a corresponding trigger to turn the light block off when the redstone current is removed.

deactivated1="world.setBlockIdAndMetadata(origin, 220, 0);";

Note that the attribute is "deactivated1" and not simply "deactivated". This is because it's the 'on' state (damage value 1) that needs to be in charge of turning itself off when it is denied redstone current.

The actual variables in this one are set up exactly the same as in the other example, just from the other side of the on/off dichotomy.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.