Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TileID.Sets.PlanterBoxes #4061

Open
wants to merge 7 commits into
base: 1.4.4
Choose a base branch
from

Conversation

Lion8cake
Copy link
Contributor

@Lion8cake Lion8cake commented Feb 11, 2024

What is the new feature?

TileID.Sets.PlanterBoxes is a TileID set for all Planter Boxes. This allows any mod to add TileID.Sets.PlanterBoxes[Type] = true; and their tile will behave similar to vanilla planter boxes.

These changes include:
Smart Cursor
Herb and Grass growth/placement
Tile Framing
AnchorType.PlanterBox
Grass and Dirt spreading through tiles
Skeletron Prime bombs not falling through

This allows for quite easy implementation of the modder's own planter box for their herb and allows for a bunch of vanilla code to run for their tile.

Why should this be part of tModLoader?

You need to make 10-12 different IL edits to get a perfectly working planter box. This is not an option for some modders that either don't want to use IL edits or are too new to modding/C# to know how to make an IL edit, this isn't even to mention the amount of IL edits needed or how big some of them would be.
This also allows for modded planter boxes to merge together as currently only modded ones can merge with vanilla planter boxes.

Are there alternative designs?

To my knowledge no, I do think this is the best way of adding support for modded planter boxes. Adding planter boxes to the herb anchor in TileObjectData and referencing that for PlantAlch in WorldGen.cs would be a alternate approach to the herb placement issue if we don't need a whole TileID Set for this.

Sample usage for the new feature

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Content.Tiles
{
	public class ExamplePlanterBox : ModTile
	{
		public override void SetStaticDefaults()
		{
			Main.tileFrameImportant[Type] = true;
			Main.tileTable[Type] = true;
			Main.tileSolid[Type] = true;
			Main.tileSolidTop[Type] = true;
			AddMapEntry(new Color(200, 200, 200));
			TileID.Sets.DisableSmartCursor[Type] = true;
			TileID.Sets.IgnoresNearbyHalfbricksWhenDrawn[Type] = true; //All vanilla planter boxes have this
			TileID.Sets.PlanterBoxes[Type] = true; //This does a majority of the work for us,
												   //both allowing vanilla herbs to attach to our planterbox amongst a list of other things
			AdjTiles = new int[] { TileID.PlanterBox };
		}

		public override bool Slope(int i, int j)
		{
			return false; //We dont want our planter box to be slope-able so we return false
		}
	}
}

ExampleMod updates

Added Example Planter Box (Item and Tile),
This will show new modders how to easily add a planter box alongside their own herb.

Allows for easy implementation of modded planter boxes. This covers everything from generating grass to tile framing. An example is provided within.
I forgor an !
(also fixed the amoungus reference)
Lion8cake and others added 2 commits February 14, 2024 17:18
Comment on lines 59 to 63
TileObjectData.newTile.AnchorAlternateTiles = new int[] {
TileID.ClayPot,
TileID.PlanterBox
TileID.PlanterBox,
ModContent.TileType<ExamplePlanterBox>()
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit tricky because ideally it should include all modded planter boxes, not just vanillas + the one from the same mod. I'm not sure what the solution here would be except manually change the tileobjectdata somewhere around TileLoader.PostSetupTileMerge (when every mod has populated TileID.Sets.PlanterBoxes) for every modded tile that has TileID.PlanterBox in its AnchorAlternateTiles

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would require redoing everything that uses AnchorAlternateTiles or making a wrapper class that overrides equality comparison with ints, but making AnchorAlternateTiles support sets (or adding a separate field for sets) would solve this issue and potentially future ones.

@direwolf420
Copy link
Contributor

do modded planter boxes now allow torches to be placed on them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants