summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CONTRIBUTORS1
-rw-r--r--MCServer/Plugins/APIDump/main_APIDump.lua10
-rw-r--r--src/CheckBasicStyle.lua103
-rw-r--r--src/Mobs/Monster.cpp24
-rw-r--r--src/Mobs/Monster.h4
-rw-r--r--src/Mobs/Skeleton.cpp20
-rw-r--r--src/Mobs/Skeleton.h5
-rw-r--r--src/Mobs/Zombie.cpp24
-rw-r--r--src/Mobs/Zombie.h8
-rw-r--r--src/World.cpp2
10 files changed, 135 insertions, 66 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 9a0a675e7..a25c6f06b 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -20,6 +20,7 @@ mtilden
nesco
p-mcgowan
rs2k
+SafwatHalaby (Safwat Halaby)
SamJBarney
Sofapriester
SphinxC0re
diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua
index 239bec69c..013ec7bef 100644
--- a/MCServer/Plugins/APIDump/main_APIDump.lua
+++ b/MCServer/Plugins/APIDump/main_APIDump.lua
@@ -1643,6 +1643,15 @@ end
+local function HandleCmdApiShow(a_Split, a_EntireCmd)
+ os.execute("API" .. cFile:GetPathSeparator() .. "index.html")
+ return true, "Launching the browser to show the API docs..."
+end
+
+
+
+
+
function Initialize(Plugin)
g_Plugin = Plugin;
g_PluginFolder = Plugin:GetLocalFolder();
@@ -1651,6 +1660,7 @@ function Initialize(Plugin)
-- Bind a console command to dump the API:
cPluginManager:BindConsoleCommand("api", HandleCmdApi, "Dumps the Lua API docs into the API/ subfolder")
+ cPluginManager:BindConsoleCommand("apishow", HandleCmdApiShow, "Runs the default browser to show the API docs")
-- Add a WebAdmin tab that has a Dump button
g_Plugin:AddWebTab("APIDump", HandleWebAdminDump)
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index 19156b537..8cd454e8f 100644
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -266,14 +266,113 @@ end
+--- Array of files to process. Filled from cmdline arguments
+local ToProcess = {}
+
+
+
+
+
+--- Handlers for the command-line arguments
+-- Maps flag => function
+local CmdLineHandlers =
+{
+ -- "-f file" checks the specified file
+ ["-f"] = function (a_Args, a_Idx)
+ local fnam = a_Args[a_Idx + 1]
+ if not(fnam) then
+ error("Invalid flag: '-f' needs a filename following it.")
+ end
+ table.insert(ToProcess, fnam)
+ return a_Idx + 2 -- skip the filename in param parsing
+ end,
+
+ -- "-g" checks files reported by git as being committed.
+ ["-g"] = function (a_Args, a_Idx)
+ local f = io.popen("git diff --cached --name-only --diff-filter=ACMR")
+ for fnam in f:lines() do
+ table.insert(ToProcess, fnam)
+ end
+ end,
+
+ -- "-h" prints help and exits
+ ["-h"] = function (a_Args, a_Idx)
+ print([[
+Usage:")
+"CheckBasicStyle [<options>]
+
+Available options:
+-f <filename> - checks the specified filename
+-g - checks files reported by Git as being committed
+-h - prints this help and exits
+-l <listfile> - checks all files listed in the specified listfile
+-- - reads the list of files to check from stdin
+
+When no options are given, the script checks all files listed in the AllFiles.lst file.
+
+Only .cpp and .h files are ever checked.
+]])
+ os.exit(0)
+ end,
+
+ -- "-l listfile" loads the list of files to check from the specified listfile
+ ["-l"] = function (a_Args, a_Idx)
+ local listFile = a_Args[a_Idx + 1]
+ if not(listFile) then
+ error("Invalid flag: '-l' needs a filename following it.")
+ end
+ for fnam in io.lines(listFile) do
+ table.insert(ToProcess, fnam)
+ end
+ return a_Idx + 2 -- Skip the listfile in param parsing
+ end,
+
+ -- "--" reads the list of files from stdin
+ ["--"] = function (a_Args, a_Idx)
+ for fnam in io.lines() do
+ table.insert(ToProcess, fnam)
+ end
+ end,
+}
+
+
+
+
+
-- Remove buffering from stdout, so that the output appears immediately in IDEs:
io.stdout:setvbuf("no")
--- Process all files in the AllFiles.lst file (generated by cmake):
-for fnam in io.lines("AllFiles.lst") do
+-- Parse the cmdline arguments to see what files to check:
+local idx = 1
+while (arg[idx]) do
+ local handler = CmdLineHandlers[arg[idx]]
+ if not(handler) then
+ error("Unknown command-line argument #" .. idx .. ": " .. arg[idx])
+ end
+ idx = handler(arg, idx) or (idx + 1) -- Call the handler, let it change the next index if it wants
+end
+
+
+-- By default process all files in the AllFiles.lst file (generated by cmake):
+if not(arg[1]) then
+ for fnam in io.lines("AllFiles.lst") do
+ table.insert(ToProcess, fnam)
+ end
+end
+
+
+
+
+
+-- Process the files in the list:
+for _, fnam in ipairs(ToProcess) do
ProcessItem(fnam)
end
+
+
+
+
-- Report final verdict:
print("Number of violations found: " .. g_NumViolations)
if (g_NumViolations > 0) then
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index e9b171e49..9b9bec51e 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -142,7 +142,7 @@ void cMonster::TickPathFinding(cChunk & a_Chunk)
case ePathFinderStatus::PATH_NOT_FOUND:
{
- FinishPathFinding();
+ ResetPathFinding();
break;
}
@@ -164,7 +164,7 @@ void cMonster::TickPathFinding(cChunk & a_Chunk)
}
if (m_Path->IsLastPoint())
{
- FinishPathFinding();
+ ResetPathFinding();
}
break;
@@ -191,7 +191,7 @@ void cMonster::MoveToPosition(const Vector3d & a_Position)
void cMonster::StopMovingToPosition()
{
m_bMovingToDestination = false;
- FinishPathFinding();
+ ResetPathFinding();
}
@@ -209,7 +209,7 @@ bool cMonster::IsCoordinateInTraversedList(Vector3i a_Coords)
/* No one should call this except the pathfinder orthe monster tick or StopMovingToPosition.
Resets the pathfinder, usually starting a brand new path, unless called from StopMovingToPosition. */
-void cMonster::FinishPathFinding(void)
+void cMonster::ResetPathFinding(void)
{
if (m_Path != nullptr)
{
@@ -254,6 +254,7 @@ bool cMonster::ReachedFinalDestination()
void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
+ GET_AND_VERIFY_CURRENT_CHUNK(Chunk, POSX_TOINT, POSZ_TOINT);
if (m_Health <= 0)
{
@@ -276,7 +277,8 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
// Burning in daylight
- HandleDaylightBurning(a_Chunk);
+ bool WouldBurnRightNow = WouldBurnAt(GetPosition(), *Chunk); // cached so that we use it twice, spares some cycles.
+ HandleDaylightBurning(*Chunk, WouldBurnRightNow);
@@ -300,7 +302,12 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
if (--m_GiveUpCounter == 0)
{
- FinishPathFinding();
+ ResetPathFinding(); // Not to be confused with StopMovingToPosition, this just discards the current path and calculates another.
+ }
+ else if (m_BurnsInDaylight && WouldBurnAt(m_Destination, *Chunk) && !WouldBurnRightNow && (m_TicksSinceLastDamaged == 100))
+ {
+ // If we burn in daylight, and we would burn at the next step, and we won't burn where we are right now, and we weren't provoked recently:
+ StopMovingToPosition();
}
else
{
@@ -1091,7 +1098,7 @@ void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, short a_LootingLevel)
-void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
+void cMonster::HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn)
{
if (!m_BurnsInDaylight)
{
@@ -1110,7 +1117,7 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk)
return;
}
- if (WouldBurnAt(GetPosition(), a_Chunk))
+ if (!IsOnFire() && WouldBurn)
{
// Burn for 100 ticks, then decide again
StartBurning(100);
@@ -1129,7 +1136,6 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk)
(a_Chunk.GetSkyLight(RelX, RelY, RelZ) == 15) && // In the daylight
(a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand
(GetWorld()->GetTimeOfDay() < (12000 + 1000)) && // It is nighttime
- !IsOnFire() && // Not already burning
GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) // Not raining
)
{
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index 56efa056a..9699e74ad 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -208,7 +208,7 @@ protected:
This is based on the ultimate, final destination and the current position, as well as the traversed coordinates, and any environmental hazards */
void TickPathFinding(cChunk & a_Chunk);
/** Finishes a pathfinding task, be it due to failure or something else */
- void FinishPathFinding(void);
+ void ResetPathFinding(void);
/** Sets the body yaw and head yaw/pitch based on next/ultimate destinations */
void SetPitchAndYawFromDestination(void);
@@ -244,7 +244,7 @@ protected:
bool m_CanPickUpLoot;
int m_TicksSinceLastDamaged; // How many ticks ago we were last damaged by a player?
- void HandleDaylightBurning(cChunk & a_Chunk);
+ void HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn);
bool WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk);
bool m_BurnsInDaylight;
double m_RelativeWalkSpeed;
diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp
index ef049f8d4..f99404669 100644
--- a/src/Mobs/Skeleton.cpp
+++ b/src/Mobs/Skeleton.cpp
@@ -48,26 +48,6 @@ void cSkeleton::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-void cSkeleton::MoveToPosition(const Vector3d & a_Position)
-{
- // Todo use WouldBurnAt(), not sure how to obtain a chunk though...
- super::MoveToPosition(a_Position); // Look at the player and update m_Destination to hit them if they're close
-
- // If the destination is sufficiently skylight challenged AND the skeleton isn't on fire AND we weren't attacked recently then block the movement
- if (
- !IsOnFire() &&
- (m_World->GetBlockSkyLight((int)floor(a_Position.x), (int)floor(a_Position.y), (int)floor(a_Position.z)) - m_World->GetSkyDarkness() > 8) &&
- m_TicksSinceLastDamaged == 100
- )
- {
- StopMovingToPosition();
- }
-}
-
-
-
-
-
void cSkeleton::Attack(std::chrono::milliseconds a_Dt)
{
m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
diff --git a/src/Mobs/Skeleton.h b/src/Mobs/Skeleton.h
index 9c49c52fb..1b6ce4bf2 100644
--- a/src/Mobs/Skeleton.h
+++ b/src/Mobs/Skeleton.h
@@ -11,19 +11,18 @@ class cSkeleton :
public cAggressiveMonster
{
typedef cAggressiveMonster super;
-
+
public:
cSkeleton(bool IsWither);
CLASS_PROTODEF(cSkeleton)
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual void MoveToPosition(const Vector3d & a_Position) override;
virtual void Attack(std::chrono::milliseconds a_Dt) override;
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual bool IsUndead(void) override { return true; }
-
+
bool IsWither(void) const { return m_bIsWither; }
private:
diff --git a/src/Mobs/Zombie.cpp b/src/Mobs/Zombie.cpp
index b2738050e..fa4ac855d 100644
--- a/src/Mobs/Zombie.cpp
+++ b/src/Mobs/Zombie.cpp
@@ -37,27 +37,3 @@ void cZombie::GetDrops(cItems & a_Drops, cEntity * a_Killer)
AddRandomArmorDropItem(a_Drops, LootingLevel);
AddRandomWeaponDropItem(a_Drops, LootingLevel);
}
-
-
-
-
-
-void cZombie::MoveToPosition(const Vector3d & a_Position)
-{
- // Todo use WouldBurnAt(), not sure how to obtain a chunk though...
- super::MoveToPosition(a_Position); // Look at the player and update m_Destination to hit them if they're close
-
- // If the destination is sufficiently skylight challenged AND the skeleton isn't on fire AND we weren't attacked recently then block the movement
- if (
- !IsOnFire() &&
- (m_World->GetBlockSkyLight((int)floor(a_Position.x), (int)floor(a_Position.y), (int)floor(a_Position.z)) - m_World->GetSkyDarkness() > 8) &&
- m_TicksSinceLastDamaged == 100
- )
- {
- StopMovingToPosition();
- }
-}
-
-
-
-
diff --git a/src/Mobs/Zombie.h b/src/Mobs/Zombie.h
index 809c2a6fe..47a9f1904 100644
--- a/src/Mobs/Zombie.h
+++ b/src/Mobs/Zombie.h
@@ -10,17 +10,15 @@ class cZombie :
public cAggressiveMonster
{
typedef cAggressiveMonster super;
-
+
public:
cZombie(bool a_IsVillagerZombie);
CLASS_PROTODEF(cZombie)
-
- virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
- virtual void MoveToPosition(const Vector3d & a_Position) override;
+ virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual bool IsUndead(void) override { return true; }
-
+
bool IsVillagerZombie(void) const { return m_IsVillagerZombie; }
bool IsConverting (void) const { return m_IsConverting; }
diff --git a/src/World.cpp b/src/World.cpp
index 8e1d0b33e..87209e4c2 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -833,7 +833,7 @@ void cWorld::InitialiseAndLoadMobSpawningValues(cIniFile & a_IniFile)
AString DefaultMonsters;
switch (m_Dimension)
{
- case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, horse, mooshroom, ocelot, pig, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break;
+ case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, guardian, horse, mooshroom, ocelot, pig, rabbit, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break;
case dimNether: DefaultMonsters = "blaze, ghast, magmacube, skeleton, zombie, zombiepigman"; break;
case dimEnd: DefaultMonsters = "enderman"; break;
case dimNotSet: ASSERT(!"Dimension not set"); break;