FANDOM


Working with WireEdit

Hey, all! Bobrocket here, and I'm gonna teach you all how to make some pretty cool items that use wire.


Starting outEdit

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) 







{   X = x;   







  Y = 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)





{





if (isLighted == true)





{





  r = 1f;





  g = 0.4f;





  b = 0.4f;




}

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)





{





X = x;





Y = y;





}





public void hitWire(int x,int y)





{





isLighted = !isLighted





}







public void AddLight(int x,int y,ref float r,ref float g,ref float b)





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.

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.