tModLoader Custom Grass/Blocks that spread?

Dual Iron

Plantera
If I wanted to create, say, grass for a custom biome (that can spread over specific blocks), how would I identify the blocks it spreads to, how often it spreads to them, how far it can spread, and...well...HOW it can spread?
 
Alright I was wondering the same, and I think the only way to create your own grass is to basically create a tile that looks like how you want your grass to look with the dirt as well, and then if you want it to spread you override RandomUpdate (int i, int j) and you put in some code that detects adjacent grass tiles(do if(Main.tile[i, j].type == 2 /*Numerical id for grass*/) You'll have to change up the i and j, eg [i + 1, j - 1] and other values to detect adjacent tiles) and kill them and place your tile (WorldGen.PlaceTile(i, j, mod.TileType("YourCustomGrass"));). As for the thing with breaking the grass then the dirt (you know how when you attack grass with a pick the grass breaks, and then you mine the dirt?) Well you'd have to override KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) and make the tile kill itself (Make sure your tile doesn't drop anything) and create a block of dirt in it's position, with WorldGen.KillTile(i, j); to kill the tile, and WorldGen.PlaceTile(i, j, TileID.Dirt); to place dirt (if for whatever reason the tile does not create dirt upon being hit with a pick, then you will have to create a projectile that the grass spawns upon death, and have that place the dirt. I've had this problem before, in my creation of custom traps). Then in order to make your grass compatible with solutions (this bit will be the most complex) you'll have to go into your GlobalProjectile file (if you have one, if not then make one) and have that detect if any solutions were near your tile and then kill your tile and the dirt, and place the grass tile corresponding to the solution.

I hope this helps, please reply if you do not understand any of it, need clarification or need help, I will be happy to assist. Also if you would like some solid code, I would be happy to provide that once I have done it. :)

I just kind of made it up as I went along, really, so sorry if it isn't the most clear or concise. I have to say, it is more complex than I thought it would be when I started typing XD.

Also if you have already made custom grass, or know an easier way to do something, or think I've said to do something wrong, please say

Edit: Here's a grass spritesheet you could use

Another Edit: Don't use what I said above for spreading grass, use: WorldGen.SpreadGrass(i , j, TileID.Dirt, mod.TileType("YourGrassName"), false, 0);
You'll have to repeat that for other tiles you want your grass to spread to, changing TileID.Dirt to that tile ID

Ok nevermind it is a lot harder to make the grass tile sprites work in-game. Unless there's an easier way, I think you'll have to resort to manually drawing the tiles in-game, and using logic to detect surrounding tiles of the appropriate type (use Main.tile[i, j].type == TileID.Dirt in if(), replacing the tile id as necessary)
 

Attachments

  • TerrariaGrassSpritesheet.png
    TerrariaGrassSpritesheet.png
    13.5 KB · Views: 9,273
Last edited:
Has anyone actually found an easier way of making modded grass
I found this while trying to make my own modded grass
 
Back
Top Bottom