Working with Wire
Comments15this wiki
Working with Wire
Edit
Hey, all! Bobrocket here, and I'm gonna teach you all how to make some pretty cool items that use wire.
Starting out
Edit
Alright, to start out, we are going to have a lamp. A simple, wired lamp.
Start off by making a basic tile, 1 block wide, 1 block high. Make sure "Shine" is set to 0 in the .ini file!
Basic C#:
|
public void Initialize(int x, int y)
} public void hitWire(int x, int y)
{
} |
This gets triggered when a wire signal hits our tile and also locks the X and Y position of the tile in.
Next, we want to control (like a lever) when it lights up and when it doesn't, so we add this:
public bool isLighted = false;
public void hitWire(int x, int y)
{
isLighted = !isLighted;
}
Now, whenever the tile gets hit, it'll switch isLighted between true and false.
But that isn't lighting anything! So, let's add a bit more:
|
public void AddLight(int x,int y,ref float r,ref float g,ref float b){if (isLighted)
}
} |
Alright, we added light whenever the isLighted bool is set to true! If you want a different color, look at the Lighting class for the syntax.
The full code:
|
public void initialize(int x, int y)
{
if (isLighted == true)
{r = 1f;
g = 0.4f;
b = 0.2f;
}
} |
Woo! Our first wire item complete!
Toggling other wire
To successfully power another wire or to power a block above, you will need some code.
Simply call this:
WorldGen.TripWire(i, j + 2); //Will power any wire 2 blocks below the tile's co-ordinates.
Syntax:
public static void TripWire(int i, int j) //i = x, j = y
Alright, that's about all for now with wire. I'll make more tutorials when I can!
-Bobrocket
Revised by Bullseye55.