tModLoader How to code spreading block (Much needed page)

Quethed

Terrarian
Some of the "using" might be useless, idk
This is unfinished, but it has the basics for normal spread, and terrible grass
Anyone can contribute extra needed or related (to either grass or spreading blocks) code to this thread (Like how to set or edit conversion tables for example)
I give permission to example mod to use this if they want

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;
using Terraria.Enums;

namespace
{
public class SpreadingBlock : ModTile
{
int distance = 5;

public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
Main.tileBlockLight[Type] = true;
drop = mod.ItemType("SpreadingBlock");
AddMapEntry(new Color(200, 200, 200));
}

public override void RandomUpdate(int i, int j)
{
int LocationX = i;
int LocationY = j;
for (int x = LocationX - distance; x <= LocationX + distance; x++)
{
for (int y = LocationY - distance; y <= LocationY + distance; y++)
{
if (Vector2.Distance(new Vector2(LocationX, LocationY), new Vector2(x, y)) <= distance)
{
if (Main.tile[x, y].type == 1)
{
if (Main.rand.Next(15) == TileID.Stone)
{
Main.tile[x, y].type = (ushort)mod.TileType("SpreadingBlock");
}
}
}
}
}
}
}
public class SpreadingGrass : ModTile
{
int HouseTile = TileID.Dirt;
int HouseTileItem = ItemID.DirtBlock;
int distance = 1;

public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
Main.tileBlockLight[Type] = true;
AddMapEntry(new Color(200, 200, 200));
minPick = 1;
}

public override void RandomUpdate(int i, int j)
{
int LocationX = i;
int LocationY = j;
for (int x = LocationX - distance; x <= LocationX + distance; x++)
{
for (int y = LocationY - distance; y <= LocationY + distance; y++)
{
if (Vector2.Distance(new Vector2(LocationX, LocationY), new Vector2(x, y)) <= distance)
{
if (Main.tile[x, y].type == HouseTile)
{
if (Main.tile[x + 1, y].active() && Main.tile[x, y - 1].active() && Main.tile[x - 1, y].active() && Main.tile[x, y + 1].active() && Main.tile[x + 1, y + 1].active() && Main.tile[x - 1, y - 1].active() && Main.tile[x - 1, y + 1].active() && Main.tile[x + 1, y - 1].active())
{
}
else
{
if (Main.rand.Next(1) == 0)
{
Main.tile[x, y].type = (ushort)mod.TileType("SpreadingGrass");;
}
}
}
}
}
}
}

public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem)
{
WorldGen.PlaceTile(i, j, (ushort)HouseTile);
}
}
}
namespace
{
public class SpreadingBlock : ModItem
{
public override void SetDefaults()
{
item.width = 12;
item.height = 12;
item.maxStack = 999;
item.useTurn = true;
item.autoReuse = true;
item.useAnimation = 15;
item.useTime = 10;
item.useStyle = 1;
item.consumable = true;
item.createTile = mod.TileType("SpreadingBlock");
}
}
public class SpreadingGrass : ModItem
{
public override void SetDefaults()
{
item.width = 12;
item.height = 12;
item.maxStack = 999;
item.useTurn = true;
item.autoReuse = true;
item.useAnimation = 15;
item.useTime = 10;
item.useStyle = 1;
item.consumable = true;
item.createTile = mod.TileType("SpreadingGrass");
}
}
}
 

Attachments

  • SpreadingBlock.cs
    3.2 KB · Views: 139
Back
Top Bottom