Merge pull request #2400 from drunderscore/feature/grow-code-dupe
Improved the `/grow` command to reduce code duplication, and allow easy future modification.
This commit is contained in:
commit
3bb3d7f00f
2 changed files with 105 additions and 228 deletions
|
|
@ -12,6 +12,10 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
||||||
* Do not forget to sign every line you change with your name. (@hakusaro)
|
* Do not forget to sign every line you change with your name. (@hakusaro)
|
||||||
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change.
|
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change.
|
||||||
|
|
||||||
|
|
||||||
|
## Upcoming changes
|
||||||
|
* Improved the `/grow` command to reduce code duplication, use `TileID` constants for less ambiguous types. (@drunderscore)
|
||||||
|
|
||||||
## TShock 4.5.13
|
## TShock 4.5.13
|
||||||
* Added hook `GetDataHandlers.OnReleaseNpc` to handling ReleaseNPC packet and a bouncer to stops unregistered and logged out players on SSC servers from releasing critters NPC. The bouncer has additional filter to stops players who tried to release different critter using crafted packet, e.g. using bunny item to release golden bunny. (@tru321)
|
* Added hook `GetDataHandlers.OnReleaseNpc` to handling ReleaseNPC packet and a bouncer to stops unregistered and logged out players on SSC servers from releasing critters NPC. The bouncer has additional filter to stops players who tried to release different critter using crafted packet, e.g. using bunny item to release golden bunny. (@tru321)
|
||||||
* Added filter in `GetDataHandlers.HandleCatchNpc` that stops unregistered and logged out players on SSC servers to catch critters. (@tru321)
|
* Added filter in `GetDataHandlers.HandleCatchNpc` that stops unregistered and logged out players on SSC servers to catch critters. (@tru321)
|
||||||
|
|
|
||||||
|
|
@ -6326,7 +6326,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static void Grow(CommandArgs args)
|
public static void Grow(CommandArgs args)
|
||||||
{
|
{
|
||||||
bool growevilAmb = args.Player.HasPermission(Permissions.growevil);
|
bool canGrowEvil = args.Player.HasPermission(Permissions.growevil);
|
||||||
string subcmd = args.Parameters.Count == 0 ? "help" : args.Parameters[0].ToLower();
|
string subcmd = args.Parameters.Count == 0 ? "help" : args.Parameters[0].ToLower();
|
||||||
|
|
||||||
var name = "Fail";
|
var name = "Fail";
|
||||||
|
|
@ -6368,284 +6368,163 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "basic":
|
bool rejectCannotGrowEvil()
|
||||||
|
{
|
||||||
|
if(!canGrowEvil)
|
||||||
|
{
|
||||||
|
args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool prepareAreaForGrow(ushort groundType = TileID.Grass, bool evil = false)
|
||||||
|
{
|
||||||
|
if(evil && !rejectCannotGrowEvil())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (var i = x - 2; i < x + 3; i++)
|
||||||
|
{
|
||||||
|
Main.tile[i, y].active(true);
|
||||||
|
Main.tile[i, y].type = groundType;
|
||||||
|
Main.tile[i, y].wall = WallID.None;
|
||||||
|
}
|
||||||
|
Main.tile[x, y - 1].wall = WallID.None;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool growTree(ushort groundType, string fancyName, bool evil = false)
|
||||||
|
{
|
||||||
|
if(!prepareAreaForGrow(groundType, evil))
|
||||||
|
return false;
|
||||||
|
WorldGen.GrowTree(x, y);
|
||||||
|
name = fancyName;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool growTreeByType(ushort groundType, string fancyName, ushort typeToPrepare = 2, bool evil = false)
|
||||||
|
{
|
||||||
|
if(!prepareAreaForGrow(typeToPrepare, evil))
|
||||||
|
return false;
|
||||||
|
WorldGen.TryGrowingTreeByType(groundType, x, y);
|
||||||
|
name = fancyName;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool growPalmTree(ushort sandType, ushort supportingType, string properName, bool evil = false)
|
||||||
|
{
|
||||||
|
if(evil && !rejectCannotGrowEvil())
|
||||||
|
return false;
|
||||||
|
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
for (int i = x - 2; i < x + 3; i++)
|
||||||
{
|
{
|
||||||
Main.tile[i, y].active(true);
|
Main.tile[i, y].active(true);
|
||||||
Main.tile[i, y].type = 2;
|
Main.tile[i, y].type = sandType;
|
||||||
Main.tile[i, y].wall = 0;
|
Main.tile[i, y].wall = WallID.None;
|
||||||
}
|
}
|
||||||
Main.tile[x, y - 1].wall = 0;
|
for (int i = x - 2; i < x + 3; i++)
|
||||||
WorldGen.GrowTree(x, y);
|
{
|
||||||
name = "Basic Tree";
|
Main.tile[i, y + 1].active(true);
|
||||||
|
Main.tile[i, y + 1].type = supportingType;
|
||||||
|
Main.tile[i, y + 1].wall = WallID.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.tile[x, y - 1].wall = WallID.None;
|
||||||
|
WorldGen.GrowPalmTree(x, y);
|
||||||
|
|
||||||
|
name = properName;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "basic":
|
||||||
|
growTree(TileID.Grass, "Basic Tree");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "boreal":
|
case "boreal":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTree(TileID.SnowBlock, "Boreal Tree");
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 147;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowTree(x, y);
|
|
||||||
name = "Boreal Tree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "mahogany":
|
case "mahogany":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTree(TileID.JungleGrass, "Rich Mahogany");
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 60;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowTree(x, y);
|
|
||||||
name = "Rich Mahogany";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "sakura":
|
case "sakura":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.VanityTreeSakura, "Sakura Tree");
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 2;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(596, x, y);
|
|
||||||
name = "Sakura Tree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "willow":
|
case "willow":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.VanityTreeYellowWillow, "Willow Tree");
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 2;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(616, x, y);
|
|
||||||
name = "Willow Tree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "shadewood":
|
case "shadewood":
|
||||||
if (growevilAmb)
|
if(!growTree(TileID.CrimsonGrass, "Shadewood Tree", true))
|
||||||
{
|
return;
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 199;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowTree(x, y);
|
|
||||||
name = "Shadewood tree";
|
|
||||||
}
|
|
||||||
else args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ebonwood":
|
case "ebonwood":
|
||||||
if (growevilAmb)
|
if(!growTree(TileID.CorruptGrass, "Ebonwood Tree", true))
|
||||||
{
|
return;
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 23;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowTree(x, y);
|
|
||||||
name = "Ebonwood Tree";
|
|
||||||
}
|
|
||||||
else args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "pearlwood":
|
case "pearlwood":
|
||||||
if (growevilAmb)
|
if(!growTree(TileID.HallowedGrass, "Pearlwood Tree", true))
|
||||||
{
|
return;
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 109;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowTree(x, y);
|
|
||||||
name = "Pearlwood Tree";
|
|
||||||
}
|
|
||||||
else args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "palm":
|
case "palm":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growPalmTree(TileID.Sand, TileID.HardenedSand, "Desert Palm");
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 53;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y + 1].active(true);
|
|
||||||
Main.tile[i, y + 1].type = 397;
|
|
||||||
Main.tile[i, y + 1].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowPalmTree(x, y);
|
|
||||||
name = "Desert Palm";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "hallowpalm":
|
case "hallowpalm":
|
||||||
if (growevilAmb)
|
if(!growPalmTree(TileID.Pearlsand, TileID.HallowHardenedSand, "Hallow Palm", true))
|
||||||
{
|
return;
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 116;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y + 1].active(true);
|
|
||||||
Main.tile[i, y + 1].type = 402;
|
|
||||||
Main.tile[i, y + 1].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowPalmTree(x, y);
|
|
||||||
name = "Hallow Palm";
|
|
||||||
}
|
|
||||||
else args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "crimsonpalm":
|
case "crimsonpalm":
|
||||||
if (growevilAmb)
|
if(!growPalmTree(TileID.Crimsand, TileID.CrimsonHardenedSand, "Crimson Palm", true))
|
||||||
{
|
return;
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 234;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y + 1].active(true);
|
|
||||||
Main.tile[i, y + 1].type = 399;
|
|
||||||
Main.tile[i, y + 1].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowPalmTree(x, y);
|
|
||||||
name = "Crimson Palm";
|
|
||||||
}
|
|
||||||
else args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "corruptpalm":
|
case "corruptpalm":
|
||||||
if (growevilAmb)
|
if(!growPalmTree(TileID.Ebonsand, TileID.CorruptHardenedSand, "Corruption Palm", true))
|
||||||
{
|
return;
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 112;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
|
||||||
{
|
|
||||||
Main.tile[i, y + 1].active(true);
|
|
||||||
Main.tile[i, y + 1].type = 398;
|
|
||||||
Main.tile[i, y + 1].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowPalmTree(x, y);
|
|
||||||
name = "Corruption Palm";
|
|
||||||
}
|
|
||||||
else args.Player.SendErrorMessage("You do not have permission to grow this tree type");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "topaz":
|
case "topaz":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeTopaz, "Topaz Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(583, x, y);
|
|
||||||
name = "Topaz Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "amethyst":
|
case "amethyst":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeAmethyst, "Amethyst Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(584, x, y);
|
|
||||||
name = "Amethyst Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "sapphire":
|
case "sapphire":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeSapphire, "Sapphire Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(585, x, y);
|
|
||||||
name = "Sapphire Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "emerald":
|
case "emerald":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeEmerald, "Emerald Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(586, x, y);
|
|
||||||
name = "Emerald Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ruby":
|
case "ruby":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeRuby, "Ruby Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(587, x, y);
|
|
||||||
name = "Ruby Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "diamond":
|
case "diamond":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeDiamond, "Diamond Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(588, x, y);
|
|
||||||
name = "Diamond Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "amber":
|
case "amber":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
growTreeByType(TileID.TreeAmber, "Amber Gemtree", 1);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 1;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.TryGrowingTreeByType(589, x, y);
|
|
||||||
name = "Amber Gemtree";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "cactus":
|
case "cactus":
|
||||||
Main.tile[x, y].type = 53;
|
Main.tile[x, y].type = TileID.Sand;
|
||||||
WorldGen.GrowCactus(x, y);
|
WorldGen.GrowCactus(x, y);
|
||||||
name = "Cactus";
|
name = "Cactus";
|
||||||
break;
|
break;
|
||||||
|
|
@ -6653,19 +6532,13 @@ namespace TShockAPI
|
||||||
case "herb":
|
case "herb":
|
||||||
Main.tile[x, y].active(true);
|
Main.tile[x, y].active(true);
|
||||||
Main.tile[x, y].frameX = 36;
|
Main.tile[x, y].frameX = 36;
|
||||||
Main.tile[x, y].type = 83;
|
Main.tile[x, y].type = TileID.MatureHerbs;
|
||||||
WorldGen.GrowAlch(x, y);
|
WorldGen.GrowAlch(x, y);
|
||||||
name = "Herb";
|
name = "Herb";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "mushroom":
|
case "mushroom":
|
||||||
for (int i = x - 2; i < x + 3; i++)
|
prepareAreaForGrow(TileID.MushroomGrass);
|
||||||
{
|
|
||||||
Main.tile[i, y].active(true);
|
|
||||||
Main.tile[i, y].type = 70;
|
|
||||||
Main.tile[i, y].wall = 0;
|
|
||||||
}
|
|
||||||
Main.tile[x, y - 1].wall = 0;
|
|
||||||
WorldGen.GrowShroom(x, y);
|
WorldGen.GrowShroom(x, y);
|
||||||
name = "Glowing Mushroom Tree";
|
name = "Glowing Mushroom Tree";
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue