Add farmland drop

This commit is contained in:
zontreck 2025-05-07 12:15:23 -07:00
parent 9715975a48
commit 419c05dbac
5 changed files with 113 additions and 3 deletions

View file

@ -559,6 +559,38 @@ namespace AriasServerUtils
else return TextCommandResult.Success(); else return TextCommandResult.Success();
} }
internal static TextCommandResult HandleUpdateASUFarmlandDowngrade(TextCommandCallingArgs args)
{
if (args[0] is bool downgrade)
{
// Update the flag
ServerUtilities.config.EnableFarmlandDowngrade = downgrade;
ServerUtilities.MarkDirty();
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig"));
}
else
{
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:farmland-downgrade", ServerUtilities.config.EnableFarmlandDowngrade));
}
}
internal static TextCommandResult HandleUpdateASUFarmlandDrop(TextCommandCallingArgs args)
{
if (args[0] is bool drop)
{
// Update the flag
ServerUtilities.config.EnableFarmlandDrop = drop;
ServerUtilities.MarkDirty();
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig"));
}
else
{
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:farmland-drop", ServerUtilities.config.EnableFarmlandDrop));
}
}
internal static TextCommandResult HandleListCooldowns(TextCommandCallingArgs args) internal static TextCommandResult HandleListCooldowns(TextCommandCallingArgs args)
{ {
string sReturn = "SERVER COOLDOWN SETTINGS\n"; string sReturn = "SERVER COOLDOWN SETTINGS\n";
@ -588,5 +620,53 @@ namespace AriasServerUtils
} }
return TextCommandResult.Success(); return TextCommandResult.Success();
} }
internal static void CheckBreakFarmland(IServerPlayer byPlayer, BlockSelection blockSel, ref float dropQuantityMultiplier, ref EnumHandling handling)
{
if (!ServerUtilities.config.EnableFarmlandDrop)
{
return; // Default behavior
}
if (blockSel.Block is BlockFarmland farmland)
{
BlockEntityFarmland beFarmland = farmland.GetBlockEntity<BlockEntityFarmland>(blockSel.Position);
string farmlandType = blockSel.Block.LastCodePart();
if (ServerUtilities.config.EnableFarmlandDowngrade)
{
switch (farmlandType)
{
case "verylow":
{ // barren
break; // Can't downgrade further
}
case "low":
{
farmlandType = "verylow";
break;
}
case "medium":
{
farmlandType = "low";
break;
}
case "compost":
{ // high
farmlandType = "medium";
break;
}
case "high":
{ // Terra preta
farmlandType = "compost";
break;
}
}
}
byPlayer.Entity.World.SpawnItemEntity(new ItemStack(byPlayer.Entity.World.GetBlock(new AssetLocation($"soil-{farmlandType}-none"))), blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5));
}
}
} }
} }

View file

@ -22,7 +22,7 @@ namespace AriasServerUtils
{ CooldownType.RTP, "30s" }, { CooldownType.RTP, "30s" },
{ CooldownType.Back, "5s" } { CooldownType.Back, "5s" }
}; };
private static readonly int CURRENT_VERSION = 5; private static readonly int CURRENT_VERSION = 6;
public int Version { get; set; } = 0; public int Version { get; set; } = 0;
@ -36,11 +36,25 @@ namespace AriasServerUtils
public int MaxRTPBlockDistance { get; set; } = 50000; public int MaxRTPBlockDistance { get; set; } = 50000;
public Dictionary<CooldownType, string> Cooldowns { get; set; } = new Dictionary<CooldownType, string>(); public Dictionary<CooldownType, string> Cooldowns { get; set; } = new Dictionary<CooldownType, string>();
/// <summary>
/// If true, attempts to downgrade the soil quality when breaking farmland.
/// </summary>
public bool EnableFarmlandDowngrade { get; set; } = false;
/// <summary>
/// If true, farmland will drop as soil when broken.
/// </summary>
public bool EnableFarmlandDrop { get; set; } = true;
public Dictionary<CooldownType, string> GetDefaultCooldowns() public Dictionary<CooldownType, string> GetDefaultCooldowns()
{ {
return m_defaultCD; return m_defaultCD;
} }
/// <summary>
/// Performs some checks against known possible invalid values and sets them to sane values.
/// </summary>
public void SanityCheck() public void SanityCheck()
{ {
foreach (var cd in GetDefaultCooldowns()) foreach (var cd in GetDefaultCooldowns())

View file

@ -94,6 +94,7 @@ namespace AriasServerUtils
api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerJoin += OnPlayerJoin;
api.Event.PlayerDisconnect += OnPlayerDC; api.Event.PlayerDisconnect += OnPlayerDC;
api.Event.ChunkColumnLoaded += RTPFactory.ChunkLoaded; api.Event.ChunkColumnLoaded += RTPFactory.ChunkLoaded;
api.Event.BreakBlock += Events.CheckBreakFarmland;
//api.Event.PlayerLeave += OnPlayerDC; //api.Event.PlayerLeave += OnPlayerDC;
@ -181,6 +182,18 @@ namespace AriasServerUtils
.WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position (Default is 50000)") .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position (Default is 50000)")
.HandleWith(Events.HandleUpdateASURTPMax) .HandleWith(Events.HandleUpdateASURTPMax)
.EndSubCommand() .EndSubCommand()
.BeginSubCommand("farmlandDowngrade")
.RequiresPrivilege(Privilege.controlserver)
.WithArgs(parsers.OptionalBool("downgrade"))
.WithDescription("Enables or disables farmland downgrade when breaking farmland")
.HandleWith(Events.HandleUpdateASUFarmlandDowngrade)
.EndSubCommand()
.BeginSubCommand("farmlandDrop")
.RequiresPrivilege(Privilege.controlserver)
.WithArgs(parsers.OptionalBool("drop"))
.WithDescription("Enables or disables dropping soil when breaking farmland")
.HandleWith(Events.HandleUpdateASUFarmlandDrop)
.EndSubCommand()
.BeginSubCommand("cooldowns") .BeginSubCommand("cooldowns")
.WithDescription("Commands related to all the various cooldowns") .WithDescription("Commands related to all the various cooldowns")
.BeginSubCommand("back") .BeginSubCommand("back")

View file

@ -23,6 +23,9 @@
"updatedconfig": "[ASU] server config updated", "updatedconfig": "[ASU] server config updated",
"config-value-reset": "[ASU] server config value reset to default", "config-value-reset": "[ASU] server config value reset to default",
"farmland-downgrade": "The current farmland downgrade setting is {0}",
"farmland-drop": "The current farmland drop setting is {0}",
"warp-tp": "Teleported to warp [{0}]", "warp-tp": "Teleported to warp [{0}]",
"warp-set": "Warp [{0}] created!", "warp-set": "Warp [{0}] created!",
"warp-no": "You lack permissions to manage a warp", "warp-no": "You lack permissions to manage a warp",

View file

@ -3,8 +3,8 @@
"modid": "ariasserverutils", "modid": "ariasserverutils",
"name": "Aria's Server Utilities", "name": "Aria's Server Utilities",
"authors": ["zontreck"], "authors": ["zontreck"],
"description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:23 PM MST", "description": "A collection of server utilities\n\nBuild Date: 05-7-2025 @ 12:15 AM MST",
"version": "1.0.10", "version": "1.0.11-dev.1",
"dependencies": { "dependencies": {
"game": "" "game": ""
} }