Debuggers: Added continuous hunger reporting.
Showcases the OnWorldTick() hook to fire events at regular intervals. Will be used for debugging the issues related to hyper-hunger.
This commit is contained in:
parent
2d7c72f1b7
commit
97aff179c1
@ -3,6 +3,7 @@ PLUGIN = {}; -- Reference to own plugin object
|
|||||||
|
|
||||||
g_DropSpensersToActivate = {}; -- A list of dispensers and droppers (as {World, X, Y Z} quadruplets) that are to be activated every tick
|
g_DropSpensersToActivate = {}; -- A list of dispensers and droppers (as {World, X, Y Z} quadruplets) that are to be activated every tick
|
||||||
g_HungerReportTick = 10;
|
g_HungerReportTick = 10;
|
||||||
|
g_ShowFoodStats = false; -- When true, each player's food stats are sent to them every 10 ticks
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ function Initialize(Plugin)
|
|||||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
|
||||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
|
||||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
||||||
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_WORLD_TICK);
|
||||||
|
|
||||||
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities");
|
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities");
|
||||||
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities");
|
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities");
|
||||||
@ -36,6 +38,7 @@ function Initialize(Plugin)
|
|||||||
PluginManager:BindCommand("/fl", "debuggers", HandleFoodLevelCmd, "- Sets the food level to the given value");
|
PluginManager:BindCommand("/fl", "debuggers", HandleFoodLevelCmd, "- Sets the food level to the given value");
|
||||||
PluginManager:BindCommand("/spidey", "debuggers", HandleSpideyCmd, "- Shoots a line of web blocks until it hits non-air");
|
PluginManager:BindCommand("/spidey", "debuggers", HandleSpideyCmd, "- Shoots a line of web blocks until it hits non-air");
|
||||||
PluginManager:BindCommand("/ench", "debuggers", HandleEnchCmd, "- Provides an instant dummy enchantment window");
|
PluginManager:BindCommand("/ench", "debuggers", HandleEnchCmd, "- Provides an instant dummy enchantment window");
|
||||||
|
PluginManager:BindCommand("/fs", "debuggers", HandleFoodStatsCmd, "- Turns regular foodstats message on or off");
|
||||||
|
|
||||||
-- Enable the following line for BlockArea / Generator interface testing:
|
-- Enable the following line for BlockArea / Generator interface testing:
|
||||||
-- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
|
-- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
|
||||||
@ -444,20 +447,28 @@ function OnTick()
|
|||||||
GCOnTick = GCOnTick - 1;
|
GCOnTick = GCOnTick - 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
return false;
|
||||||
if (g_HungerReportTick > 0) then
|
end
|
||||||
g_HungerReportTick = g_HungerReportTick - 1;
|
|
||||||
else
|
|
||||||
g_HungerReportTick = 10;
|
|
||||||
cRoot:Get():GetDefaultWorld():ForEachPlayer(
|
|
||||||
function(a_Player)
|
|
||||||
a_Player:SendMessage("FoodStat: " .. a_Player:GetFoodLevel() .. " / " .. a_Player:GetFoodExhaustionLevel());
|
function OnWorldTick(a_World, a_Dt)
|
||||||
|
local Tick = a_World:GetWorldAge();
|
||||||
|
if (not(g_ShowFoodStats) or (math.mod(Tick, 10) ~= 0)) then
|
||||||
|
return false;
|
||||||
end
|
end
|
||||||
|
a_World:ForEachPlayer(
|
||||||
|
function(a_Player)
|
||||||
|
a_Player:SendMessage(
|
||||||
|
tostring(Tick / 10) ..
|
||||||
|
" > FS: fl " .. a_Player:GetFoodLevel() ..
|
||||||
|
"; sat " .. a_Player:GetFoodSaturationLevel() ..
|
||||||
|
"; exh " .. a_Player:GetFoodExhaustionLevel()
|
||||||
);
|
);
|
||||||
end
|
end
|
||||||
]]
|
);
|
||||||
|
|
||||||
return false;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -708,7 +719,13 @@ function HandleFoodLevelCmd(a_Split, a_Player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
a_Player:SetFoodLevel(tonumber(a_Split[2]));
|
a_Player:SetFoodLevel(tonumber(a_Split[2]));
|
||||||
a_Player:SendMessage("Food level set to " .. a_Player:GetFoodLevel());
|
a_Player:SetFoodSaturationLevel(5);
|
||||||
|
a_Player:SetFoodExhaustionLevel(0);
|
||||||
|
a_Player:SendMessage(
|
||||||
|
"Food level set to " .. a_Player:GetFoodLevel() ..
|
||||||
|
", saturation reset to " .. a_Player:GetFoodSaturationLevel() ..
|
||||||
|
" and exhaustion reset to " .. a_Player:GetFoodExhaustionLevel()
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -748,9 +765,21 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function HandleEnchCmd(a_Split, a_Player)
|
function HandleEnchCmd(a_Split, a_Player)
|
||||||
local Wnd = cLuaWindow(cWindow.Enchantment, 1, 1, "Ench")
|
local Wnd = cLuaWindow(cWindow.Enchantment, 1, 1, "Ench");
|
||||||
a_Player:OpenWindow(Wnd)
|
a_Player:OpenWindow(Wnd);
|
||||||
Wnd:SetProperty(0, 10)
|
Wnd:SetProperty(0, 10);
|
||||||
Wnd:SetProperty(1, 15)
|
Wnd:SetProperty(1, 15);
|
||||||
Wnd:SetProperty(2, 25)
|
Wnd:SetProperty(2, 25);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function HandleFoodStatsCmd(a_Split, a_Player)
|
||||||
|
g_ShowFoodStats = not(g_ShowFoodStats);
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ bool cDeadlockDetect::Start(void)
|
|||||||
|
|
||||||
void cDeadlockDetect::Execute(void)
|
void cDeadlockDetect::Execute(void)
|
||||||
{
|
{
|
||||||
// Loop until the event is signalled
|
// Loop until the signal to terminate:
|
||||||
while (!m_ShouldTerminate)
|
while (!m_ShouldTerminate)
|
||||||
{
|
{
|
||||||
// Check the world ages:
|
// Check the world ages:
|
||||||
|
@ -340,9 +340,9 @@ void cPlayer::SetFoodTickTimer(int a_FoodTickTimer)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::SetFoodExhaustionLevel(double a_FoodSaturationLevel)
|
void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
|
||||||
{
|
{
|
||||||
m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodSaturationLevel, 4.0));
|
m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 4.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,14 +171,17 @@ public:
|
|||||||
void SetFoodLevel (int a_FoodLevel);
|
void SetFoodLevel (int a_FoodLevel);
|
||||||
void SetFoodSaturationLevel (double a_FoodSaturationLevel);
|
void SetFoodSaturationLevel (double a_FoodSaturationLevel);
|
||||||
void SetFoodTickTimer (int a_FoodTickTimer);
|
void SetFoodTickTimer (int a_FoodTickTimer);
|
||||||
void SetFoodExhaustionLevel (double a_FoodSaturationLevel);
|
void SetFoodExhaustionLevel (double a_FoodExhaustionLevel);
|
||||||
void SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining);
|
void SetFoodPoisonedTicksRemaining(int a_FoodPoisonedTicksRemaining);
|
||||||
|
|
||||||
/// Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full"
|
/// Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full"
|
||||||
bool Feed(int a_Food, double a_Saturation);
|
bool Feed(int a_Food, double a_Saturation);
|
||||||
|
|
||||||
/// Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values.
|
/// Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values.
|
||||||
void AddFoodExhaustion(double a_Exhaustion) { m_FoodExhaustionLevel += a_Exhaustion; }
|
void AddFoodExhaustion(double a_Exhaustion)
|
||||||
|
{
|
||||||
|
m_FoodExhaustionLevel += a_Exhaustion;
|
||||||
|
}
|
||||||
|
|
||||||
/// Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two
|
/// Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two
|
||||||
void FoodPoison(int a_NumTicks);
|
void FoodPoison(int a_NumTicks);
|
||||||
|
Loading…
Reference in New Issue
Block a user