1
0

Merge pull request #2974 from LogicParrot/perl

Bulk clearing of whitespace
This commit is contained in:
Julian Laubstein 2016-02-06 11:37:34 +01:00
commit 6fdd7194c8
406 changed files with 4497 additions and 4497 deletions

View File

@ -15,23 +15,23 @@ public:
{
public:
virtual ~cStarvationCallbacks() {}
/** Is called when the reserve buffer starts to be used */
virtual void OnStartUsingReserve() = 0;
/** Is called once the reserve buffer has returned to normal size */
virtual void OnEndUsingReserve() = 0;
/** Is called when the allocation pool is unable to allocate memory. Will be repeatedly
called if it does not free sufficient memory */
virtual void OnOutOfReserve() = 0;
};
virtual ~cAllocationPool() {}
/** Allocates a pointer to T */
virtual T * Allocate() = 0;
/** Frees the pointer passed in a_ptr, invalidating it */
virtual void Free(T * a_ptr) = 0;
};
@ -47,7 +47,7 @@ class cListAllocationPool:
public cAllocationPool<T>
{
public:
cListAllocationPool(std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> a_Callbacks):
m_Callbacks(std::move(a_Callbacks))
{
@ -62,7 +62,7 @@ public:
m_FreeList.push_front(space);
}
}
virtual ~cListAllocationPool()
{
@ -72,7 +72,7 @@ public:
m_FreeList.pop_front();
}
}
virtual T * Allocate() override
{
@ -115,7 +115,7 @@ public:
m_Callbacks->OnEndUsingReserve();
}
}
private:
std::list<void *> m_FreeList;
std::unique_ptr<typename cAllocationPool<T>::cStarvationCallbacks> m_Callbacks;

View File

@ -25,10 +25,10 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos)
{
// This function is expected to be called just once, with all the coords in a table
ASSERT(m_Chunks.empty());
cPluginLua::cOperation Op(m_Plugin);
cLuaState & L = Op();
// Check that we got a table:
if (!lua_istable(L, a_ChunkCoordTableStackPos))
{
@ -38,7 +38,7 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos)
L.LogStackTrace();
return false;
}
// Add each set of coords:
int NumChunks = luaL_getn(L, a_ChunkCoordTableStackPos);
m_Chunks.reserve(static_cast<size_t>(NumChunks));
@ -58,7 +58,7 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos)
AddChunkCoord(L, idx);
lua_pop(L, 1);
}
// If there are no chunks, log a warning and return failure:
if (m_Chunks.empty())
{
@ -66,7 +66,7 @@ bool cLuaChunkStay::AddChunks(int a_ChunkCoordTableStackPos)
L.LogStackTrace();
return false;
}
// All ok
return true;
}
@ -86,14 +86,14 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index)
);
return;
}
// Read the two coords from the element:
lua_rawgeti(L, -1, 1);
lua_rawgeti(L, -2, 2);
int ChunkX = luaL_checkint(L, -2);
int ChunkZ = luaL_checkint(L, -1);
lua_pop(L, 2);
// Check that a coord is not yet present:
for (cChunkCoordsVector::iterator itr = m_Chunks.begin(), end = m_Chunks.end(); itr != end; ++itr)
{
@ -105,7 +105,7 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index)
return;
}
} // for itr - m_Chunks[]
m_Chunks.push_back(cChunkCoords(ChunkX, ChunkZ));
}
@ -119,7 +119,7 @@ void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPo
m_LuaState = &m_Plugin.GetLuaState();
m_OnChunkAvailable.RefStack(*m_LuaState, a_OnChunkAvailableStackPos);
m_OnAllChunksAvailable.RefStack(*m_LuaState, a_OnAllChunksAvailableStackPos);
// Enable the ChunkStay:
super::Enable(a_ChunkMap);
}
@ -148,12 +148,12 @@ bool cLuaChunkStay::OnAllChunksAvailable(void)
// Call the callback:
cPluginLua::cOperation Op(m_Plugin);
Op().Call(static_cast<int>(m_OnAllChunksAvailable));
// Remove the callback references - they won't be needed anymore
m_OnChunkAvailable.UnRef();
m_OnAllChunksAvailable.UnRef();
}
// Disable the ChunkStay by returning true
return true;
}

View File

@ -28,38 +28,38 @@ class cLuaChunkStay
: public cChunkStay
{
typedef cChunkStay super;
public:
cLuaChunkStay(cPluginLua & a_Plugin);
~cLuaChunkStay() { }
/** Adds chunks in the specified on-stack Lua table.
Returns true if any chunk added, false (plus log warning) if none. */
bool AddChunks(int a_ChunkCoordTableStackPos);
/** Enables the ChunkStay for the specified chunkmap, with the specified Lua callbacks. */
void Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos);
protected:
/** The plugin which has created the ChunkStay, via cWorld:ChunkStay() binding method. */
cPluginLua & m_Plugin;
/** The Lua state associated with the callbacks. Only valid when enabled. */
cLuaState * m_LuaState;
/** The Lua function to call in OnChunkAvailable. Only valid when enabled. */
cLuaState::cRef m_OnChunkAvailable;
/** The Lua function to call in OnAllChunksAvailable. Only valid when enabled. */
cLuaState::cRef m_OnAllChunksAvailable;
// cChunkStay overrides:
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override;
virtual bool OnAllChunksAvailable(void) override;
virtual void OnDisabled(void) override;
/** Adds a single chunk coord from the table at the top of the Lua stack.
Expects the top element to be a table, checks that it contains two numbers.
Uses those two numbers as chunk coords appended to m_Chunks.

View File

@ -267,12 +267,12 @@ void cLuaState::AddPackagePath(const AString & a_PathVariable, const AString & a
lua_getfield(m_LuaState, -1, a_PathVariable.c_str()); // Stk: <package> <package.path>
size_t len = 0;
const char * PackagePath = lua_tolstring(m_LuaState, -1, &len);
// Append the new path:
AString NewPackagePath(PackagePath, len);
NewPackagePath.append(LUA_PATHSEP);
NewPackagePath.append(a_Path);
// Set the new path to the environment:
lua_pop(m_LuaState, 1); // Stk: <package>
lua_pushlstring(m_LuaState, NewPackagePath.c_str(), NewPackagePath.length()); // Stk: <package> <NewPackagePath>
@ -382,10 +382,10 @@ bool cLuaState::PushFunction(const char * a_FunctionName)
// This happens if cPlugin::Initialize() fails with an error
return false;
}
// Push the error handler for lua_pcall()
lua_pushcfunction(m_LuaState, &ReportFnCallErrors);
lua_getglobal(m_LuaState, a_FunctionName);
if (!lua_isfunction(m_LuaState, -1))
{
@ -406,10 +406,10 @@ bool cLuaState::PushFunction(int a_FnRef)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack
// Push the error handler for lua_pcall()
lua_pushcfunction(m_LuaState, &ReportFnCallErrors);
lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_FnRef); // same as lua_getref()
if (!lua_isfunction(m_LuaState, -1))
{
@ -429,10 +429,10 @@ bool cLuaState::PushFunction(const cTableRef & a_TableRef)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs == -1); // If not, there's already something pushed onto the stack
// Push the error handler for lua_pcall()
lua_pushcfunction(m_LuaState, &ReportFnCallErrors);
lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_TableRef.GetTableRef()); // Get the table ref
if (!lua_istable(m_LuaState, -1))
{
@ -447,10 +447,10 @@ bool cLuaState::PushFunction(const cTableRef & a_TableRef)
lua_pop(m_LuaState, 3);
return false;
}
// Pop the table off the stack:
lua_remove(m_LuaState, -2);
Printf(m_CurrentFunctionName, "<table-callback %s>", a_TableRef.GetFnName());
m_NumCurrentFunctionArgs = 0;
return true;
@ -1005,13 +1005,13 @@ bool cLuaState::CallFunction(int a_NumResults)
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 1)); // The function to call
ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 2)); // The error handler
// Save the current "stack" state and reset, in case the callback calls another function:
AString CurrentFunctionName;
std::swap(m_CurrentFunctionName, CurrentFunctionName);
int NumArgs = m_NumCurrentFunctionArgs;
m_NumCurrentFunctionArgs = -1;
// Call the function:
int s = lua_pcall(m_LuaState, NumArgs, a_NumResults, -NumArgs - 2);
if (s != 0)
@ -1020,10 +1020,10 @@ bool cLuaState::CallFunction(int a_NumResults)
LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), CurrentFunctionName.c_str());
return false;
}
// Remove the error handler from the stack:
lua_remove(m_LuaState, -a_NumResults - 1);
return true;
}
@ -1034,12 +1034,12 @@ bool cLuaState::CallFunction(int a_NumResults)
bool cLuaState::CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
tolua_Error tolua_err;
for (int i = a_StartParam; i <= a_EndParam; i++)
{
@ -1055,7 +1055,7 @@ bool cLuaState::CheckParamUserTable(int a_StartParam, const char * a_UserTable,
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1067,12 +1067,12 @@ bool cLuaState::CheckParamUserTable(int a_StartParam, const char * a_UserTable,
bool cLuaState::CheckParamUserType(int a_StartParam, const char * a_UserType, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
tolua_Error tolua_err;
for (int i = a_StartParam; i <= a_EndParam; i++)
{
@ -1088,7 +1088,7 @@ bool cLuaState::CheckParamUserType(int a_StartParam, const char * a_UserType, in
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1100,12 +1100,12 @@ bool cLuaState::CheckParamUserType(int a_StartParam, const char * a_UserType, in
bool cLuaState::CheckParamTable(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
tolua_Error tolua_err;
for (int i = a_StartParam; i <= a_EndParam; i++)
{
@ -1124,7 +1124,7 @@ bool cLuaState::CheckParamTable(int a_StartParam, int a_EndParam)
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1136,12 +1136,12 @@ bool cLuaState::CheckParamTable(int a_StartParam, int a_EndParam)
bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
tolua_Error tolua_err;
for (int i = a_StartParam; i <= a_EndParam; i++)
{
@ -1157,7 +1157,7 @@ bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam)
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1169,12 +1169,12 @@ bool cLuaState::CheckParamNumber(int a_StartParam, int a_EndParam)
bool cLuaState::CheckParamBool(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
tolua_Error tolua_err;
for (int i = a_StartParam; i <= a_EndParam; i++)
{
@ -1190,7 +1190,7 @@ bool cLuaState::CheckParamBool(int a_StartParam, int a_EndParam)
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1202,12 +1202,12 @@ bool cLuaState::CheckParamBool(int a_StartParam, int a_EndParam)
bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
tolua_Error tolua_err;
for (int i = a_StartParam; i <= a_EndParam; i++)
{
@ -1226,7 +1226,7 @@ bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam)
tolua_error(m_LuaState, ErrMsg.c_str(), &tolua_err);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1238,12 +1238,12 @@ bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam)
bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
for (int i = a_StartParam; i <= a_EndParam; i++)
{
if (lua_isfunction(m_LuaState, i))
@ -1259,7 +1259,7 @@ bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam)
);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1271,12 +1271,12 @@ bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam)
bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam)
{
ASSERT(IsValid());
if (a_EndParam < 0)
{
a_EndParam = a_StartParam;
}
for (int i = a_StartParam; i <= a_EndParam; i++)
{
if (lua_isfunction(m_LuaState, i) || lua_isnil(m_LuaState, i))
@ -1292,7 +1292,7 @@ bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam)
);
return false;
} // for i - Param
// All params checked ok
return true;
}
@ -1324,7 +1324,7 @@ bool cLuaState::CheckParamEnd(int a_Param)
bool cLuaState::IsParamUserType(int a_Param, AString a_UserType)
{
ASSERT(IsValid());
tolua_Error tolua_err;
return (tolua_isusertype(m_LuaState, a_Param, a_UserType.c_str(), 0, &tolua_err) == 1);
}
@ -1336,7 +1336,7 @@ bool cLuaState::IsParamUserType(int a_Param, AString a_UserType)
bool cLuaState::IsParamNumber(int a_Param)
{
ASSERT(IsValid());
tolua_Error tolua_err;
return (tolua_isnumber(m_LuaState, a_Param, 0, &tolua_err) == 1);
}
@ -1361,7 +1361,7 @@ bool cLuaState::ReportErrors(lua_State * a_LuaState, int a_Status)
// No error to report
return false;
}
LOGWARNING("LUA: %d - %s", a_Status, lua_tostring(a_LuaState, -1));
lua_pop(a_LuaState, 1);
return true;
@ -1416,10 +1416,10 @@ int cLuaState::CallFunctionWithForeignParams(
{
ASSERT(IsValid());
ASSERT(a_SrcLuaState.IsValid());
// Store the stack position before any changes
int OldTop = lua_gettop(m_LuaState);
// Push the function to call, including the error handler:
if (!PushFunction(a_FunctionName.c_str()))
{
@ -1437,7 +1437,7 @@ int cLuaState::CallFunctionWithForeignParams(
m_CurrentFunctionName.clear();
return -1;
}
// Call the function, with an error handler:
int s = lua_pcall(m_LuaState, a_SrcParamEnd - a_SrcParamStart + 1, LUA_MULTRET, OldTop + 1);
if (ReportErrors(s))
@ -1445,23 +1445,23 @@ int cLuaState::CallFunctionWithForeignParams(
LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str());
// Reset the stack:
lua_settop(m_LuaState, OldTop);
// Reset the internal checking mechanisms:
m_NumCurrentFunctionArgs = -1;
m_CurrentFunctionName.clear();
// Make Lua think everything is okay and return 0 values, so that plugins continue executing.
// The failure is indicated by the zero return values.
return 0;
}
// Reset the internal checking mechanisms:
m_NumCurrentFunctionArgs = -1;
m_CurrentFunctionName.clear();
// Remove the error handler from the stack:
lua_remove(m_LuaState, OldTop + 1);
// Return the number of return values:
return lua_gettop(m_LuaState) - OldTop;
}
@ -1520,7 +1520,7 @@ int cLuaState::CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_Sr
lua_rawget(a_SrcLuaState, LUA_REGISTRYINDEX); // Stack +1
type = lua_tostring(a_SrcLuaState, -1);
lua_pop(a_SrcLuaState, 1); // Stack -1
// Copy the value:
void * ud = tolua_touserdata(a_SrcLuaState, i, nullptr);
tolua_pushusertype(m_LuaState, ud, type);
@ -1693,7 +1693,7 @@ void cLuaState::cRef::RefStack(cLuaState & a_LuaState, int a_StackPos)
void cLuaState::cRef::UnRef(void)
{
ASSERT(m_LuaState->IsValid()); // The reference should be destroyed before destroying the LuaState
if (IsValid())
{
luaL_unref(*m_LuaState, LUA_REGISTRYINDEX, m_Ref);

View File

@ -57,26 +57,26 @@ public:
public:
/** Creates an unbound reference object. */
cRef(void);
/** Creates a reference in the specified LuaState for object at the specified StackPos */
cRef(cLuaState & a_LuaState, int a_StackPos);
/** Moves the reference from the specified instance into a newly created instance.
The old instance is then "!IsValid()". */
cRef(cRef && a_FromRef);
~cRef();
/** Creates a reference to Lua object at the specified stack pos, binds this object to it.
Calls UnRef() first if previously bound to another reference. */
void RefStack(cLuaState & a_LuaState, int a_StackPos);
/** Removes the bound reference, resets the object to Unbound state. */
void UnRef(void);
/** Returns true if the reference is valid */
bool IsValid(void) const {return (m_Ref != LUA_REFNIL); }
/** Allows to use this class wherever an int (i. e. ref) is to be used */
explicit operator int(void) const { return m_Ref; }
@ -87,8 +87,8 @@ public:
// Remove the copy-constructor:
cRef(const cRef &) = delete;
} ;
/** Used for calling functions stored in a reference-stored table */
class cTableRef
{
@ -100,7 +100,7 @@ public:
m_FnName(a_FnName)
{
}
cTableRef(const cRef & a_TableRef, const char * a_FnName) :
m_TableRef(static_cast<int>(a_TableRef)),
m_FnName(a_FnName)
@ -110,13 +110,13 @@ public:
int GetTableRef(void) const { return m_TableRef; }
const char * GetFnName(void) const { return m_FnName; }
} ;
/** A dummy class that's used only to delimit function args from return values for cLuaState::Call() */
class cRet
{
} ;
static const cRet Return; // Use this constant to delimit function args from return values for cLuaState::Call()
@ -180,31 +180,31 @@ public:
or "LuaScript" for the cLuaScript template
*/
cLuaState(const AString & a_SubsystemName);
/** Creates a new instance. The a_AttachState is attached.
Subsystem name is set to "<attached>".
*/
explicit cLuaState(lua_State * a_AttachState);
~cLuaState();
/** Allows this object to be used in the same way as a lua_State *, for example in the LuaLib functions */
operator lua_State * (void) { return m_LuaState; }
/** Creates the m_LuaState, if not closed already. This state will be automatically closed in the destructor.
The regular Lua libs are registered, but the MCS API is not registered (so that Lua can be used as
lite-config as well), use RegisterAPILibs() to do that. */
void Create(void);
/** Registers all the API libraries that MCS provides into m_LuaState. */
void RegisterAPILibs(void);
/** Closes the m_LuaState, if not closed already */
void Close(void);
/** Attaches the specified state. Operations will be carried out on this state, but it will not be closed in the destructor */
void Attach(lua_State * a_State);
/** Detaches a previously attached state. */
void Detach(void);
@ -260,7 +260,7 @@ public:
void Push(long a_Value);
void Push(const UInt32 a_Value);
void Push(std::chrono::milliseconds a_time);
// GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged.
// Returns whether value was changed
// Enum values are checked for their allowed values and fail if the value is not assigned.
@ -335,7 +335,7 @@ public:
// Include the auto-generated Push and GetStackValue() functions:
#include "LuaState_Declaration.inc"
/** Call the specified Lua function.
Returns true if call succeeded, false if there was an error.
A special param of cRet & signifies the end of param list and the start of return values.
@ -364,50 +364,50 @@ public:
/** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */
bool CheckParamUserTable(int a_StartParam, const char * a_UserTable, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are of the specified usertype; also logs warning if not. Used for regular functions */
bool CheckParamUserType(int a_StartParam, const char * a_UserType, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are tables; also logs warning if not */
bool CheckParamTable(int a_StartParam, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are numbers; also logs warning if not */
bool CheckParamNumber(int a_StartParam, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are bools; also logs warning if not */
bool CheckParamBool(int a_StartParam, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are strings; also logs warning if not */
bool CheckParamString(int a_StartParam, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are functions; also logs warning if not */
bool CheckParamFunction(int a_StartParam, int a_EndParam = -1);
/** Returns true if the specified parameters on the stack are functions or nils; also logs warning if not */
bool CheckParamFunctionOrNil(int a_StartParam, int a_EndParam = -1);
/** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */
bool CheckParamEnd(int a_Param);
bool IsParamUserType(int a_Param, AString a_UserType);
bool IsParamNumber(int a_Param);
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
bool ReportErrors(int status);
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
static bool ReportErrors(lua_State * a_LuaState, int status);
/** Logs all items in the current stack trace to the server console */
void LogStackTrace(int a_StartingDepth = 0);
/** Logs all items in the current stack trace to the server console */
static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0);
/** Returns the type of the item on the specified position in the stack */
AString GetTypeText(int a_StackPos);
/** Calls the function specified by its name, with arguments copied off the foreign state.
If successful, keeps the return values on the stack and returns their number.
If unsuccessful, returns a negative number and keeps the stack position unchanged. */
@ -417,37 +417,37 @@ public:
int a_SrcParamStart,
int a_SrcParamEnd
);
/** Copies objects on the stack from the specified state.
Only numbers, bools, strings and userdatas are copied.
If successful, returns the number of objects copied.
If failed, returns a negative number and rewinds the stack position. */
int CopyStackFrom(cLuaState & a_SrcLuaState, int a_SrcStart, int a_SrcEnd);
/** Reads the value at the specified stack position as a string and sets it to a_String. */
void ToString(int a_StackPos, AString & a_String);
/** Logs all the elements' types on the API stack, with an optional header for the listing. */
void LogStack(const char * a_Header = nullptr);
/** Logs all the elements' types on the API stack, with an optional header for the listing. */
static void LogStack(lua_State * a_LuaState, const char * a_Header = nullptr);
protected:
lua_State * m_LuaState;
/** If true, the state is owned by this object and will be auto-Closed. False => attached state */
bool m_IsOwned;
/** The subsystem name is used for reporting errors to the console, it is either "plugin %s" or "LuaScript"
whatever is given to the constructor
*/
AString m_SubsystemName;
/** Name of the currently pushed function (for the Push / Call chain) */
AString m_CurrentFunctionName;
/** Number of arguments currently pushed (for the Push / Call chain) */
int m_NumCurrentFunctionArgs;
@ -499,12 +499,12 @@ protected:
Returns true if successful. Logs a warning on failure (incl. m_SubsystemName)
*/
bool PushFunction(const char * a_FunctionName);
/** Pushes a function that has been saved into the global registry, identified by a_FnRef.
Returns true if successful. Logs a warning on failure
*/
bool PushFunction(int a_FnRef);
/** Pushes a function that has been saved as a reference.
Returns true if successful. Logs a warning on failure
*/
@ -512,12 +512,12 @@ protected:
{
return PushFunction(static_cast<int>(a_FnRef));
}
/** Pushes a function that is stored in a referenced table by name
Returns true if successful. Logs a warning on failure
*/
bool PushFunction(const cTableRef & a_TableRef);
/** Pushes a usertype of the specified class type onto the stack */
// void PushUserType(void * a_Object, const char * a_Type);
@ -527,7 +527,7 @@ protected:
Returns true if successful, logs a warning on failure.
*/
bool CallFunction(int a_NumReturnValues);
/** Used as the error reporting function for function calls */
static int ReportFnCallErrors(lua_State * a_LuaState);

View File

@ -25,7 +25,7 @@ cLuaWindow::cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_Slo
{
m_Contents.AddListener(*this);
m_SlotAreas.push_back(new cSlotAreaItemGrid(m_Contents, *this));
// If appropriate, add an Armor slot area:
switch (a_WindowType)
{
@ -93,13 +93,13 @@ void cLuaWindow::SetOnClosing(cPluginLua * a_Plugin, int a_FnRef)
{
// Either m_Plugin is not set or equal to the passed plugin; only one plugin can use one cLuaWindow object
ASSERT((m_Plugin == nullptr) || (m_Plugin == a_Plugin));
// If there already was a function, unreference it first
if (m_OnClosingFnRef != LUA_REFNIL)
{
m_Plugin->Unreference(m_OnClosingFnRef);
}
// Store the new reference
m_Plugin = a_Plugin;
m_OnClosingFnRef = a_FnRef;
@ -113,13 +113,13 @@ void cLuaWindow::SetOnSlotChanged(cPluginLua * a_Plugin, int a_FnRef)
{
// Either m_Plugin is not set or equal to the passed plugin; only one plugin can use one cLuaWindow object
ASSERT((m_Plugin == nullptr) || (m_Plugin == a_Plugin));
// If there already was a function, unreference it first
if (m_OnSlotChangedFnRef != LUA_REFNIL)
{
m_Plugin->Unreference(m_OnSlotChangedFnRef);
}
// Store the new reference
m_Plugin = a_Plugin;
m_OnSlotChangedFnRef = a_FnRef;
@ -141,7 +141,7 @@ bool cLuaWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse)
return false;
}
}
return super::ClosedByPlayer(a_Player, a_CanRefuse);
}
@ -152,13 +152,13 @@ bool cLuaWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse)
void cLuaWindow::Destroy(void)
{
super::Destroy();
if ((m_LuaRef != LUA_REFNIL) && (m_Plugin != nullptr))
{
// The object is referenced by Lua, un-reference it
m_Plugin->Unreference(m_LuaRef);
}
// Lua will take care of this object, it will garbage-collect it, so we must not delete it!
m_IsDestroyed = false;
}
@ -192,7 +192,7 @@ void cLuaWindow::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
ASSERT(!"Invalid ItemGrid in callback");
return;
}
// If an OnSlotChanged callback has been registered, call it:
if (m_OnSlotChangedFnRef != LUA_REFNIL)
{

View File

@ -40,52 +40,52 @@ class cLuaWindow :
// tolua_begin
{
typedef cWindow super;
public:
/** Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size */
cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_SlotsY, const AString & a_Title);
virtual ~cLuaWindow();
/** Returns the internal representation of the contents that are manipulated by Lua */
cItemGrid & GetContents(void) { return m_Contents; }
// tolua_end
/** Sets the plugin reference and the internal Lua object reference index
used for preventing Lua's GC to collect this class while the window is open. */
void SetLuaRef(cPluginLua * a_Plugin, int a_LuaRef);
/** Returns true if SetLuaRef() has been called */
bool IsLuaReferenced(void) const;
/** Sets the callback function (Lua reference) to call when the window is about to close */
void SetOnClosing(cPluginLua * a_Plugin, int a_FnRef);
/** Sets the callback function (Lua reference) to call when a slot is changed */
void SetOnSlotChanged(cPluginLua * a_Plugin, int a_FnRef);
protected:
/** Contents of the non-inventory part */
cItemGrid m_Contents;
/** The plugin that has opened the window and owns the m_LuaRef */
cPluginLua * m_Plugin;
/** The Lua object reference, used for keeping the object alive as long as any player has the window open */
int m_LuaRef;
/** The Lua reference for the callback to call when the window is closing for any player */
int m_OnClosingFnRef;
/** The Lua reference for the callback to call when a slot has changed */
int m_OnSlotChangedFnRef;
// cWindow overrides:
virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) override;
virtual void Destroy(void) override;
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
// cItemGrid::cListener overrides:
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
} ; // tolua_export

View File

@ -356,7 +356,7 @@ static int tolua_LOG(lua_State * tolua_S)
{
LogLevel = cCompositeChat::MessageTypeToLogLevel(reinterpret_cast<cCompositeChat *>(tolua_tousertype(tolua_S, 1, nullptr))->GetMessageType());
}
// Log the message:
cLogger::GetInstance().LogSimple(GetLogMessage(tolua_S).c_str(), LogLevel);
return 0;
@ -430,7 +430,7 @@ static int tolua_Base64Encode(lua_State * tolua_S)
{
return 0;
}
AString Src;
L.GetStackValue(1, Src);
AString res = Base64Encode(Src);
@ -452,7 +452,7 @@ static int tolua_Base64Decode(lua_State * tolua_S)
{
return 0;
}
AString Src;
L.GetStackValue(1, Src);
AString res = Base64Decode(Src);
@ -476,7 +476,7 @@ cPluginLua * cManualBindings::GetLuaPlugin(lua_State * L)
}
cPluginLua * Plugin = reinterpret_cast<cPluginLua *>(const_cast<void*>(lua_topointer(L, -1)));
lua_pop(L, 1);
return Plugin;
}
@ -746,7 +746,7 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
{
return 0;
}
// Get params:
AString Folder;
ASSERT(LuaState.GetStackValues(2, Folder));
@ -883,7 +883,7 @@ static int tolua_cFile_ReadWholeFile(lua_State * tolua_S)
{
return 0;
}
// Get params:
AString FileName;
ASSERT(LuaState.GetStackValues(2, FileName));
@ -982,7 +982,7 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager,
// Helper function for cPluginmanager:AddHook() binding
// Takes care of the new case (#121): args are HOOK_TYPE and CallbackFunction
// The arg types have already been checked
// Retrieve the cPlugin from the LuaState:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(S);
if (Plugin == nullptr)
@ -990,7 +990,7 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager,
// An error message has been already printed in GetLuaPlugin()
return 0;
}
// Retrieve and check the hook type
int HookType = static_cast<int>(tolua_tonumber(S, a_ParamIdx, -1));
if (!a_PluginManager->IsValidHookType(HookType))
@ -999,7 +999,7 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager,
S.LogStackTrace();
return 0;
}
// Add the hook to the plugin
if (!Plugin->AddHookRef(HookType, a_ParamIdx + 1))
{
@ -1008,7 +1008,7 @@ static int tolua_cPluginManager_AddHook_FnRef(cPluginManager * a_PluginManager,
return 0;
}
a_PluginManager->AddHook(Plugin, HookType);
// Success
return 0;
}
@ -1022,7 +1022,7 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager,
// Helper function for cPluginmanager:AddHook() binding
// Takes care of the old case (#121): args are cPluginLua and HOOK_TYPE
// The arg types have already been checked
// Retrieve and check the cPlugin parameter
cPluginLua * Plugin = reinterpret_cast<cPluginLua *>(tolua_tousertype(S, a_ParamIdx, nullptr));
if (Plugin == nullptr)
@ -1038,7 +1038,7 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager,
S.LogStackTrace();
return 0;
}
// Retrieve and check the hook type
int HookType = static_cast<int>(tolua_tonumber(S, a_ParamIdx + 1, -1));
if (!a_PluginManager->IsValidHookType(HookType))
@ -1047,7 +1047,7 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager,
S.LogStackTrace();
return 0;
}
// Get the standard name for the callback function:
const char * FnName = cPluginLua::GetHookFnName(HookType);
if (FnName == nullptr)
@ -1068,7 +1068,7 @@ static int tolua_cPluginManager_AddHook_DefFn(cPluginManager * a_PluginManager,
return 0;
}
a_PluginManager->AddHook(Plugin, HookType);
// Success
return 0;
}
@ -1087,7 +1087,7 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S)
cPluginManager:Get():AddHook(Plugin, HOOK_TYPE) -- (4) old style (#121), accepted but complained about in the console
cPluginManager.AddHook(Plugin, HOOK_TYPE) -- (5) old style (#121) mangled, accepted but complained about in the console
*/
cLuaState S(tolua_S);
cPluginManager * PlgMgr = cPluginManager::Get();
@ -1111,7 +1111,7 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S)
// Style 1, use the global PlgMgr, but increment ParamIdx
ParamIdx++;
}
if (lua_isnumber(S, ParamIdx) && lua_isfunction(S, ParamIdx + 1))
{
// The next params are a number and a function, assume style 1 or 2
@ -1124,7 +1124,7 @@ static int tolua_cPluginManager_AddHook(lua_State * tolua_S)
S.LogStackTrace();
return tolua_cPluginManager_AddHook_DefFn(PlgMgr, S, ParamIdx);
}
AString ParamDesc;
Printf(ParamDesc, "%s, %s, %s", S.GetTypeText(1).c_str(), S.GetTypeText(2).c_str(), S.GetTypeText(3).c_str());
LOGWARNING("cPluginManager:AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got %s. Hook not added.", ParamDesc.c_str());
@ -1264,7 +1264,7 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
{
return 0;
}
// Read the arguments to this API call:
tolua_Error tolua_err;
int idx = 1;
@ -1294,7 +1294,7 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
AString Command (tolua_tocppstring(L, idx, ""));
AString Permission(tolua_tocppstring(L, idx + 1, ""));
AString HelpString(tolua_tocppstring(L, idx + 3, ""));
// Store the function reference:
lua_pop(L, 1); // Pop the help string off the stack
int FnRef = luaL_ref(L, LUA_REGISTRYINDEX); // Store function reference
@ -1303,7 +1303,7 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
LOGERROR("\"BindCommand\": Cannot create a function reference. Command \"%s\" not bound.", Command.c_str());
return 0;
}
if (!self->BindCommand(Command, Plugin, Permission, HelpString))
{
// Refused. Possibly already bound. Error message has been given, display the callstack:
@ -1311,7 +1311,7 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
LS.LogStackTrace();
return 0;
}
Plugin->BindCommand(Command, FnRef);
lua_pushboolean(L, true);
return 1;
@ -1327,14 +1327,14 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
cPluginManager:BindConsoleCommand(Command, Function, HelpString)
cPluginManager.BindConsoleCommand(Command, Function, HelpString) -- without the "self" param
*/
// Get the plugin identification out of LuaState:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
{
return 0;
}
// Read the arguments to this API call:
tolua_Error tolua_err;
int idx = 1;
@ -1362,7 +1362,7 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
cPluginManager * self = cPluginManager::Get();
AString Command (tolua_tocppstring(L, idx, ""));
AString HelpString(tolua_tocppstring(L, idx + 2, ""));
// Store the function reference:
lua_pop(L, 1); // Pop the help string off the stack
int FnRef = luaL_ref(L, LUA_REGISTRYINDEX); // Store function reference
@ -1371,7 +1371,7 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
LOGERROR("\"BindConsoleCommand\": Cannot create a function reference. Console Command \"%s\" not bound.", Command.c_str());
return 0;
}
if (!self->BindConsoleCommand(Command, Plugin, HelpString))
{
// Refused. Possibly already bound. Error message has been given, display the callstack:
@ -1379,7 +1379,7 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
LS.LogStackTrace();
return 0;
}
Plugin->BindConsoleCommand(Command, FnRef);
lua_pushboolean(L, true);
return 1;
@ -1395,7 +1395,7 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
Function signature:
cPluginManager:CallPlugin("PluginName", "FunctionName", args...)
*/
// Check the parameters:
cLuaState L(tolua_S);
if (
@ -1404,7 +1404,7 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
{
return 0;
}
// Retrieve the plugin name and function name
AString PluginName, FunctionName;
L.ToString(2, PluginName);
@ -1415,7 +1415,7 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
L.LogStackTrace();
return 0;
}
// If requesting calling the current plugin, refuse:
cPluginLua * ThisPlugin = cManualBindings::GetLuaPlugin(L);
if (ThisPlugin == nullptr)
@ -1428,7 +1428,7 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
L.LogStackTrace();
return 0;
}
// Call the destination plugin using a plugin callback:
class cCallback :
public cPluginManager::cPluginCallback
@ -1445,7 +1445,7 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
protected:
const AString & m_FunctionName;
cLuaState & m_SrcLuaState;
virtual bool Item(cPlugin * a_Plugin) override
{
if (!a_Plugin->IsLoaded())
@ -1544,7 +1544,7 @@ static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, static_cast<void *>(self));
return 0;
}
// Push the permissions:
L.Push(self->GetPermissions());
return 1;
@ -1575,7 +1575,7 @@ static int tolua_cPlayer_GetRestrictions(lua_State * tolua_S)
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, static_cast<void *>(self));
return 0;
}
// Push the permissions:
L.Push(self->GetRestrictions());
return 1;
@ -1604,7 +1604,7 @@ static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
LOGWARNING("%s: invalid self (%p) or wnd (%p)", __FUNCTION__, static_cast<void *>(self), static_cast<void *>(wnd));
return 0;
}
// If cLuaWindow, add a reference, so that Lua won't delete the cLuaWindow object mid-processing
tolua_Error err;
if (tolua_isusertype(tolua_S, 2, "cLuaWindow", 0, &err))
@ -1624,7 +1624,7 @@ static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
LuaWnd->SetLuaRef(Plugin, LuaRef);
}
}
// Open the window
self->OpenWindow(wnd);
return 0;
@ -1652,7 +1652,7 @@ static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S)
// Get the params:
AString Permission, Template;
L.GetStackValues(2, Permission, Template);
// Push the result of the match:
L.Push(cPlayer::PermissionMatches(StringSplit(Permission, "."), StringSplit(Template, ".")));
return 1;
@ -1691,7 +1691,7 @@ static int tolua_SetObjectCallback(lua_State * tolua_S)
LOGERROR("%s: Cannot create a function reference. Callback not set.", __FUNCTION__);
return 0;
}
// Set the callback
(self->*SetCallback)(Plugin, FnRef);
return 0;
@ -1711,7 +1711,7 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S)
LOGWARNING("cPluginLua:AddWebTab: invalid self as first argument");
return 0;
}
tolua_Error tolua_err;
tolua_err.array = 0;
tolua_err.index = 3;
@ -1752,14 +1752,14 @@ static int tolua_cPluginLua_AddWebTab(lua_State * tolua_S)
static int tolua_cPlugin_GetDirectory(lua_State * tolua_S)
{
cLuaState L(tolua_S);
// Log the obsoletion warning:
LOGWARNING("cPlugin:GetDirectory() is obsolete, use cPlugin:GetFolderName() instead.");
L.LogStackTrace();
// Retrieve the params:
cPlugin * Plugin = static_cast<cPluginLua *>(tolua_tousertype(tolua_S, 1, nullptr));
// Get the folder name:
L.Push(Plugin->GetFolderName());
return 1;
@ -1772,14 +1772,14 @@ static int tolua_cPlugin_GetDirectory(lua_State * tolua_S)
static int tolua_cPlugin_GetLocalDirectory(lua_State * tolua_S)
{
cLuaState L(tolua_S);
// Log the obsoletion warning:
LOGWARNING("cPlugin:GetLocalDirectory() is obsolete, use cPlugin:GetLocalFolder() instead.");
L.LogStackTrace();
// Retrieve the params:
cPlugin * Plugin = static_cast<cPluginLua *>(tolua_tousertype(tolua_S, 1, nullptr));
// Get the folder:
L.Push(Plugin->GetLocalFolder());
return 1;
@ -2145,11 +2145,11 @@ static int tolua_AllToLua_cWebAdmin_GetHTMLEscapedString(lua_State * tolua_S)
{
return 0;
}
// Get the parameters:
AString Input;
S.GetStackValue(2, Input);
// Convert and return:
S.Push(cWebAdmin::GetHTMLEscapedString(Input));
return 1;
@ -2173,11 +2173,11 @@ static int tolua_AllToLua_cWebAdmin_GetURLEncodedString(lua_State * tolua_S)
{
return 0;
}
// Get the parameters:
AString Input;
S.GetStackValue(2, Input);
// Convert and return:
S.Push(cWebAdmin::GetURLEncodedString(Input));
return 1;
@ -2249,12 +2249,12 @@ static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L)
{
return 0;
}
// Retrieve the parameters:
AString UUID, PlayerName;
S.GetStackValue(2, PlayerName);
S.GetStackValue(3, UUID);
// Store in the cache:
cRoot::Get()->GetMojangAPI().AddPlayerNameToUUIDMapping(PlayerName, UUID);
return 0;
@ -2275,10 +2275,10 @@ static int tolua_cMojangAPI_GetPlayerNameFromUUID(lua_State * L)
{
return 0;
}
AString UUID;
S.GetStackValue(2, UUID);
// If the UseOnlyCached param was given, read it; default to false
bool ShouldUseCacheOnly = false;
if (lua_gettop(L) == 3)
@ -2308,10 +2308,10 @@ static int tolua_cMojangAPI_GetUUIDFromPlayerName(lua_State * L)
{
return 0;
}
AString PlayerName;
S.GetStackValue(2, PlayerName);
// If the UseOnlyCached param was given, read it; default to false
bool ShouldUseCacheOnly = false;
if (lua_gettop(L) == 3)
@ -2341,7 +2341,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
{
return 0;
}
// Convert the input table into AStringVector:
AStringVector PlayerNames;
int NumNames = luaL_getn(L, 2);
@ -2357,7 +2357,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
}
lua_pop(L, 1);
}
// If the UseOnlyCached param was given, read it; default to false
bool ShouldUseCacheOnly = false;
if (lua_gettop(L) == 3)
@ -2368,7 +2368,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
// Push the output table onto the stack:
lua_newtable(L);
// Get the UUIDs:
AStringVector UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames, ShouldUseCacheOnly);
if (UUIDs.size() != PlayerNames.size())
@ -2376,7 +2376,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
// A hard error has occured while processing the request, no UUIDs were returned. Return an empty table:
return 1;
}
// Convert to output table, PlayerName -> UUID:
size_t len = UUIDs.size();
for (size_t i = 0; i < len; i++)
@ -2410,7 +2410,7 @@ static int tolua_cMojangAPI_MakeUUIDDashed(lua_State * L)
{
return 0;
}
// Get the params:
AString UUID;
S.GetStackValue(2, UUID);
@ -2438,7 +2438,7 @@ static int tolua_cMojangAPI_MakeUUIDShort(lua_State * L)
{
return 0;
}
// Get the params:
AString UUID;
S.GetStackValue(2, UUID);
@ -2478,7 +2478,7 @@ static int Lua_ItemGrid_GetSlotCoords(lua_State * L)
tolua_pushnumber(L, static_cast<lua_Number>(Y));
return 2;
}
tolua_lerror:
tolua_error(L, "#ferror in function 'cItemGrid:GetSlotCoords'.", &tolua_err);
return 0;
@ -2498,7 +2498,7 @@ public:
m_TableRef(a_LuaState, a_ParamNum)
{
}
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
{
bool res = false;
@ -2513,7 +2513,7 @@ public:
}
return res;
}
virtual bool OnNextBlockNoData(int a_BlockX, int a_BlockY, int a_BlockZ, char a_EntryFace) override
{
bool res = false;
@ -2528,7 +2528,7 @@ public:
}
return res;
}
virtual bool OnOutOfWorld(double a_BlockX, double a_BlockY, double a_BlockZ) override
{
bool res = false;
@ -2543,7 +2543,7 @@ public:
}
return res;
}
virtual bool OnIntoWorld(double a_BlockX, double a_BlockY, double a_BlockZ) override
{
bool res = false;
@ -2558,12 +2558,12 @@ public:
}
return res;
}
virtual void OnNoMoreHits(void) override
{
m_LuaState.Call(cLuaState::cTableRef(m_TableRef, "OnNoMoreHits"));
}
virtual void OnNoChunk(void) override
{
m_LuaState.Call(cLuaState::cTableRef(m_TableRef, "OnNoChunk"));
@ -2584,7 +2584,7 @@ static int tolua_cLineBlockTracer_Trace(lua_State * tolua_S)
cLineBlockTracer:Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ) // Canonical
cLineBlockTracer.Trace(World, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ)
*/
// If the first param is the cLineBlockTracer class, shift param index by one:
int idx = 1;
tolua_Error err;
@ -2592,7 +2592,7 @@ static int tolua_cLineBlockTracer_Trace(lua_State * tolua_S)
{
idx = 2;
}
// Check params:
cLuaState L(tolua_S);
if (
@ -2726,7 +2726,7 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S)
{
return 0;
}
// Check the input param:
cItem * Input = nullptr;
L.GetStackValue(2, Input);
@ -2735,7 +2735,7 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S)
LOGWARNING("cRoot:GetFurnaceRecipe: the Input parameter is nil or missing.");
return 0;
}
// Get the recipe for the input
cFurnaceRecipe * FR = cRoot::Get()->GetFurnaceRecipe();
const cFurnaceRecipe::cRecipe * Recipe = FR->GetRecipeFrom(*Input);
@ -2744,7 +2744,7 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S)
// There is no such furnace recipe for this input, return no value
return 0;
}
// Push the output, number of ticks and input as the three return values:
L.Push(Recipe->Out);
L.Push(Recipe->CookTime);
@ -2760,7 +2760,7 @@ static int tolua_cHopperEntity_GetOutputBlockPos(lua_State * tolua_S)
{
// function cHopperEntity::GetOutputBlockPos()
// Exported manually because tolua would require meaningless params
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cHopperEntity") ||
@ -2800,7 +2800,7 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * tolua_S)
{
// function cBlockArea::GetBlockTypeMeta()
// Exported manually because tolua generates extra input params for the outputs
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cBlockArea") ||
@ -2809,7 +2809,7 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * tolua_S)
{
return 0;
}
cBlockArea * self = reinterpret_cast<cBlockArea *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
@ -2837,20 +2837,20 @@ static int tolua_cBlockArea_GetOrigin(lua_State * tolua_S)
// Returns all three coords of the origin point
// Exported manually because there's no direct C++ equivalent,
// plus tolua would generate extra input params for the outputs
cLuaState L(tolua_S);
if (!L.CheckParamUserType(1, "cBlockArea"))
{
return 0;
}
cBlockArea * self = reinterpret_cast<cBlockArea *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetOrigin'", nullptr);
return 0;
}
// Push the three origin coords:
lua_pushnumber(tolua_S, self->GetOriginX());
lua_pushnumber(tolua_S, self->GetOriginY());
@ -2866,13 +2866,13 @@ static int tolua_cBlockArea_GetNonAirCropRelCoords(lua_State * tolua_S)
{
// function cBlockArea::GetNonAirCropRelCoords()
// Exported manually because tolua would generate extra input params for the outputs
cLuaState L(tolua_S);
if (!L.CheckParamUserType(1, "cBlockArea"))
{
return 0;
}
cBlockArea * self = nullptr;
BLOCKTYPE IgnoreBlockType = E_BLOCK_AIR;
L.GetStackValues(1, self, IgnoreBlockType);
@ -2881,7 +2881,7 @@ static int tolua_cBlockArea_GetNonAirCropRelCoords(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetNonAirCropRelCoords'", nullptr);
return 0;
}
// Calculate the crop coords:
int MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ;
self->GetNonAirCropRelCoords(MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ, IgnoreBlockType);
@ -2904,7 +2904,7 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S)
{
// function cBlockArea::GetRelBlockTypeMeta()
// Exported manually because tolua generates extra input params for the outputs
cLuaState L(tolua_S);
if (
!L.CheckParamUserType(1, "cBlockArea") ||
@ -2913,7 +2913,7 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S)
{
return 0;
}
cBlockArea * self = reinterpret_cast<cBlockArea *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
@ -2941,20 +2941,20 @@ static int tolua_cBlockArea_GetSize(lua_State * tolua_S)
// Returns all three sizes of the area
// Exported manually because there's no direct C++ equivalent,
// plus tolua would generate extra input params for the outputs
cLuaState L(tolua_S);
if (!L.CheckParamUserType(1, "cBlockArea"))
{
return 0;
}
cBlockArea * self = reinterpret_cast<cBlockArea *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetSize'", nullptr);
return 0;
}
// Push the three origin coords:
lua_pushnumber(tolua_S, self->GetSizeX());
lua_pushnumber(tolua_S, self->GetSizeY());
@ -2972,20 +2972,20 @@ static int tolua_cBlockArea_GetCoordRange(lua_State * tolua_S)
// Returns all three sizes of the area, miuns one, so that they represent the maximum coord value
// Exported manually because there's no direct C++ equivalent,
// plus tolua would generate extra input params for the outputs
cLuaState L(tolua_S);
if (!L.CheckParamUserType(1, "cBlockArea"))
{
return 0;
}
cBlockArea * self = reinterpret_cast<cBlockArea *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetSize'", nullptr);
return 0;
}
// Push the three origin coords:
lua_pushnumber(tolua_S, self->GetSizeX() - 1);
lua_pushnumber(tolua_S, self->GetSizeY() - 1);
@ -3105,7 +3105,7 @@ static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea::SaveToSchematicFile'", nullptr);
return 0;
}
AString Data;
if (cSchematicFileSerializer::SaveToSchematicString(*self, Data))
{
@ -3123,7 +3123,7 @@ static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S)
{
// function cCompositeChat:AddRunCommandPart(Message, Command, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (
@ -3139,14 +3139,14 @@ static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddRunCommandPart'", nullptr);
return 0;
}
// Add the part:
AString Text, Command, Style;
L.GetStackValue(2, Text);
L.GetStackValue(3, Command);
L.GetStackValue(4, Style);
self->AddRunCommandPart(Text, Command, Style);
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3160,7 +3160,7 @@ static int tolua_cCompositeChat_AddSuggestCommandPart(lua_State * tolua_S)
{
// function cCompositeChat:AddSuggestCommandPart(Message, Command, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (
@ -3176,14 +3176,14 @@ static int tolua_cCompositeChat_AddSuggestCommandPart(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddSuggestCommandPart'", nullptr);
return 0;
}
// Add the part:
AString Text, Command, Style;
L.GetStackValue(2, Text);
L.GetStackValue(3, Command);
L.GetStackValue(4, Style);
self->AddSuggestCommandPart(Text, Command, Style);
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3197,7 +3197,7 @@ static int tolua_cCompositeChat_AddTextPart(lua_State * tolua_S)
{
// function cCompositeChat:AddTextPart(Message, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (
@ -3213,13 +3213,13 @@ static int tolua_cCompositeChat_AddTextPart(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddTextPart'", nullptr);
return 0;
}
// Add the part:
AString Text, Style;
L.GetStackValue(2, Text);
L.GetStackValue(3, Style);
self->AddTextPart(Text, Style);
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3233,7 +3233,7 @@ static int tolua_cCompositeChat_AddUrlPart(lua_State * tolua_S)
{
// function cCompositeChat:AddTextPart(Message, Url, [Style])
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (
@ -3249,14 +3249,14 @@ static int tolua_cCompositeChat_AddUrlPart(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:AddUrlPart'", nullptr);
return 0;
}
// Add the part:
AString Text, Url, Style;
L.GetStackValue(2, Text);
L.GetStackValue(3, Url);
L.GetStackValue(4, Style);
self->AddUrlPart(Text, Url, Style);
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3270,7 +3270,7 @@ static int tolua_cCompositeChat_ParseText(lua_State * tolua_S)
{
// function cCompositeChat:ParseText(TextMessage)
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (
@ -3286,12 +3286,12 @@ static int tolua_cCompositeChat_ParseText(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:ParseText'", nullptr);
return 0;
}
// Parse the text:
AString Text;
L.GetStackValue(2, Text);
self->ParseText(Text);
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3305,7 +3305,7 @@ static int tolua_cCompositeChat_SetMessageType(lua_State * tolua_S)
{
// function cCompositeChat:SetMessageType(MessageType)
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (
@ -3321,12 +3321,12 @@ static int tolua_cCompositeChat_SetMessageType(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:SetMessageType'", nullptr);
return 0;
}
// Set the type:
int MessageType = mtCustom;
L.GetStackValue(2, MessageType);
self->SetMessageType(static_cast<eMessageType>(MessageType));
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3340,7 +3340,7 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S)
{
// function cCompositeChat:UnderlineUrls()
// Exported manually to support call-chaining (return *this)
// Check params:
cLuaState L(tolua_S);
if (!L.CheckParamUserType(1, "cCompositeChat"))
@ -3353,10 +3353,10 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S)
tolua_error(tolua_S, "invalid 'self' in function 'cCompositeChat:UnderlineUrls'", nullptr);
return 0;
}
// Call the processing
self->UnderlineUrls();
// Cut away everything from the stack except for the cCompositeChat instance; return that:
lua_settop(L, 1);
return 1;
@ -3494,7 +3494,7 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "GetDirectory", tolua_cPlugin_GetDirectory);
tolua_function(tolua_S, "GetLocalDirectory", tolua_cPlugin_GetLocalDirectory);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cPluginLua");
tolua_function(tolua_S, "AddWebTab", tolua_cPluginLua_AddWebTab);
tolua_endmodule(tolua_S);

View File

@ -27,7 +27,7 @@ class cManualBindings
public:
/** Binds all the manually implemented functions to tolua_S. */
static void Bind(lua_State * tolua_S);
protected:
/** Binds the manually implemented cNetwork-related API to tolua_S.
Implemented in ManualBindings_Network.cpp. */

View File

@ -37,7 +37,7 @@ static int tolua_cNetwork_Connect(lua_State * L)
{
return 0;
}
// Get the plugin instance:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
@ -90,7 +90,7 @@ static int tolua_cNetwork_CreateUDPEndpoint(lua_State * L)
{
return 0;
}
// Get the plugin instance:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
@ -142,7 +142,7 @@ static int tolua_cNetwork_EnumLocalIPAddresses(lua_State * L)
{
return 0;
}
// Push the enumerated addresses:
S.Push(cNetwork::EnumLocalIPAddresses());
return 1;
@ -168,7 +168,7 @@ static int tolua_cNetwork_HostnameToIP(lua_State * L)
{
return 0;
}
// Get the plugin instance:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
@ -209,7 +209,7 @@ static int tolua_cNetwork_IPToHostname(lua_State * L)
{
return 0;
}
// Get the plugin instance:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
@ -250,7 +250,7 @@ static int tolua_cNetwork_Listen(lua_State * L)
{
return 0;
}
// Get the plugin instance:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(L);
if (Plugin == nullptr)
@ -320,7 +320,7 @@ static int tolua_cServerHandle_Close(lua_State * L)
{
return 0;
}
// Get the server handle:
cLuaServerHandle * Srv;
if (lua_isnil(L, 1))
@ -354,7 +354,7 @@ static int tolua_cServerHandle_IsListening(lua_State * L)
{
return 0;
}
// Get the server handle:
cLuaServerHandle * Srv;
if (lua_isnil(L, 1))
@ -391,7 +391,7 @@ static int tolua_cTCPLink_Close(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -425,7 +425,7 @@ static int tolua_cTCPLink_GetLocalIP(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -459,7 +459,7 @@ static int tolua_cTCPLink_GetLocalPort(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -493,7 +493,7 @@ static int tolua_cTCPLink_GetRemoteIP(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -527,7 +527,7 @@ static int tolua_cTCPLink_GetRemotePort(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -562,7 +562,7 @@ static int tolua_cTCPLink_Send(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -600,7 +600,7 @@ static int tolua_cTCPLink_Shutdown(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -671,7 +671,7 @@ static int tolua_cTCPLink_StartTLSServer(lua_State * L)
{
return 0;
}
// Get the link:
cLuaTCPLink * Link;
if (lua_isnil(L, 1))
@ -732,7 +732,7 @@ static int tolua_cUDPEndpoint_Close(lua_State * L)
{
return 0;
}
// Get the endpoint:
if (lua_isnil(L, 1))
{
@ -765,7 +765,7 @@ static int tolua_cUDPEndpoint_EnableBroadcasts(lua_State * L)
{
return 0;
}
// Get the endpoint:
if (lua_isnil(L, 1))
{
@ -798,7 +798,7 @@ static int tolua_cUDPEndpoint_GetPort(lua_State * L)
{
return 0;
}
// Get the endpoint:
if (lua_isnil(L, 1))
{
@ -831,7 +831,7 @@ static int tolua_cUDPEndpoint_IsOpen(lua_State * L)
{
return 0;
}
// Get the endpoint:
if (lua_isnil(L, 1))
{
@ -866,7 +866,7 @@ static int tolua_cUDPEndpoint_Send(lua_State * L)
{
return 0;
}
// Get the link:
if (lua_isnil(L, 1))
{
@ -913,7 +913,7 @@ void cManualBindings::BindNetwork(lua_State * tolua_S)
tolua_cclass(tolua_S, "cServerHandle", "cServerHandle", "", tolua_collect_cServerHandle);
tolua_cclass(tolua_S, "cTCPLink", "cTCPLink", "", nullptr);
tolua_cclass(tolua_S, "cUDPEndpoint", "cUDPEndpoint", "", tolua_collect_cUDPEndpoint);
// Fill in the functions (alpha-sorted):
tolua_beginmodule(tolua_S, "cNetwork");
tolua_function(tolua_S, "Connect", tolua_cNetwork_Connect);

View File

@ -28,11 +28,11 @@ static int tolua_cRankManager_AddGroup(lua_State * L)
{
return 0;
}
// Read the params:
AString GroupName;
S.GetStackValue(2, GroupName);
// Add the group:
cRoot::Get()->GetRankManager()->AddGroup(GroupName);
return 0;
@ -57,11 +57,11 @@ static int tolua_cRankManager_AddGroupToRank(lua_State * L)
{
return 0;
}
// Read the params:
AString GroupName, RankName;
S.GetStackValues(2, GroupName, RankName);
// Add the group to the rank:
S.Push(cRoot::Get()->GetRankManager()->AddGroupToRank(GroupName, RankName));
return 1;
@ -86,11 +86,11 @@ static int tolua_cRankManager_AddPermissionToGroup(lua_State * L)
{
return 0;
}
// Read the params:
AString GroupName, Permission;
S.GetStackValues(2, Permission, GroupName);
// Add the group to the rank:
S.Push(cRoot::Get()->GetRankManager()->AddPermissionToGroup(Permission, GroupName));
return 1;
@ -115,11 +115,11 @@ static int tolua_cRankManager_AddRestrictionToGroup(lua_State * L)
{
return 0;
}
// Read the params:
AString GroupName, Permission;
S.GetStackValues(2, Permission, GroupName);
// Add the group to the rank:
S.Push(cRoot::Get()->GetRankManager()->AddRestrictionToGroup(Permission, GroupName));
return 1;
@ -134,7 +134,7 @@ static int tolua_cRankManager_AddRank(lua_State * L)
{
// Function signature:
// cRankManager:AddRank(RankName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -144,11 +144,11 @@ static int tolua_cRankManager_AddRank(lua_State * L)
{
return 0;
}
// Read the params:
AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode;
S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
// Add the rank:
cRoot::Get()->GetRankManager()->AddRank(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
return 0;
@ -184,7 +184,7 @@ static int tolua_cRankManager_GetAllGroups(lua_State * L)
{
// Function signature:
// cRankManager:GetAllGroups() -> arraytable of GroupNames
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -193,10 +193,10 @@ static int tolua_cRankManager_GetAllGroups(lua_State * L)
{
return 0;
}
// Get the groups:
AStringVector Groups = cRoot::Get()->GetRankManager()->GetAllGroups();
// Push the results:
S.Push(Groups);
return 1;
@ -211,7 +211,7 @@ static int tolua_cRankManager_GetAllPermissions(lua_State * L)
{
// Function signature:
// cRankManager:GetAllPermissions() -> arraytable of Permissions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -220,10 +220,10 @@ static int tolua_cRankManager_GetAllPermissions(lua_State * L)
{
return 0;
}
// Get the permissions:
AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllPermissions();
// Push the results:
S.Push(Permissions);
return 1;
@ -238,7 +238,7 @@ static int tolua_cRankManager_GetAllRestrictions(lua_State * L)
{
// Function signature:
// cRankManager:GetAllRestrictions() -> arraytable of Permissions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -247,10 +247,10 @@ static int tolua_cRankManager_GetAllRestrictions(lua_State * L)
{
return 0;
}
// Get the permissions:
AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllRestrictions();
// Push the results:
S.Push(Permissions);
return 1;
@ -265,7 +265,7 @@ static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L)
{
// Function signature:
// cRankManager:GetAllPermissionsRestrictions() -> arraytable of Permissions and Restrictions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -274,10 +274,10 @@ static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L)
{
return 0;
}
// Get the permissions:
AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllPermissionsRestrictions();
// Push the results:
S.Push(Permissions);
return 1;
@ -319,7 +319,7 @@ static int tolua_cRankManager_GetAllRanks(lua_State * L)
{
// Function signature:
// cRankManager:GetAllRanks() -> arraytable of RankNames
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -328,10 +328,10 @@ static int tolua_cRankManager_GetAllRanks(lua_State * L)
{
return 0;
}
// Get the ranks:
AStringVector Ranks = cRoot::Get()->GetRankManager()->GetAllRanks();
// Push the results:
S.Push(Ranks);
return 1;
@ -346,7 +346,7 @@ static int tolua_cRankManager_GetDefaultRank(lua_State * L)
{
// Function signature:
// cRankManager:GetDefaultRank() -> string
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -355,7 +355,7 @@ static int tolua_cRankManager_GetDefaultRank(lua_State * L)
{
return 0;
}
// Return the rank name:
S.Push(cRoot::Get()->GetRankManager()->GetDefaultRank());
return 1;
@ -370,7 +370,7 @@ static int tolua_cRankManager_GetGroupPermissions(lua_State * L)
{
// Function signature:
// cRankManager:GetGroupPermissions(GroupName) -> arraytable of permissions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -380,14 +380,14 @@ static int tolua_cRankManager_GetGroupPermissions(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName;
S.GetStackValue(2, GroupName);
// Get the permissions:
AStringVector Permissions = cRoot::Get()->GetRankManager()->GetGroupPermissions(GroupName);
// Push the results:
S.Push(Permissions);
return 1;
@ -402,7 +402,7 @@ static int tolua_cRankManager_GetGroupRestrictions(lua_State * L)
{
// Function signature:
// cRankManager:GetGroupRestrictions(GroupName) -> arraytable of restrictions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -412,14 +412,14 @@ static int tolua_cRankManager_GetGroupRestrictions(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName;
S.GetStackValue(2, GroupName);
// Get the restrictions:
AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetGroupRestrictions(GroupName);
// Push the results:
S.Push(Restrictions);
return 1;
@ -434,7 +434,7 @@ static int tolua_cRankManager_GetPlayerGroups(lua_State * L)
{
// Function signature:
// cRankManager:GetPlayerGroups(PlayerUUID) -> arraytable of GroupNames
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -444,14 +444,14 @@ static int tolua_cRankManager_GetPlayerGroups(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Get the groups:
AStringVector Groups = cRoot::Get()->GetRankManager()->GetPlayerGroups(PlayerUUID);
// Push the results:
S.Push(Groups);
return 1;
@ -466,7 +466,7 @@ static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L)
{
// Function signature:
// cRankManager:GetPlayerMsgVisuals(PlayerUUID) -> string, string, string
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -476,18 +476,18 @@ static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Get the permissions:
AString MsgPrefix, MsgSuffix, MsgNameColorCode;
if (!cRoot::Get()->GetRankManager()->GetPlayerMsgVisuals(PlayerUUID, MsgPrefix, MsgSuffix, MsgNameColorCode))
{
return 0;
}
// Push the results:
S.Push(MsgPrefix);
S.Push(MsgSuffix);
@ -504,7 +504,7 @@ static int tolua_cRankManager_GetPlayerPermissions(lua_State * L)
{
// Function signature:
// cRankManager:GetPlayerPermissions(PlayerUUID) -> arraytable of permissions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -514,14 +514,14 @@ static int tolua_cRankManager_GetPlayerPermissions(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Get the permissions:
AStringVector Permissions = cRoot::Get()->GetRankManager()->GetPlayerPermissions(PlayerUUID);
// Push the results:
S.Push(Permissions);
return 1;
@ -536,7 +536,7 @@ static int tolua_cRankManager_GetPlayerRestrictions(lua_State * L)
{
// Function signature:
// cRankManager:GetPlayerRestrictions(PlayerUUID) -> arraytable of restrictions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -546,14 +546,14 @@ static int tolua_cRankManager_GetPlayerRestrictions(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Get the permissions:
AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetPlayerRestrictions(PlayerUUID);
// Push the results:
S.Push(Restrictions);
return 1;
@ -568,7 +568,7 @@ static int tolua_cRankManager_GetPlayerRankName(lua_State * L)
{
// Function signature:
// cRankManager:GetPlayerRankName(PlayerUUID) -> string
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -578,14 +578,14 @@ static int tolua_cRankManager_GetPlayerRankName(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Get the rank name:
AString RankName = cRoot::Get()->GetRankManager()->GetPlayerRankName(PlayerUUID);
// Push the result:
S.Push(RankName);
return 1;
@ -632,7 +632,7 @@ static int tolua_cRankManager_GetRankGroups(lua_State * L)
{
// Function signature:
// cRankManager:GetRankGroups(RankName) -> arraytable of groupnames
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -642,14 +642,14 @@ static int tolua_cRankManager_GetRankGroups(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName;
S.GetStackValue(2, RankName);
// Get the groups:
AStringVector Groups = cRoot::Get()->GetRankManager()->GetRankGroups(RankName);
// Push the results:
S.Push(Groups);
return 1;
@ -664,7 +664,7 @@ static int tolua_cRankManager_GetRankPermissions(lua_State * L)
{
// Function signature:
// cRankManager:GetRankPermissions(RankName) -> arraytable of permissions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -674,14 +674,14 @@ static int tolua_cRankManager_GetRankPermissions(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName;
S.GetStackValue(2, RankName);
// Get the permissions:
AStringVector Permissions = cRoot::Get()->GetRankManager()->GetRankPermissions(RankName);
// Push the results:
S.Push(Permissions);
return 1;
@ -696,7 +696,7 @@ static int tolua_cRankManager_GetRankRestrictions(lua_State * L)
{
// Function signature:
// cRankManager:GetRankRestrictions(RankName) -> arraytable of restrictions
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -706,14 +706,14 @@ static int tolua_cRankManager_GetRankRestrictions(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName;
S.GetStackValue(2, RankName);
// Get the permissions:
AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetRankRestrictions(RankName);
// Push the results:
S.Push(Restrictions);
return 1;
@ -728,7 +728,7 @@ static int tolua_cRankManager_GetRankVisuals(lua_State * L)
{
// Function signature:
// cRankManager:GetRankVisuals(RankName) -> MsgPrefix, MsgSuffix, MsgNameColorCode
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -738,11 +738,11 @@ static int tolua_cRankManager_GetRankVisuals(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName;
S.GetStackValue(2, RankName);
// Get the visuals:
AString MsgPrefix, MsgSuffix, MsgNameColorCode;
if (!cRoot::Get()->GetRankManager()->GetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode))
@ -750,7 +750,7 @@ static int tolua_cRankManager_GetRankVisuals(lua_State * L)
// No such rank, return nothing:
return 0;
}
// Push the results:
S.Push(MsgPrefix);
S.Push(MsgSuffix);
@ -767,7 +767,7 @@ static int tolua_cRankManager_GroupExists(lua_State * L)
{
// Function signature:
// cRankManager:GroupExists(GroupName) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -777,14 +777,14 @@ static int tolua_cRankManager_GroupExists(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName;
S.GetStackValue(2, GroupName);
// Get the response:
bool res = cRoot::Get()->GetRankManager()->GroupExists(GroupName);
// Push the result:
S.Push(res);
return 1;
@ -799,7 +799,7 @@ static int tolua_cRankManager_IsGroupInRank(lua_State * L)
{
// Function signature:
// cRankManager:IsGroupInRank(GroupName, RankName) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -809,14 +809,14 @@ static int tolua_cRankManager_IsGroupInRank(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName, RankName;
S.GetStackValues(2, GroupName, RankName);
// Get the response:
bool res = cRoot::Get()->GetRankManager()->IsGroupInRank(GroupName, RankName);
// Push the result:
S.Push(res);
return 1;
@ -831,7 +831,7 @@ static int tolua_cRankManager_IsPermissionInGroup(lua_State * L)
{
// Function signature:
// cRankManager:IsPermissionInGroup(Permission, GroupName) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -841,14 +841,14 @@ static int tolua_cRankManager_IsPermissionInGroup(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName, Permission;
S.GetStackValues(2, Permission, GroupName);
// Get the response:
bool res = cRoot::Get()->GetRankManager()->IsPermissionInGroup(Permission, GroupName);
// Push the result:
S.Push(res);
return 1;
@ -863,7 +863,7 @@ static int tolua_cRankManager_IsRestrictionInGroup(lua_State * L)
{
// Function signature:
// cRankManager:IsRestrictionInGroup(Restriction, GroupName) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -873,14 +873,14 @@ static int tolua_cRankManager_IsRestrictionInGroup(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName, Restriction;
S.GetStackValues(2, Restriction, GroupName);
// Get the response:
bool res = cRoot::Get()->GetRankManager()->IsRestrictionInGroup(Restriction, GroupName);
// Push the result:
S.Push(res);
return 1;
@ -895,7 +895,7 @@ static int tolua_cRankManager_IsPlayerRankSet(lua_State * L)
{
// Function signature:
// cRankManager:IsPlayerRankSet(PlayerUUID) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -905,14 +905,14 @@ static int tolua_cRankManager_IsPlayerRankSet(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Get the response:
bool res = cRoot::Get()->GetRankManager()->IsPlayerRankSet(PlayerUUID);
// Push the result:
S.Push(res);
return 1;
@ -927,7 +927,7 @@ static int tolua_cRankManager_RankExists(lua_State * L)
{
// Function signature:
// cRankManager:RankExists(RankName) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -937,14 +937,14 @@ static int tolua_cRankManager_RankExists(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName;
S.GetStackValue(2, RankName);
// Get the response:
bool res = cRoot::Get()->GetRankManager()->RankExists(RankName);
// Push the result:
S.Push(res);
return 1;
@ -959,7 +959,7 @@ static int tolua_cRankManager_RemoveGroup(lua_State * L)
{
// Function signature:
// cRankManager:RemoveGroup(GroupName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -969,11 +969,11 @@ static int tolua_cRankManager_RemoveGroup(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName;
S.GetStackValue(2, GroupName);
// Remove the group:
cRoot::Get()->GetRankManager()->RemoveGroup(GroupName);
return 0;
@ -988,7 +988,7 @@ static int tolua_cRankManager_RemoveGroupFromRank(lua_State * L)
{
// Function signature:
// cRankManager:RemoveGroupFromRank(GroupName, RankName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -998,11 +998,11 @@ static int tolua_cRankManager_RemoveGroupFromRank(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName, RankName;
S.GetStackValues(2, GroupName, RankName);
// Remove the group:
cRoot::Get()->GetRankManager()->RemoveGroupFromRank(GroupName, RankName);
return 0;
@ -1017,7 +1017,7 @@ static int tolua_cRankManager_RemovePermissionFromGroup(lua_State * L)
{
// Function signature:
// cRankManager:RemovePermissionFromGroup(Permission, GroupName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1027,11 +1027,11 @@ static int tolua_cRankManager_RemovePermissionFromGroup(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName, Permission;
S.GetStackValues(2, Permission, GroupName);
// Remove the permission:
cRoot::Get()->GetRankManager()->RemovePermissionFromGroup(Permission, GroupName);
return 0;
@ -1046,7 +1046,7 @@ static int tolua_cRankManager_RemoveRestrictionFromGroup(lua_State * L)
{
// Function signature:
// cRankManager:RemoveRestrictionFromGroup(Restriction, GroupName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1056,11 +1056,11 @@ static int tolua_cRankManager_RemoveRestrictionFromGroup(lua_State * L)
{
return 0;
}
// Get the params:
AString GroupName, Restriction;
S.GetStackValues(2, Restriction, GroupName);
// Remove the restriction:
cRoot::Get()->GetRankManager()->RemoveRestrictionFromGroup(Restriction, GroupName);
return 0;
@ -1075,7 +1075,7 @@ static int tolua_cRankManager_RemovePlayerRank(lua_State * L)
{
// Function signature:
// cRankManager:RemovePlayerRank(PlayerUUID)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1085,11 +1085,11 @@ static int tolua_cRankManager_RemovePlayerRank(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID;
S.GetStackValue(2, PlayerUUID);
// Remove the player's rank:
cRoot::Get()->GetRankManager()->RemovePlayerRank(PlayerUUID);
return 0;
@ -1104,7 +1104,7 @@ static int tolua_cRankManager_RemoveRank(lua_State * L)
{
// Function signature:
// cRankManager:RemoveRank(RankName, [ReplacementRankName])
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1115,11 +1115,11 @@ static int tolua_cRankManager_RemoveRank(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName, ReplacementRankName;
S.GetStackValues(2, RankName, ReplacementRankName);
// Remove the rank:
cRoot::Get()->GetRankManager()->RemoveRank(RankName, ReplacementRankName);
return 0;
@ -1134,7 +1134,7 @@ static int tolua_cRankManager_RenameGroup(lua_State * L)
{
// Function signature:
// cRankManager:RenameGroup(OldName, NewName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1144,14 +1144,14 @@ static int tolua_cRankManager_RenameGroup(lua_State * L)
{
return 0;
}
// Get the params:
AString OldName, NewName;
S.GetStackValues(2, OldName, NewName);
// Remove the group:
bool res = cRoot::Get()->GetRankManager()->RenameGroup(OldName, NewName);
// Push the result:
S.Push(res);
return 1;
@ -1166,7 +1166,7 @@ static int tolua_cRankManager_RenameRank(lua_State * L)
{
// Function signature:
// cRankManager:RenameRank(OldName, NewName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1176,14 +1176,14 @@ static int tolua_cRankManager_RenameRank(lua_State * L)
{
return 0;
}
// Get the params:
AString OldName, NewName;
S.GetStackValues(2, OldName, NewName);
// Remove the rank:
bool res = cRoot::Get()->GetRankManager()->RenameRank(OldName, NewName);
// Push the result:
S.Push(res);
return 1;
@ -1198,7 +1198,7 @@ static int tolua_cRankManager_SetDefaultRank(lua_State * L)
{
// Function signature:
// cRankManager:SetDefaultRank(RankName) -> bool
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1208,11 +1208,11 @@ static int tolua_cRankManager_SetDefaultRank(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName;
S.GetStackValue(2, RankName);
// Set the rank, return the result:
S.Push(cRoot::Get()->GetRankManager()->SetDefaultRank(RankName));
return 1;
@ -1227,7 +1227,7 @@ static int tolua_cRankManager_SetPlayerRank(lua_State * L)
{
// Function signature:
// cRankManager:SetPlayerRank(PlayerUUID, PlayerName, RankName)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1237,11 +1237,11 @@ static int tolua_cRankManager_SetPlayerRank(lua_State * L)
{
return 0;
}
// Get the params:
AString PlayerUUID, PlayerName, RankName;
S.GetStackValues(2, PlayerUUID, PlayerName, RankName);
// Set the rank:
cRoot::Get()->GetRankManager()->SetPlayerRank(PlayerUUID, PlayerName, RankName);
return 0;
@ -1256,7 +1256,7 @@ static int tolua_cRankManager_SetRankVisuals(lua_State * L)
{
// Function signature:
// cRankManager:SetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode)
cLuaState S(L);
if (
!S.CheckParamUserTable(1, "cRankManager") ||
@ -1266,11 +1266,11 @@ static int tolua_cRankManager_SetRankVisuals(lua_State * L)
{
return 0;
}
// Get the params:
AString RankName, MsgPrefix, MsgSuffix, MsgNameColorCode;
S.GetStackValues(2, RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
// Set the visuals:
cRoot::Get()->GetRankManager()->SetRankVisuals(RankName, MsgPrefix, MsgSuffix, MsgNameColorCode);
return 0;
@ -1285,7 +1285,7 @@ void cManualBindings::BindRankManager(lua_State * tolua_S)
// Create the cRankManager class in the API:
tolua_usertype(tolua_S, "cRankManager");
tolua_cclass(tolua_S, "cRankManager", "cRankManager", "", nullptr);
// Fill in the functions (alpha-sorted):
tolua_beginmodule(tolua_S, "cRankManager");
tolua_function(tolua_S, "AddGroup", tolua_cRankManager_AddGroup);

View File

@ -30,7 +30,7 @@ static int tolua_cWorld_BroadcastParticleEffect(lua_State * tolua_S)
{
return 0;
}
// Read the params:
cWorld * World = nullptr;
AString Name;
@ -68,7 +68,7 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
World:ChunkStay(ChunkCoordTable, OnChunkAvailable, OnAllChunksAvailable)
ChunkCoordTable == { {Chunk1x, Chunk1z}, {Chunk2x, Chunk2z}, ... }
*/
cLuaState L(tolua_S);
if (
!L.CheckParamUserType (1, "cWorld") ||
@ -78,13 +78,13 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
{
return 0;
}
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S);
if (Plugin == nullptr)
{
return 0;
}
// Read the params:
cWorld * World = reinterpret_cast<cWorld *>(tolua_tousertype(tolua_S, 1, nullptr));
if (World == nullptr)
@ -116,7 +116,7 @@ static int tolua_cWorld_DoExplosionAt(lua_State * tolua_S)
/* Function signature:
World:DoExplosionAt(ExplosionSize, BlockX, BlockY, BlockZ, CanCauseFire, SourceType, [SourceData])
*/
cLuaState L(tolua_S);
if (
!L.CheckParamUserType (1, "cWorld") ||
@ -128,7 +128,7 @@ static int tolua_cWorld_DoExplosionAt(lua_State * tolua_S)
{
return 0;
}
// Read the params:
cWorld * World;
double ExplosionSize;
@ -405,7 +405,7 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S)
/* Function signature:
World:PrepareChunk(ChunkX, ChunkZ, Callback)
*/
// Check the param types:
cLuaState L(tolua_S);
if (
@ -416,7 +416,7 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S)
{
return 0;
}
// Read the params:
cWorld * world = nullptr;
int chunkX = 0;
@ -497,7 +497,7 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S)
{
// Binding for cWorld::QueueTask
// Params: function
// Retrieve the cPlugin from the LuaState:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S);
if (Plugin == nullptr)
@ -578,7 +578,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
{
// Binding for cWorld::ScheduleTask
// Params: function, Ticks
// Retrieve the cPlugin from the LuaState:
cPluginLua * Plugin = cManualBindings::GetLuaPlugin(tolua_S);
if (Plugin == nullptr)
@ -609,7 +609,7 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
{
return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
}
auto ResettableTask = std::make_shared<cLuaWorldTask>(*Plugin, FnRef);
Plugin->AddResettable(ResettableTask);
World->ScheduleTask(static_cast<int>(tolua_tonumber(tolua_S, 2, 0)), std::bind(&cLuaWorldTask::Run, ResettableTask, std::placeholders::_1));

View File

@ -20,14 +20,14 @@ class cPlugin
{
public:
// tolua_end
/** Creates a new instance.
a_FolderName is the name of the folder (in the Plugins folder) from which the plugin is loaded.
The plugin's name defaults to the folder name. */
cPlugin(const AString & a_FolderName);
virtual ~cPlugin();
/** Called as the last call into the plugin before it is unloaded. */
virtual void OnDisable(void) {}
@ -109,22 +109,22 @@ public:
virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) = 0;
virtual bool OnWorldStarted (cWorld & a_World) = 0;
virtual bool OnWorldTick (cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec) = 0;
/** Handles the command split into a_Split, issued by player a_Player.
Command permissions have already been checked.
Returns true if command handled successfully. */
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer & a_Player, const AString & a_FullCommand) = 0;
/** Handles the console command split into a_Split.
Returns true if command handled successfully. Output is to be sent to the a_Output callback. */
virtual bool HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_FullCommand) = 0;
/** All bound commands are to be removed, do any language-dependent cleanup here */
virtual void ClearCommands(void) {}
/** All bound console commands are to be removed, do any language-dependent cleanup here */
virtual void ClearConsoleCommands(void) {}
// tolua_begin
const AString & GetName(void) const { return m_Name; }
void SetName(const AString & a_Name) { m_Name = a_Name; }
@ -145,7 +145,7 @@ public:
bool IsLoaded(void) const { return (m_Status == cPluginManager::psLoaded); }
// tolua_end
// Needed for ManualBindings' tolua_ForEach<>
static const char * GetClassStatic(void) { return "cPlugin"; }

View File

@ -105,13 +105,13 @@ bool cPluginLua::Load(void)
{
m_LuaState.Create();
m_LuaState.RegisterAPILibs();
// Inject the identification global variables into the state:
lua_pushlightuserdata(m_LuaState, this);
lua_setglobal(m_LuaState, LUA_PLUGIN_INSTANCE_VAR_NAME);
lua_pushstring(m_LuaState, GetName().c_str());
lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME);
// Add the plugin's folder to the package.path and package.cpath variables (#693):
m_LuaState.AddPackagePath("path", FILE_IO_PREFIX + GetLocalFolder() + "/?.lua");
#ifdef _WIN32
@ -119,7 +119,7 @@ bool cPluginLua::Load(void)
#else
m_LuaState.AddPackagePath("cpath", FILE_IO_PREFIX + GetLocalFolder() + "/?.so");
#endif
tolua_pushusertype(m_LuaState, this, "cPluginLua");
lua_setglobal(m_LuaState, "g_Plugin");
}
@ -145,7 +145,7 @@ bool cPluginLua::Load(void)
}
}
std::sort(LuaFiles.begin(), LuaFiles.end());
// Warn if there are no Lua files in the plugin folder:
if (LuaFiles.empty())
{
@ -1879,7 +1879,7 @@ bool cPluginLua::HandleCommand(const AStringVector & a_Split, cPlayer & a_Player
LOGWARNING("Command handler is registered in cPluginManager but not in cPlugin, wtf? Command \"%s\".", a_Split[0].c_str());
return false;
}
cCSLock Lock(m_CriticalSection);
bool res = false;
m_LuaState.Call(cmd->second, a_Split, &a_Player, a_FullCommand, cLuaState::Return, res);
@ -1901,7 +1901,7 @@ bool cPluginLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOut
);
return false;
}
cCSLock Lock(m_CriticalSection);
bool res = false;
AString str;
@ -1967,13 +1967,13 @@ bool cPluginLua::CanAddOldStyleHook(int a_HookType)
m_LuaState.LogStackTrace();
return false;
}
// Check if the function is available
if (m_LuaState.HasFunction(FnName))
{
return true;
}
LOGWARNING("Plugin %s wants to add a hook (%d), but it doesn't provide the callback function \"%s\" for it. The plugin need not work properly.",
GetName().c_str(), a_HookType, FnName
);
@ -2042,7 +2042,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType)
case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged";
case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging";
case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick";
case cPluginManager::HOOK_NUM_HOOKS:
{
// Satisfy a warning that all enum values should be used in a switch
@ -2062,7 +2062,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType)
bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
{
ASSERT(m_CriticalSection.IsLockedByCurrentThread()); // It probably has to be, how else would we have a LuaState?
// Check if the function reference is valid:
cLuaState::cRef * Ref = new cLuaState::cRef(m_LuaState, a_FnRefIdx);
if ((Ref == nullptr) || !Ref->IsValid())
@ -2073,7 +2073,7 @@ bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
Ref = nullptr;
return false;
}
m_HookMap[a_HookType].push_back(Ref);
return true;
}
@ -2090,7 +2090,7 @@ int cPluginLua::CallFunctionFromForeignState(
)
{
cCSLock Lock(m_CriticalSection);
// Call the function:
int NumReturns = m_LuaState.CallFunctionWithForeignParams(a_FunctionName, a_ForeignState, a_ParamStart, a_ParamEnd);
if (NumReturns < 0)
@ -2098,17 +2098,17 @@ int cPluginLua::CallFunctionFromForeignState(
// The call has failed, an error has already been output to the log, so just silently bail out with the same error
return NumReturns;
}
// Copy all the return values:
int Top = lua_gettop(m_LuaState);
int res = a_ForeignState.CopyStackFrom(m_LuaState, Top - NumReturns + 1, Top);
// Remove the return values off this stack:
if (NumReturns > 0)
{
lua_pop(m_LuaState, NumReturns);
}
return res;
}
@ -2204,7 +2204,7 @@ void cPluginLua::Unreference(int a_LuaRef)
bool cPluginLua::CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer & a_Player, bool a_CanRefuse)
{
ASSERT(a_FnRef != LUA_REFNIL);
cCSLock Lock(m_CriticalSection);
bool res = false;
m_LuaState.Call(a_FnRef, &a_Window, &a_Player, a_CanRefuse, cLuaState::Return, res);
@ -2218,7 +2218,7 @@ bool cPluginLua::CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer
void cPluginLua::CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum)
{
ASSERT(a_FnRef != LUA_REFNIL);
cCSLock Lock(m_CriticalSection);
m_LuaState.Call(a_FnRef, &a_Window, a_SlotNum);
}

View File

@ -36,7 +36,7 @@ class cPluginLua :
public:
// tolua_end
/** A RAII-style mutex lock for accessing the internal LuaState.
This will be the only way to retrieve the plugin's LuaState;
therefore it directly supports accessing the LuaState of the locked plugin.
@ -54,10 +54,10 @@ public:
}
cLuaState & operator ()(void) { return m_Plugin.m_LuaState; }
protected:
cPluginLua & m_Plugin;
/** RAII lock for m_Plugin.m_CriticalSection */
cCSLock m_Lock;
} ;
@ -92,8 +92,8 @@ public:
typedef SharedPtr<cResettable> cResettablePtr;
typedef std::vector<cResettablePtr> cResettablePtrs;
cPluginLua(const AString & a_PluginDirectory);
~cPluginLua();
@ -169,18 +169,18 @@ public:
virtual bool OnWeatherChanging (cWorld & a_World, eWeather & a_NewWeather) override;
virtual bool OnWorldStarted (cWorld & a_World) override;
virtual bool OnWorldTick (cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec) override;
virtual bool HandleCommand(const AStringVector & a_Split, cPlayer & a_Player, const AString & a_FullCommand) override;
virtual bool HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_FullCommand) override;
virtual void ClearCommands(void) override;
virtual void ClearConsoleCommands(void) override;
/** Returns true if the plugin contains the function for the specified hook type, using the old-style registration (#121) */
bool CanAddOldStyleHook(int a_HookType);
// cWebPlugin overrides
virtual const AString GetWebTitle(void) const override {return GetName(); }
virtual AString HandleWebRequest(const HTTPRequest & a_Request) override;
@ -188,7 +188,7 @@ public:
/** Adds a new web tab to webadmin.
Displaying the tab calls the referenced function. */
bool AddWebTab(const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference); // Exported in ManualBindings.cpp
/** Binds the command to call the function specified by a Lua function reference. Simply adds to CommandMap. */
void BindCommand(const AString & a_Command, int a_FnRef);
@ -198,25 +198,25 @@ public:
cLuaState & GetLuaState(void) { return m_LuaState; }
cCriticalSection & GetCriticalSection(void) { return m_CriticalSection; }
/** Removes a previously referenced object (luaL_unref()) */
void Unreference(int a_LuaRef);
/** Calls the plugin-specified "cLuaWindow closing" callback. Returns true only if the callback returned true */
bool CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer & a_Player, bool a_CanRefuse);
/** Calls the plugin-specified "cLuaWindow slot changed" callback. */
void CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum);
/** Returns the name of Lua function that should handle the specified hook type in the older (#121) API */
static const char * GetHookFnName(int a_HookType);
/** Adds a Lua function to be called for the specified hook.
The function has to be on the Lua stack at the specified index a_FnRefIdx
Returns true if the hook was added successfully.
*/
bool AddHookRef(int a_HookType, int a_FnRefIdx);
/** Calls a function in this plugin's LuaState with parameters copied over from a_ForeignState.
The values that the function returns are placed onto a_ForeignState.
Returns the number of values returned, if successful, or negative number on failure. */
@ -226,7 +226,7 @@ public:
int a_ParamStart,
int a_ParamEnd
);
/** Call a Lua function residing in the plugin. */
template <typename FnT, typename... Args>
bool Call(FnT a_Fn, Args && ... a_Args)
@ -241,20 +241,20 @@ public:
protected:
/** Maps command name into Lua function reference */
typedef std::map<AString, int> CommandMap;
/** Provides an array of Lua function references */
typedef std::vector<cLuaState::cRef *> cLuaRefs;
/** Maps hook types into arrays of Lua function references to call for each hook type */
typedef std::map<int, cLuaRefs> cHookMap;
/** The mutex protecting m_LuaState and each of the m_Resettables[] against multithreaded use. */
cCriticalSection m_CriticalSection;
/** The plugin's Lua state. */
cLuaState m_LuaState;
/** Objects that need notification when the plugin is about to be unloaded. */
cResettablePtrs m_Resettables;
@ -263,10 +263,10 @@ protected:
/** Console commands that the plugin has registered. */
CommandMap m_ConsoleCommands;
/** Hooks that the plugin has registered. */
cHookMap m_HookMap;
/** Releases all Lua references, notifies and removes all m_Resettables[] and closes the m_LuaState. */
void Close(void);

View File

@ -317,21 +317,21 @@ bool cPluginManager::CallHookChat(cPlayer & a_Player, AString & a_Message)
// The command has executed successfully
return true;
}
case crBlocked:
{
// The command was blocked by a plugin using HOOK_EXECUTE_COMMAND
// The plugin has most likely sent a message to the player already
return true;
}
case crError:
{
// An error in the plugin has prevented the command from executing. Report the error to the player:
a_Player.SendMessageFailure(Printf("Something went wrong while executing command \"%s\"", a_Message.c_str()));
return true;
}
case crNoPermission:
{
// The player is not allowed to execute this command

View File

@ -143,10 +143,10 @@ public:
HOOK_WORLD_TICK,
// tolua_end
// Note that if a hook type is added, it may need processing in cPlugin::CanAddHook() descendants,
// and it definitely needs adding in cPluginLua::GetHookFnName() !
// Keep these two as the last items, they are used for validity checking and get their values automagically
HOOK_NUM_HOOKS,
HOOK_MAX = HOOK_NUM_HOOKS - 1,
@ -157,22 +157,22 @@ public:
{
public:
virtual ~cCommandEnumCallback() {}
/** Called for each command; return true to abort enumeration
For console commands, a_Permission is not used (set to empty string)
*/
virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) = 0;
} ;
/** The interface used for enumerating and extern-calling plugins */
typedef cItemCallback<cPlugin> cPluginCallback;
typedef std::list<cPlugin *> PluginList;
/** Called each tick, calls the plugins' OnTick hook, as well as processes plugin events (addition, removal) */
void Tick(float a_Dt);
/** Returns the instance of the Plugin Manager (there is only ever one) */
static cPluginManager * Get(void); // tolua_export
@ -182,7 +182,7 @@ public:
/** Schedules a reload of the plugins to happen within the next call to Tick(). */
void ReloadPlugins(); // tolua_export
/** Adds the plugin to the list of plugins called for the specified hook type.
If a plugin adds multiple handlers for a single hook, it is added only once (ignore-duplicates). */
void AddHook(cPlugin * a_Plugin, int a_HookType);
@ -192,7 +192,7 @@ public:
/** Returns the number of plugins that are psLoaded. */
size_t GetNumLoadedPlugins(void) const; // tolua_export
// Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort
bool CallHookBlockSpread (cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source);
bool CallHookBlockToPickups (cWorld & a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
@ -260,7 +260,7 @@ public:
bool CallHookWeatherChanging (cWorld & a_World, eWeather & a_NewWeather);
bool CallHookWorldStarted (cWorld & a_World);
bool CallHookWorldTick (cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec);
/** Queues the specified plugin to be unloaded in the next call to Tick().
Note that this function returns before the plugin is unloaded, to avoid deadlocks. */
void UnloadPlugin(const AString & a_PluginFolder); // tolua_export
@ -271,10 +271,10 @@ public:
/** Removes all hooks the specified plugin has registered */
void RemoveHooks(cPlugin * a_Plugin);
/** Removes the plugin of the specified name from the internal structures and deletes its object. */
void RemovePlugin(const AString & a_PluginName);
/** Removes all command bindings that the specified plugin has made */
void RemovePluginCommands(cPlugin * a_Plugin);
@ -283,47 +283,47 @@ public:
/** Binds a command to the specified plugin. Returns true if successful, false if command already bound. */
bool BindCommand(const AString & a_Command, cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString); // Exported in ManualBindings.cpp, without the a_Plugin param
/** Calls a_Callback for each bound command, returns true if all commands were enumerated */
bool ForEachCommand(cCommandEnumCallback & a_Callback); // Exported in ManualBindings.cpp
/** Returns true if the command is in the command map */
bool IsCommandBound(const AString & a_Command); // tolua_export
/** Returns the permission needed for the specified command; empty string if command not found */
AString GetCommandPermission(const AString & a_Command); // tolua_export
/** Executes the command, as if it was requested by a_Player. Checks permissions first. Returns crExecuted if executed. */
CommandResult ExecuteCommand(cPlayer & a_Player, const AString & a_Command); // tolua_export
/** Executes the command, as if it was requested by a_Player. Permisssions are not checked. Returns crExecuted if executed. */
CommandResult ForceExecuteCommand(cPlayer & a_Player, const AString & a_Command); // tolua_export
/** Removes all console command bindings that the specified plugin has made */
void RemovePluginConsoleCommands(cPlugin * a_Plugin);
/** Binds a console command to the specified plugin. Returns true if successful, false if command already bound. */
bool BindConsoleCommand(const AString & a_Command, cPlugin * a_Plugin, const AString & a_HelpString); // Exported in ManualBindings.cpp, without the a_Plugin param
/** Calls a_Callback for each bound console command, returns true if all commands were enumerated */
bool ForEachConsoleCommand(cCommandEnumCallback & a_Callback); // Exported in ManualBindings.cpp
/** Returns true if the console command is in the command map */
bool IsConsoleCommandBound(const AString & a_Command); // tolua_export
/** Executes the command split into a_Split, as if it was given on the console.
Returns true if executed. Output is sent to the a_Output callback
Exported in ManualBindings.cpp with a different signature. */
bool ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output, const AString & a_Command);
/** Appends all commands beginning with a_Text (case-insensitive) into a_Results.
If a_Player is not nullptr, only commands for which the player has permissions are added.
*/
void TabCompleteCommand(const AString & a_Text, AStringVector & a_Results, cPlayer * a_Player);
/** Returns true if the specified hook type is within the allowed range */
static bool IsValidHookType(int a_HookType);
/** Calls the specified callback with the plugin object of the specified plugin.
Returns false if plugin not found, otherwise returns the value that the callback has returned. */
bool DoWithPlugin(const AString & a_PluginName, cPluginCallback & a_Callback);
@ -331,14 +331,14 @@ public:
/** Calls the specified callback for each plugin in m_Plugins.
Returns true if all plugins have been reported, false if the callback has aborted the enumeration by returning true. */
bool ForEachPlugin(cPluginCallback & a_Callback);
/** Returns the path where individual plugins' folders are expected.
The path doesn't end in a slash. */
static AString GetPluginsPath(void) { return FILE_IO_PREFIX + AString("Plugins"); } // tolua_export
private:
friend class cRoot;
class cCommandReg
{
public:
@ -346,7 +346,7 @@ private:
AString m_Permission; // Not used for console commands
AString m_HelpString;
} ;
typedef std::map<int, cPluginManager::PluginList> HookMap;
typedef std::map<AString, cCommandReg> CommandMap;

View File

@ -40,7 +40,7 @@ public:
/** Returns the title of the plugin, as it should be presented in the webadmin's pages tree. */
virtual const AString GetWebTitle(void) const = 0;
/** Sanitizes the input string, replacing spaces with underscores. */
static AString SafeString(const AString & a_String);

View File

@ -42,7 +42,7 @@ static struct
{biExtremeHillsEdge, "ExtremeHillsEdge"},
{biJungle, "Jungle"},
{biJungleHills, "JungleHills"},
// Release 1.7 biomes:
{biJungleEdge, "JungleEdge"},
{biDeepOcean, "DeepOcean"},
@ -61,7 +61,7 @@ static struct
{biMesa, "Mesa"},
{biMesaPlateauF, "MesaPlateauF"},
{biMesaPlateau, "MesaPlateau"},
// Release 1.7 variants:
{biSunflowerPlains, "SunflowerPlains"},
{biDesertM, "DesertM"},
@ -107,7 +107,7 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
// It was an invalid number
return biInvalidBiome;
}
for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
{
if (NoCaseCompare(g_BiomeMap[i].m_String, a_BiomeString) == 0)
@ -239,7 +239,7 @@ int GetSnowStartHeight(EMCSBiome a_Biome)
// Always snow
return 0;
}
case biExtremeHills:
case biExtremeHillsM:
case biExtremeHillsPlus:
@ -338,7 +338,7 @@ int GetSnowStartHeight(EMCSBiome a_Biome)
// These biomes don't actualy have any downfall.
return 1000;
}
case biNether:
case biEnd:
{

View File

@ -49,7 +49,7 @@ enum EMCSBiome
biExtremeHillsEdge = 20,
biJungle = 21,
biJungleHills = 22,
// Release 1.7 biomes:
biJungleEdge = 23,
biDeepOcean = 24,
@ -68,14 +68,14 @@ enum EMCSBiome
biMesa = 37,
biMesaPlateauF = 38,
biMesaPlateau = 39,
// Automatically capture the maximum consecutive biome value into biMaxBiome:
biNumBiomes, // True number of biomes, since they are zero-based
biMaxBiome = biNumBiomes - 1, // The maximum biome value
// Add this number to the biomes to get the variant
biVariant = 128,
// Release 1.7 biome variants:
biFirstVariantBiome = 129,
biSunflowerPlains = 129,

View File

@ -146,7 +146,7 @@ void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE
}
return;
}
// Water and lava are never overwritten
switch (a_DstType)
{
@ -158,7 +158,7 @@ void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE
return;
}
}
// Water and lava always overwrite
switch (a_SrcType)
{
@ -175,7 +175,7 @@ void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE
return;
}
}
if (a_SrcType == E_BLOCK_STONE)
{
switch (a_DstType)
@ -342,7 +342,7 @@ void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
{
LOGWARNING("Creating a cBlockArea with height larger than world height (%d). Continuing, but the area may misbehave.", a_SizeY);
}
Clear();
int BlockCount = a_SizeX * a_SizeY * a_SizeZ;
if ((a_DataTypes & baTypes) != 0)
@ -445,12 +445,12 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB
{
std::swap(a_MinBlockZ, a_MaxBlockZ);
}
// Include the Max coords:
a_MaxBlockX += 1;
a_MaxBlockY += 1;
a_MaxBlockZ += 1;
// Check coords validity:
if (a_MinBlockY < 0)
{
@ -480,7 +480,7 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB
);
a_MaxBlockY = cChunkDef::Height;
}
// Allocate the needed memory:
Clear();
if (!SetSize(a_MaxBlockX - a_MinBlockX, a_MaxBlockY - a_MinBlockY, a_MaxBlockZ - a_MinBlockZ, a_DataTypes))
@ -489,20 +489,20 @@ bool cBlockArea::Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinB
}
m_Origin.Set(a_MinBlockX, a_MinBlockY, a_MinBlockZ);
cChunkReader Reader(*this);
// Convert block coords to chunks coords:
int MinChunkX, MaxChunkX;
int MinChunkZ, MaxChunkZ;
cChunkDef::AbsoluteToRelative(a_MinBlockX, a_MinBlockY, a_MinBlockZ, MinChunkX, MinChunkZ);
cChunkDef::AbsoluteToRelative(a_MaxBlockX, a_MaxBlockY, a_MaxBlockZ, MaxChunkX, MaxChunkZ);
// Query block data:
if (!a_ForEachChunkProvider->ForEachChunkInRect(MinChunkX, MaxChunkX, MinChunkZ, MaxChunkZ, Reader))
{
Clear();
return false;
}
return true;
}
@ -584,7 +584,7 @@ void cBlockArea::CopyTo(cBlockArea & a_Into) const
LOGWARNING("Trying to copy a cBlockArea into self, ignoring.");
return;
}
a_Into.Clear();
a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes());
a_Into.m_Origin = m_Origin;
@ -684,7 +684,7 @@ void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY
);
return;
}
if (HasBlockTypes())
{
CropBlockTypes(a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
@ -744,9 +744,9 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
const NIBBLETYPE * SrcMetas = a_Src.GetBlockMetas();
NIBBLETYPE * DstMetas = m_BlockMetas;
bool IsDummyMetas = ((SrcMetas == nullptr) || (DstMetas == nullptr));
if (IsDummyMetas)
{
MergeByStrategy<false>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas);
@ -779,7 +779,7 @@ void cBlockArea::Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_Block
);
a_DataTypes = a_DataTypes & GetDataTypes();
}
size_t BlockCount = GetBlockCount();
if ((a_DataTypes & baTypes) != 0)
{
@ -827,7 +827,7 @@ void cBlockArea::FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int
);
a_DataTypes = a_DataTypes & GetDataTypes();
}
if ((a_DataTypes & baTypes) != 0)
{
for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++)
@ -983,7 +983,7 @@ void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int
a_RelY1 += sy;
yd -= dz;
}
// move along z
a_RelZ1 += sz;
xd += dx;
@ -1019,14 +1019,14 @@ void cBlockArea::RotateCCW(void)
LOGWARNING("cBlockArea: Cannot rotate blockmeta without blocktypes!");
return;
}
if (!HasBlockMetas())
{
// There are no blockmetas to rotate, just use the NoMeta function
RotateCCWNoMeta();
return;
}
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
@ -1071,7 +1071,7 @@ void cBlockArea::RotateCW(void)
RotateCWNoMeta();
return;
}
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
BLOCKTYPE * NewTypes = new BLOCKTYPE[GetBlockCount()];
NIBBLETYPE * NewMetas = new NIBBLETYPE[GetBlockCount()];
@ -1109,7 +1109,7 @@ void cBlockArea::MirrorXY(void)
LOGWARNING("cBlockArea: Cannot mirror meta without blocktypes!");
return;
}
if (!HasBlockMetas())
{
// There are no blockmetas to mirror, just use the NoMeta function
@ -1329,7 +1329,7 @@ void cBlockArea::MirrorXYNoMeta(void)
} // for z
} // for y
} // if (HasBlockTypes)
if (HasBlockMetas())
{
for (int y = 0; y < m_Size.y; y++)
@ -1366,7 +1366,7 @@ void cBlockArea::MirrorXZNoMeta(void)
} // for z
} // for y
} // if (HasBlockTypes)
if (HasBlockMetas())
{
for (int y = 0; y < HalfY; y++)
@ -1403,7 +1403,7 @@ void cBlockArea::MirrorYZNoMeta(void)
} // for z
} // for y
} // if (HasBlockTypes)
if (HasBlockMetas())
{
for (int y = 0; y < m_Size.y; y++)
@ -1632,7 +1632,7 @@ void cBlockArea::GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTY
{
a_BlockType = m_BlockTypes[idx];
}
if (m_BlockMetas == nullptr)
{
LOGWARNING("cBlockArea: BlockMetas have not been read!");
@ -1834,7 +1834,7 @@ int cBlockArea::GetDataTypes(void) const
bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
{
ASSERT(m_BlockTypes == nullptr); // Has been cleared
if (a_DataTypes & baTypes)
{
m_BlockTypes = new BLOCKTYPE[a_SizeX * a_SizeY * a_SizeZ];
@ -1895,7 +1895,7 @@ int cBlockArea::MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const
ASSERT(a_RelY < m_Size.y);
ASSERT(a_RelZ >= 0);
ASSERT(a_RelZ < m_Size.z);
return a_RelX + a_RelZ * m_Size.x + a_RelY * m_Size.x * m_Size.z;
}
@ -1969,7 +1969,7 @@ void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLET
{
int SizeY = m_Area.m_Size.y;
int MinY = m_Origin.y;
// SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union)
// OffX, OffZ are the offsets of the current chunk data from the area origin
// BaseX, BaseZ are the offsets of the area data within the current chunk from the chunk borders
@ -2085,7 +2085,7 @@ void cBlockArea::cChunkReader::ChunkData(const cChunkData & a_BlockBuffer)
{
SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
}
// Copy the blocktypes:
if (m_Area.m_BlockTypes != nullptr)
{
@ -2323,7 +2323,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
LOGWARNING("%s: cannot merge because one of the areas doesn't have blocktypes.", __FUNCTION__);
return;
}
// Dst is *this, Src is a_Src
int SrcOffX = std::max(0, -a_RelX); // Offset in Src where to start reading
int DstOffX = std::max(0, a_RelX); // Offset in Dst where to start writing
@ -2336,7 +2336,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
int SrcOffZ = std::max(0, -a_RelZ); // Offset in Src where to start reading
int DstOffZ = std::max(0, a_RelZ); // Offset in Dst where to start writing
int SizeZ = std::min(a_Src.GetSizeZ() - SrcOffZ, GetSizeZ() - DstOffZ); // How many blocks to copy
switch (a_Strategy)
{
case cBlockArea::msOverwrite:
@ -2352,7 +2352,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
);
return;
} // case msOverwrite
case cBlockArea::msFillAir:
{
InternalMergeBlocks<MetasValid, MergeCombinatorFillAir<MetasValid> >(
@ -2366,7 +2366,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
);
return;
} // case msFillAir
case cBlockArea::msImprint:
{
InternalMergeBlocks<MetasValid, MergeCombinatorImprint<MetasValid> >(
@ -2380,7 +2380,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
);
return;
} // case msImprint
case cBlockArea::msLake:
{
InternalMergeBlocks<MetasValid, MergeCombinatorLake<MetasValid> >(
@ -2394,7 +2394,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
);
return;
} // case msLake
case cBlockArea::msSpongePrint:
{
InternalMergeBlocks<MetasValid, MergeCombinatorSpongePrint<MetasValid> >(
@ -2422,7 +2422,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
);
return;
} // case msDifference
case cBlockArea::msSimpleCompare:
{
InternalMergeBlocks<MetasValid, MergeCombinatorSimpleCompare<MetasValid> >(
@ -2436,7 +2436,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
);
return;
} // case msSimpleCompare
case cBlockArea::msMask:
{
InternalMergeBlocks<MetasValid, MergeCombinatorMask<MetasValid> >(
@ -2451,7 +2451,7 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel
return;
} // case msMask
} // switch (a_Strategy)
LOGWARNING("Unknown block area merge strategy: %d", a_Strategy);
ASSERT(!"Unknown block area merge strategy");
return;

View File

@ -32,7 +32,7 @@ class cBlockArea
// tolua_end
DISALLOW_COPY_AND_ASSIGN(cBlockArea);
// tolua_begin
public:
/** What data is to be queried (bit-mask) */
@ -43,7 +43,7 @@ public:
baLight = 4,
baSkyLight = 8,
} ;
/** The per-block strategy to use when merging another block area into this object.
See the Merge function for the description of these */
enum eMergeStrategy
@ -57,64 +57,64 @@ public:
msSimpleCompare,
msMask,
} ;
cBlockArea(void);
~cBlockArea();
/** Clears the data stored to reclaim memory */
void Clear(void);
/** Creates a new area of the specified size and contents.
Origin is set to all zeroes.
BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light.
*/
void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas);
/** Creates a new area of the specified size and contents.
Origin is set to all zeroes.
BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light.
*/
void Create(const Vector3i & a_Size, int a_DataTypes = baTypes | baMetas);
/** Resets the origin. No other changes are made, contents are untouched. */
void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ);
/** Resets the origin. No other changes are made, contents are untouched. */
void SetOrigin(const Vector3i & a_Origin);
/** Reads an area of blocks specified. Returns true if successful. All coords are inclusive. */
bool Read(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas);
/** Reads an area of blocks specified. Returns true if successful. The bounds are included in the read area. */
bool Read(cForEachChunkProvider * a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes = baTypes | baMetas);
/** Reads an area of blocks specified. Returns true if successful. The bounds are included in the read area. */
bool Read(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes = baTypes | baMetas);
// TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write
// A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again
/** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */
bool Write(cForEachChunkProvider * a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas);
/** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all */
bool Write(cForEachChunkProvider * a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes = baTypes | baMetas);
/** Copies this object's contents into the specified BlockArea. */
void CopyTo(cBlockArea & a_Into) const;
/** Copies the contents from the specified BlockArea into this object. */
void CopyFrom(const cBlockArea & a_From);
/** For testing purposes only, dumps the area into a file. */
void DumpToRawFile(const AString & a_FileName);
/** Crops the internal contents by the specified amount of blocks from each border. */
void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
/** Expands the internal contents by the specified amount of blocks from each border */
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
/** Merges another block area into this one, using the specified block combinating strategy
This function combines another BlockArea into the current object.
The strategy parameter specifies how individual blocks are combined together, using the table below.
@ -126,7 +126,7 @@ public:
| A | air | air | A | A |
| air | B | B | B | B |
| A | B | B | A | B |
So to sum up:
- msOverwrite completely overwrites all blocks with the Src's blocks
- msFillAir overwrites only those blocks that were air
@ -148,7 +148,7 @@ public:
| mycelium | stone | stone | ... and mycelium
| A | stone | A | ... but nothing else
| A | * | A | Everything else is left as it is
msSpongePrint:
Used for most generators, it allows carving out air pockets, too, and uses the Sponge as the NOP block
| area block | |
@ -156,7 +156,7 @@ public:
+----------+--------+--------+
| A | sponge | A | Sponge is the NOP block
| * | B | B | Everything else overwrites anything
msDifference:
Used to determine the differences between two areas. Only the differring blocks are preserved:
| area block | |
@ -183,68 +183,68 @@ public:
*/
void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy);
/** Merges another block area into this one, using the specified block combinating strategy.
See Merge() above for details. */
void Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy);
/** Fills the entire block area with the specified data */
void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f);
/** Fills a cuboid inside the block area with the specified data */
void FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ,
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
);
/** Fills a cuboid inside the block area with the specified data. a_Cuboid must be sorted. */
void FillRelCuboid(const cCuboid & a_RelCuboid,
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
);
/** Draws a line from between two points with the specified data */
void RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2,
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
);
/** Draws a line from between two points with the specified data */
void RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2,
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
);
/** Rotates the entire area counter-clockwise around the Y axis */
void RotateCCW(void);
/** Rotates the entire area clockwise around the Y axis */
void RotateCW(void);
/** Mirrors the entire area around the XY plane */
void MirrorXY(void);
/** Mirrors the entire area around the XZ plane */
void MirrorXZ(void);
/** Mirrors the entire area around the YZ plane */
void MirrorYZ(void);
/** Rotates the entire area counter-clockwise around the Y axis, doesn't use blockhandlers for block meta */
void RotateCCWNoMeta(void);
/** Rotates the entire area clockwise around the Y axis, doesn't use blockhandlers for block meta */
void RotateCWNoMeta(void);
/** Mirrors the entire area around the XY plane, doesn't use blockhandlers for block meta */
void MirrorXYNoMeta(void);
/** Mirrors the entire area around the XZ plane, doesn't use blockhandlers for block meta */
void MirrorXZNoMeta(void);
/** Mirrors the entire area around the YZ plane, doesn't use blockhandlers for block meta */
void MirrorYZNoMeta(void);
// Setters:
void SetRelBlockType (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType);
void SetBlockType (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType);
@ -270,35 +270,35 @@ public:
void SetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
// tolua_end
// These need manual exporting, tolua generates the binding as requiring 2 extra input params
void GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
// GetSize() is already exported manually to return 3 numbers, can't auto-export
const Vector3i & GetSize(void) const { return m_Size; }
// GetOrigin() is already exported manually to return 3 numbers, can't auto-export
const Vector3i & GetOrigin(void) const { return m_Origin; }
// tolua_begin
int GetSizeX(void) const { return m_Size.x; }
int GetSizeY(void) const { return m_Size.y; }
int GetSizeZ(void) const { return m_Size.z; }
/** Returns the volume of the area, as number of blocks */
int GetVolume(void) const { return m_Size.x * m_Size.y * m_Size.z; }
int GetOriginX(void) const { return m_Origin.x; }
int GetOriginY(void) const { return m_Origin.y; }
int GetOriginZ(void) const { return m_Origin.z; }
/** Returns the datatypes that are stored in the object (bitmask of baXXX values) */
int GetDataTypes(void) const;
bool HasBlockTypes (void) const { return (m_BlockTypes != nullptr); }
bool HasBlockMetas (void) const { return (m_BlockMetas != nullptr); }
bool HasBlockLights (void) const { return (m_BlockLight != nullptr); }
@ -323,7 +323,7 @@ public:
If there are no non-ignored blocks within the area, or blocktypes are not present, the returned values are reverse-ranges (MinX <- m_RangeX, MaxX <- 0 etc.)
Exported to Lua in ManualBindings.cpp. */
void GetNonAirCropRelCoords(int & a_MinRelX, int & a_MinRelY, int & a_MinRelZ, int & a_MaxRelX, int & a_MaxRelY, int & a_MaxRelZ, BLOCKTYPE a_IgnoreBlockType = E_BLOCK_AIR);
// Clients can use these for faster access to all blocktypes. Be careful though!
/** Returns the internal pointer to the block types */
BLOCKTYPE * GetBlockTypes (void) const { return m_BlockTypes; }
@ -336,32 +336,32 @@ public:
protected:
friend class cChunkDesc;
friend class cSchematicFileSerializer;
class cChunkReader :
public cChunkDataCallback
{
public:
cChunkReader(cBlockArea & a_Area);
protected:
cBlockArea & m_Area;
Vector3i m_Origin;
int m_CurrentChunkX;
int m_CurrentChunkZ;
void CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc);
// cChunkDataCallback overrides:
virtual bool Coords(int a_ChunkX, int a_ChunkZ) override;
virtual void ChunkData(const cChunkData & a_BlockTypes) override;
} ;
typedef NIBBLETYPE * NIBBLEARRAY;
Vector3i m_Origin;
Vector3i m_Size;
/** An extra data value sometimes stored in the .schematic file. Used mainly by the WorldEdit plugin.
cBlockArea doesn't use this value in any way. */
Vector3i m_WEOffset;
@ -370,10 +370,10 @@ protected:
NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access
NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access
NIBBLETYPE * m_BlockSkyLight; // Each light value is stored as a separate byte for faster access
/** Clears the data stored and prepares a fresh new block area with the specified dimensions */
bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes);
// Basic Setters:
void SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array);
void SetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array);
@ -381,11 +381,11 @@ protected:
// Basic Getters:
NIBBLETYPE GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE * a_Array) const;
NIBBLETYPE GetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const;
// Crop helpers:
void CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
void CropNibbles (NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
// Expand helpers:
void ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
void ExpandNibbles (NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
@ -396,7 +396,7 @@ protected:
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
);
template <bool MetasValid>
void MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE * SrcMetas, NIBBLETYPE * DstMetas);
// tolua_begin

View File

@ -53,21 +53,21 @@ protected:
public:
// tolua_end
virtual ~cBlockEntity() {} // force a virtual destructor in all descendants
virtual void Destroy(void) {}
void SetWorld(cWorld * a_World)
{
m_World = a_World;
}
/** Creates a new block entity for the specified block type
If a_World is valid, then the entity is created bound to that world
Returns nullptr for unknown block types. */
static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World = nullptr);
static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
{
return "cBlockEntity";
@ -81,9 +81,9 @@ public:
/** Returns the name of the parent class, or empty string if no parent class. */
virtual const char * GetParentClass(void) const { return ""; }
// tolua_begin
// Position, in absolute block coordinates:
Vector3i GetPos(void) const { return Vector3i{m_PosX, m_PosY, m_PosZ}; }
int GetPosX(void) const { return m_PosX; }
@ -91,25 +91,25 @@ public:
int GetPosZ(void) const { return m_PosZ; }
BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
cWorld * GetWorld(void) const { return m_World; }
int GetChunkX(void) const { return FAST_FLOOR_DIV(m_PosX, cChunkDef::Width); }
int GetChunkZ(void) const { return FAST_FLOOR_DIV(m_PosZ, cChunkDef::Width); }
int GetRelX(void) const { return m_RelX; }
int GetRelZ(void) const { return m_RelZ; }
// tolua_end
/** Called when a player uses this entity; should open the UI window.
returns true if the use was successful, return false to use the block as a "normal" block */
virtual bool UsedBy( cPlayer * a_Player) = 0;
/** Sends the packet defining the block entity to the client specified.
To send to all eligible clients, use cWorld::BroadcastBlockEntity() */
virtual void SendTo(cClientHandle & a_Client) = 0;
/** Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. */
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
@ -120,12 +120,12 @@ public:
protected:
/** Position in absolute block coordinates */
int m_PosX, m_PosY, m_PosZ;
/** Position relative to the chunk, used to speed up ticking */
int m_RelX, m_RelZ;
BLOCKTYPE m_BlockType;
cWorld * m_World;
} ; // tolua_export

View File

@ -30,9 +30,9 @@ class cBlockEntityWithItems :
public:
// tolua_end
BLOCKENTITY_PROTODEF(cBlockEntityWithItems)
cBlockEntityWithItems(
BLOCKTYPE a_BlockType, // Type of the block that the entity represents
int a_BlockX, int a_BlockY, int a_BlockZ, // Position of the block entity
@ -45,7 +45,7 @@ public:
{
m_Contents.AddListener(*this);
}
virtual void Destroy(void) override
{
// Drop the contents as pickups:
@ -55,12 +55,12 @@ public:
m_Contents.Clear();
m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); // Spawn in centre of block
}
// tolua_begin
const cItem & GetSlot(int a_SlotNum) const { return m_Contents.GetSlot(a_SlotNum); }
const cItem & GetSlot(int a_X, int a_Y) const { return m_Contents.GetSlot(a_X, a_Y); }
void SetSlot(int a_SlotNum, const cItem & a_Item) { m_Contents.SetSlot(a_SlotNum, a_Item); }
void SetSlot(int a_X, int a_Y, const cItem & a_Item) { m_Contents.SetSlot(a_X, a_Y, a_Item); }
@ -68,13 +68,13 @@ public:
cItemGrid & GetContents(void) { return m_Contents; }
// tolua_end
/** Const version of the GetContents() function for C++ type-safety */
const cItemGrid & GetContents(void) const { return m_Contents; }
protected:
cItemGrid m_Contents;
// cItemGrid::cListener overrides:
virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override
{

View File

@ -18,27 +18,27 @@ class cChestEntity :
public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
public:
enum
{
ContentsHeight = 3,
ContentsWidth = 9,
} ;
// tolua_end
BLOCKENTITY_PROTODEF(cChestEntity)
/** Constructor used for normal operation */
cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, BLOCKTYPE a_Type);
virtual ~cChestEntity();
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool UsedBy(cPlayer * a_Player) override;
/** Opens a new chest window for this chest.
Scans for neighbors to open a double chest window, if appropriate. */
void OpenNewWindow(void);

View File

@ -120,7 +120,7 @@ bool cCommandBlockEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
return false;
}
m_ShouldExecute = false;
Execute();
return true;
@ -142,7 +142,7 @@ void cCommandBlockEntity::SendTo(cClientHandle & a_Client)
void cCommandBlockEntity::Execute()
{
ASSERT(m_World != nullptr); // Execute should not be called before the command block is attached to a world
if (!m_World->AreCommandBlocksEnabled())
{
return;

View File

@ -21,13 +21,13 @@ class cCommandBlockEntity :
public cBlockEntity
{
typedef cBlockEntity super;
public:
// tolua_end
BLOCKENTITY_PROTODEF(cCommandBlockEntity)
/** Creates a new empty command block entity */
cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
@ -43,7 +43,7 @@ public:
/** Sets the command block to execute a command in the next tick */
void Activate(void);
/** Sets the command */
void SetCommand(const AString & a_Cmd);
@ -55,9 +55,9 @@ public:
/** Retrieves the result (signal strength) of the last operation */
NIBBLETYPE GetResult(void) const;
// tolua_end
private:
/** Executes the associated command */

View File

@ -18,19 +18,19 @@ public:
// tolua_end
BLOCKENTITY_PROTODEF(cDispenserEntity)
/** Constructor used for normal operation */
cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
// tolua_begin
/** Spawns a projectile of the given kind in front of the dispenser with the specified speed.
Returns the UniqueID of the spawned projectile, or 0 on failure. */
UInt32 SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_Speed);
/** Returns a unit vector in the cardinal direction of where the dispenser is facing. */
Vector3d GetShootVector(NIBBLETYPE a_Meta);
// tolua_end
private:

View File

@ -71,19 +71,19 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk)
SlotsCnt++;
}
} // for i - m_Contents[]
if (SlotsCnt == 0)
{
// Nothing in the dropspenser, play the click sound
m_World->BroadcastSoundEffect("random.click", static_cast<double>(m_PosX), static_cast<double>(m_PosY), static_cast<double>(m_PosZ), 1.0f, 1.2f);
return;
}
int RandomSlot = m_World->GetTickRandomNumber(SlotsCnt - 1);
// DropSpense the item, using the specialized behavior in the subclasses:
DropSpenseFromSlot(a_Chunk, OccupiedSlots[RandomSlot]);
// Broadcast a smoke and click effects:
NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ);
int SmokeDir = 0;
@ -120,7 +120,7 @@ bool cDropSpenserEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
return false;
}
m_ShouldDropSpense = false;
DropSpense(a_Chunk);
return true;
@ -148,7 +148,7 @@ bool cDropSpenserEntity::UsedBy(cPlayer * a_Player)
OpenWindow(new cDropSpenserWindow(m_PosX, m_PosY, m_PosZ, this));
Window = GetWindow();
}
if (Window != nullptr)
{
if (a_Player->GetWindow() != Window)

View File

@ -34,38 +34,38 @@ public:
ContentsHeight = 3,
ContentsWidth = 3,
} ;
// tolua_end
BLOCKENTITY_PROTODEF(cDropSpenserEntity)
cDropSpenserEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cDropSpenserEntity();
// cBlockEntity overrides:
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool UsedBy(cPlayer * a_Player) override;
// tolua_begin
/** Modifies the block coords to match the dropspenser direction given (where the dropspensed pickups should materialize) */
void AddDropSpenserDir(int & a_BlockX, int & a_BlockY, int & a_BlockZ, NIBBLETYPE a_Direction);
/** Sets the dropspenser to dropspense an item in the next tick */
void Activate(void);
// tolua_end
protected:
bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick
/** Does the actual work on dropspensing an item. Chooses the slot, calls DropSpenseFromSlot() and handles smoke / sound effects */
void DropSpense(cChunk & a_Chunk);
/** Override this function to provide the specific behavior for item dropspensing (drop / shoot / pour / ...) */
virtual void DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) = 0;
/** Helper function, drops one item from the specified slot (like a dropper) */
void DropFromSlot(cChunk & a_Chunk, int a_SlotNum);
} ; // tolua_export

View File

@ -20,20 +20,20 @@ class cDropperEntity :
public cDropSpenserEntity
{
typedef cDropSpenserEntity super;
public:
// tolua_end
BLOCKENTITY_PROTODEF(cDropperEntity)
/** Constructor used for normal operation */
cDropperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
protected:
// cDropSpenserEntity overrides:
virtual void DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) override;
/** Takes an item from slot a_SlotNum and puts it into the container in front of the dropper.
Called when there's a container directly in front of the dropper,
so the dropper should store items there, rather than dropping. */

View File

@ -14,12 +14,12 @@ class cEnderChestEntity :
public cBlockEntityWindowOwner
{
typedef cBlockEntity super;
public:
// tolua_end
BLOCKENTITY_PROTODEF(cEnderChestEntity)
cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cEnderChestEntity();
@ -29,7 +29,7 @@ public:
static void LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid);
static void SaveToJson(Json::Value & a_Value, const cItemGrid & a_Grid);
/** Opens a new enderchest window for this enderchest */
void OpenNewWindow(void);
} ; // tolua_export

View File

@ -21,31 +21,31 @@ class cFlowerPotEntity :
public cBlockEntity
{
typedef cBlockEntity super;
public:
// tolua_end
BLOCKENTITY_PROTODEF(cFlowerPotEntity)
/** Creates a new flowerpot entity at the specified block coords. a_World may be nullptr */
cFlowerPotEntity(int a_BlocX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual void Destroy(void) override;
// tolua_begin
/** Is a flower in the pot? */
bool IsItemInPot(void) { return !m_Item.IsEmpty(); }
/** Get the item in the flower pot */
cItem GetItem(void) const { return m_Item; }
/** Set the item in the flower pot */
void SetItem(const cItem & a_Item) { m_Item = a_Item; }
// tolua_end
/** Called when the player is using the entity; returns true if it was a successful use, return false if it should be treated as a normal block */
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;

View File

@ -365,7 +365,7 @@ void cFurnaceEntity::UpdateProgressBars(bool a_ForceUpdate)
int CurFuel = (m_FuelBurnTime > 0) ? 200 - (200 * m_TimeBurned / m_FuelBurnTime) : 0;
BroadcastProgress(PROGRESSBAR_FUEL, static_cast<short>(CurFuel));
int CurCook = (m_NeedCookTime > 0) ? (200 * m_TimeCooked / m_NeedCookTime) : 0;
BroadcastProgress(PROGRESSBAR_SMELTING_CONFIRM, 200); // Post 1.8, Mojang requires a random packet with an ID of three and value of 200. Wat. Wat. Wat.
BroadcastProgress(PROGRESSBAR_SMELTING, static_cast<short>(CurCook));

View File

@ -19,25 +19,25 @@ class cFurnaceEntity :
public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
public:
enum
{
fsInput = 0, // Input slot number
fsFuel = 1, // Fuel slot number
fsOutput = 2, // Output slot number
ContentsWidth = 3,
ContentsHeight = 1,
};
// tolua_end
BLOCKENTITY_PROTODEF(cFurnaceEntity)
/** Constructor used for normal operation */
cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cWorld * a_World);
virtual ~cFurnaceEntity();
// cBlockEntity overrides:
@ -54,41 +54,41 @@ public:
Used after the furnace is loaded from storage to set up the internal variables so that cooking continues, if it was active
Returns true if cooking */
bool ContinueCooking(void);
// tolua_begin
/** Returns the item in the input slot */
const cItem & GetInputSlot(void) const { return GetSlot(fsInput); }
/** Returns the item in the fuel slot */
const cItem & GetFuelSlot(void) const { return GetSlot(fsFuel); }
/** Returns the item in the output slot */
const cItem & GetOutputSlot(void) const { return GetSlot(fsOutput); }
/** Sets the item in the input slot */
void SetInputSlot(const cItem & a_Item) { SetSlot(fsInput, a_Item); }
/** Sets the item in the fuel slot */
void SetFuelSlot(const cItem & a_Item) { SetSlot(fsFuel, a_Item); }
/** Sets the item in the output slot */
void SetOutputSlot(const cItem & a_Item) { SetSlot(fsOutput, a_Item); }
/** Returns the time that the current item has been cooking, in ticks */
int GetTimeCooked(void) const { return m_TimeCooked; }
/** Returns the time until the current item finishes cooking, in ticks */
int GetCookTimeLeft(void) const { return m_NeedCookTime - m_TimeCooked; }
/** Returns the time until the current fuel is depleted, in ticks */
int GetFuelBurnTimeLeft(void) const { return m_FuelBurnTime - m_TimeBurned; }
/** Returns true if there's time left before the current fuel is depleted */
bool HasFuelTimeLeft(void) const { return (GetFuelBurnTimeLeft() > 0); }
// tolua_end
void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned)
{
m_FuelBurnTime = a_FuelBurnTime;
@ -100,29 +100,29 @@ public:
m_NeedCookTime = a_NeedCookTime;
m_TimeCooked = a_TimeCooked;
}
void SetLoading(bool a_IsLoading)
{
m_IsLoading = a_IsLoading;
}
protected:
/** Block meta of the block currently represented by this entity */
NIBBLETYPE m_BlockMeta;
/** The recipe for the current input slot */
const cFurnaceRecipe::cRecipe * m_CurrentRecipe;
/** The item that is being smelted */
cItem m_LastInput;
/** Set to true when the furnace entity has been destroyed to prevent the block being set again */
bool m_IsDestroyed;
/** Set to true if the furnace is cooking an item */
bool m_IsCooking;
/** Amount of ticks needed to fully cook current item */
int m_NeedCookTime;
@ -137,37 +137,37 @@ protected:
/** Is the block currently being loaded into the world? */
bool m_IsLoading;
/** Sends the specified progressbar value to all clients of the window */
void BroadcastProgress(short a_ProgressbarID, short a_Value);
/** One item finished cooking */
void FinishOne();
/** Starts burning a new fuel, if possible */
void BurnNewFuel(void);
/** Updates the recipe, based on the current input */
void UpdateInput(void);
/** Called when the fuel slot changes or when the fuel is spent, burns another piece of fuel if appropriate */
void UpdateFuel(void);
/** Called when the output slot changes */
void UpdateOutput(void);
/** Returns true if the input can be cooked into output and the item counts allow for another cooking operation */
bool CanCookInputToOutput(void) const;
/** Broadcasts progressbar updates, if needed */
void UpdateProgressBars(bool a_ForceUpdate = false);
/** Sets the m_IsCooking variable, updates the furnace block type based on the value */
void SetIsCooking(bool a_IsCooking);
// cItemGrid::cListener overrides:
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
} ; // tolua_export

View File

@ -30,17 +30,17 @@ public:
} ;
// tolua_end
BLOCKENTITY_PROTODEF(cHopperEntity)
/** Constructor used for normal operation */
cHopperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
/** Returns the block coords of the block receiving the output items, based on the meta
Returns false if unattached.
Exported in ManualBindings.cpp. */
bool GetOutputBlockPos(NIBBLETYPE a_BlockMeta, int & a_OutputX, int & a_OutputY, int & a_OutputZ);
protected:
Int64 m_LastMoveItemsInTick;
@ -50,37 +50,37 @@ protected:
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool UsedBy(cPlayer * a_Player) override;
/** Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. */
void OpenNewWindow(void);
/** Moves items from the container above it into this hopper. Returns true if the contents have changed. */
bool MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick);
/** Moves pickups from above this hopper into it. Returns true if the contents have changed. */
bool MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick);
/** Moves items out from this hopper into the destination. Returns true if the contents have changed. */
bool MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick);
/** Moves items from a chest (dblchest) above the hopper into this hopper. Returns true if contents have changed. */
bool MoveItemsFromChest(cChunk & a_Chunk);
/** Moves items from a furnace above the hopper into this hopper. Returns true if contents have changed. */
bool MoveItemsFromFurnace(cChunk & a_Chunk);
/** Moves items from the specified a_Entity's Contents into this hopper. Returns true if contents have changed. */
bool MoveItemsFromGrid(cBlockEntityWithItems & a_Entity);
/** Moves one piece from the specified itemstack into this hopper. Returns true if contents have changed. Doesn't change the itemstack. */
bool MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_SrcSlotNum);
/** Moves items to the chest at the specified coords. Returns true if contents have changed */
bool MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ);
/** Moves items to the furnace at the specified coords. Returns true if contents have changed */
bool MoveItemsToFurnace(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_HopperMeta);
/** Moves items to the specified ItemGrid. Returns true if contents have changed */
bool MoveItemsToGrid(cBlockEntityWithItems & a_Entity);

View File

@ -16,32 +16,32 @@ class cJukeboxEntity :
public:
// tolua_end
BLOCKENTITY_PROTODEF(cJukeboxEntity)
cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cJukeboxEntity();
// tolua_begin
int GetRecord(void);
void SetRecord(int a_Record);
/** Plays the specified Record. Return false if a_Record isn't a playable Record (E_ITEM_XXX_DISC).
If there is a record already playing, ejects it first. */
bool PlayRecord(int a_Record);
/** Ejects the currently held record as a pickup. Return false when no record had been inserted. */
bool EjectRecord(void);
/** Is in the Jukebox a Record? */
bool IsPlayingRecord(void);
static bool IsRecordItem(int a_Item)
{
return ((a_Item >= E_ITEM_FIRST_DISC) && (a_Item <= E_ITEM_LAST_DISC));
}
// tolua_end
virtual bool UsedBy(cPlayer * a_Player) override;

View File

@ -21,36 +21,36 @@ class cMobHeadEntity :
public cBlockEntity
{
typedef cBlockEntity super;
public:
// tolua_end
BLOCKENTITY_PROTODEF(cMobHeadEntity)
/** Creates a new mob head entity at the specified block coords. a_World may be nullptr */
cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
// tolua_begin
/** Set the type of the mob head */
void SetType(const eMobHeadType & a_SkullType);
/** Set the rotation of the mob head */
void SetRotation(eMobHeadRotation a_Rotation);
/** Set the player for mob heads with player type */
void SetOwner(const cPlayer & a_Owner);
/** Sets the player components for the mob heads with player type */
void SetOwner(const AString & a_OwnerUUID, const AString & a_OwnerName, const AString & a_OwnerTexture, const AString & a_OwnerTextureSignature);
/** Returns the type of the mob head */
eMobHeadType GetType(void) const { return m_Type; }
/** Returns the rotation of the mob head */
eMobHeadRotation GetRotation(void) const { return m_Rotation; }
/** Returns the player name of the mob head */
AString GetOwnerName(void) const { return m_OwnerName; }
@ -62,9 +62,9 @@ public:
/** Returns the texture signature of the mob head */
AString GetOwnerTextureSignature(void) const { return m_OwnerTextureSignature; }
// tolua_end
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;

View File

@ -24,7 +24,7 @@ class cMobSpawnerEntity :
public:
// tolua_end
cMobSpawnerEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual void SendTo(cClientHandle & a_Client) override;

View File

@ -35,7 +35,7 @@ void cNoteEntity::MakeSound(void)
{
char instrument;
AString sampleName;
switch (m_World->GetBlock(m_PosX, m_PosY - 1, m_PosZ))
{
case E_BLOCK_PLANKS:
@ -47,7 +47,7 @@ void cNoteEntity::MakeSound(void)
sampleName = "note.bassattack";
break;
}
case E_BLOCK_SAND:
case E_BLOCK_GRAVEL:
case E_BLOCK_SOULSAND:
@ -56,7 +56,7 @@ void cNoteEntity::MakeSound(void)
sampleName = "note.snare";
break;
}
case E_BLOCK_GLASS:
case E_BLOCK_GLASS_PANE:
case E_BLOCK_GLOWSTONE:
@ -89,7 +89,7 @@ void cNoteEntity::MakeSound(void)
}
m_World->BroadcastBlockAction(m_PosX, m_PosY, m_PosZ, static_cast<Byte>(instrument), static_cast<Byte>(m_Pitch), E_BLOCK_NOTE_BLOCK);
// TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all
float calcPitch = static_cast<float>(pow(2.0f, static_cast<float>(m_Pitch - 12.0f) / 12.0f));
m_World->BroadcastSoundEffect(

View File

@ -31,20 +31,20 @@ public:
// tolua_end
BLOCKENTITY_PROTODEF(cNoteEntity)
/** Creates a new note entity. a_World may be nullptr */
cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
virtual ~cNoteEntity() {}
// tolua_begin
char GetPitch(void);
void SetPitch(char a_Pitch);
void IncrementPitch(void);
void MakeSound(void);
// tolua_end
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {}

View File

@ -20,29 +20,29 @@ class cSignEntity :
public cBlockEntity
{
typedef cBlockEntity super;
public:
// tolua_end
BLOCKENTITY_PROTODEF(cSignEntity)
/** Creates a new empty sign entity at the specified block coords and block type (wall or standing). a_World may be nullptr */
cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World);
// tolua_begin
/** Sets all the sign's lines */
void SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
/** Sets individual line (zero-based index) */
void SetLine(int a_Index, const AString & a_Line);
/** Retrieves individual line (zero-based index) */
AString GetLine(int a_Index) const;
// tolua_end
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;

View File

@ -22,9 +22,9 @@ class cBlockIDMap
return (NoCaseCompare(a_Item1, a_Item2) > 0);
}
} ;
typedef std::map<AString, std::pair<short, short>, Comparator> ItemMap;
public:
static bool m_bHasRunInit;
@ -60,8 +60,8 @@ public:
AddToMap(Name, Value);
} // for i - Ini.Values[]
}
int Resolve(const AString & a_ItemName)
{
ItemMap::iterator itr = m_Map.find(a_ItemName);
@ -71,8 +71,8 @@ public:
}
return itr->second.first;
}
bool ResolveItem(const AString & a_ItemName, cItem & a_Item)
{
// Split into parts divided by either ':' or '^'
@ -102,7 +102,7 @@ public:
return false;
}
}
// Parse the damage, if present:
if (Split.size() < 2)
{
@ -119,8 +119,8 @@ public:
a_Item.m_ItemCount = 1;
return true;
}
AString Desolve(short a_ItemType, short a_ItemDamage)
{
// First try an exact match, both ItemType and ItemDamage ("birchplanks=5:2"):
@ -131,7 +131,7 @@ public:
return itr->first;
}
} // for itr - m_Map[]
// There is no exact match, try matching ItemType only ("planks=5"):
if (a_ItemDamage == 0)
{
@ -156,12 +156,12 @@ public:
}
return res;
}
protected:
ItemMap m_Map;
void AddToMap(const AString & a_Name, const AString & a_Value)
{
AStringVector Split = StringSplit(a_Value, ":");
@ -224,7 +224,7 @@ int BlockStringToType(const AString & a_BlockTypeString)
// It was a valid number, return that
return res;
}
if (!gsBlockIDMap.m_bHasRunInit)
{
gsBlockIDMap.init();
@ -300,7 +300,7 @@ eDimension StringToDimension(const AString & a_DimensionString)
// It was a valid number
return static_cast<eDimension>(res);
}
// Decode using a built-in map:
static struct
{
@ -323,7 +323,7 @@ eDimension StringToDimension(const AString & a_DimensionString)
return DimensionMap[i].m_Dimension;
}
} // for i - DimensionMap[]
// Not found
LOGWARNING("Unknown dimension: \"%s\". Setting to Overworld", a_DimensionString.c_str());
return dimOverworld;
@ -389,7 +389,7 @@ AString DamageTypeToString(eDamageType a_DamageType)
case dtSuffocating: return "dtSuffocation";
case dtExplosion: return "dtExplosion";
}
// Unknown damage type:
ASSERT(!"Unknown DamageType");
return Printf("dtUnknown_%d", static_cast<int>(a_DamageType));
@ -410,7 +410,7 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString)
// It was a valid number
return static_cast<eDamageType>(res);
}
// Decode using a built-in map:
static struct
{
@ -467,7 +467,7 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString)
return DamageTypeMap[i].m_DamageType;
}
} // for i - DamageTypeMap[]
// Not found:
return static_cast<eDamageType>(-1);
}

View File

@ -163,7 +163,7 @@ enum BLOCKTYPE
E_BLOCK_TRAPPED_CHEST = 146,
E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE = 147,
E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE = 148,
E_BLOCK_INACTIVE_COMPARATOR = 149,
E_BLOCK_ACTIVE_COMPARATOR = 150,
E_BLOCK_DAYLIGHT_SENSOR = 151,
@ -174,7 +174,7 @@ enum BLOCKTYPE
E_BLOCK_QUARTZ_BLOCK = 155,
E_BLOCK_QUARTZ_STAIRS = 156,
E_BLOCK_ACTIVATOR_RAIL = 157,
E_BLOCK_DROPPER = 158,
E_BLOCK_STAINED_CLAY = 159,
E_BLOCK_STAINED_GLASS_PANE = 160,
@ -215,12 +215,12 @@ enum BLOCKTYPE
E_BLOCK_JUNGLE_DOOR = 195,
E_BLOCK_ACACIA_DOOR = 196,
E_BLOCK_DARK_OAK_DOOR = 197,
// Keep these two as the last values. Update the last block value when adding another block
// IsValidBlock() depends on this
E_BLOCK_NUMBER_OF_TYPES = E_BLOCK_DARK_OAK_DOOR + 1, ///< Number of individual (different) blocktypes
E_BLOCK_MAX_TYPE_ID = E_BLOCK_NUMBER_OF_TYPES - 1, ///< Maximum BlockType number used
// Synonym or ID compatibility
E_BLOCK_YELLOW_FLOWER = E_BLOCK_DANDELION,
E_BLOCK_RED_ROSE = E_BLOCK_FLOWER,
@ -244,7 +244,7 @@ enum ENUM_ITEM_ID
E_ITEM_EMPTY = -1,
E_ITEM_FIRST = 256, // First true item type
E_ITEM_IRON_SHOVEL = 256,
E_ITEM_IRON_PICKAXE = 257,
E_ITEM_IRON_AXE = 258,
@ -422,7 +422,7 @@ enum ENUM_ITEM_ID
E_ITEM_JUNGLE_DOOR = 429,
E_ITEM_ACACIA_DOOR = 430,
E_ITEM_DARK_OAK_DOOR = 431,
// Keep these two as the last values of the consecutive list, without a number - they will get their correct number assigned automagically by C++
// IsValidItem() depends on this!
E_ITEM_NUMBER_OF_CONSECUTIVE_TYPES, ///< Number of individual (different) consecutive itemtypes
@ -441,12 +441,12 @@ enum ENUM_ITEM_ID
E_ITEM_WARD_DISC = 2265,
E_ITEM_11_DISC = 2266,
E_ITEM_WAIT_DISC = 2267,
// Keep these two as the last values of the disc list, without a number - they will get their correct number assigned automagically by C++
// IsValidItem() depends on this!
E_ITEM_LAST_DISC_PLUS_ONE, ///< Useless, really, but needs to be present for the following value
E_ITEM_LAST_DISC = E_ITEM_LAST_DISC_PLUS_ONE - 1, ///< Maximum disc itemtype number used
E_ITEM_LAST = E_ITEM_LAST_DISC, ///< Maximum valid ItemType
};
@ -458,7 +458,7 @@ enum
{
// Please keep this list alpha-sorted by the blocktype / itemtype part
// then number-sorted for the same block / item
////////////////////////////////////////////////////////////////////////////////
// Block metas:
@ -516,19 +516,19 @@ enum
E_META_CARPET_GREEN = 13,
E_META_CARPET_RED = 14,
E_META_CARPET_BLACK = 15,
// E_BLOCK_CHEST metas:
E_META_CHEST_FACING_ZM = 2,
E_META_CHEST_FACING_ZP = 3,
E_META_CHEST_FACING_XM = 4,
E_META_CHEST_FACING_XP = 5,
// E_BLOCK_DIRT metas:
E_META_DIRT_NORMAL = 0,
E_META_DIRT_GRASSLESS = 1,
E_META_DIRT_COARSE = 1,
E_META_DIRT_PODZOL = 2,
// E_BLOCK_DISPENSER / E_BLOCK_DROPPER metas:
E_META_DROPSPENSER_FACING_YM = 0,
E_META_DROPSPENSER_FACING_YP = 1,
@ -549,7 +549,7 @@ enum
E_META_DOUBLE_STONE_SLAB_SMOOTH_STONE = 8,
E_META_DOUBLE_STONE_SLAB_SMOOTH_SANDSTONE = 9,
E_META_DOUBLE_STONE_SLAB_TILE_QUARTZ = 10,
// E_BLOCK_FLOWER metas:
E_META_FLOWER_POPPY = 0,
E_META_FLOWER_BLUE_ORCHID = 1,
@ -559,11 +559,11 @@ enum
E_META_FLOWER_WHITE_TULIP = 6,
E_META_FLOWER_PINK_TULIP = 7,
E_META_FLOWER_OXEYE_DAISY = 8,
// E_BLOCK_JUKEBOX metas:
E_META_JUKEBOX_OFF = 0,
E_META_JUKEBOX_ON = 1,
// E_BLOCK_HOPPER metas:
E_META_HOPPER_FACING_YM = 0,
E_META_HOPPER_UNATTACHED = 1, // Hopper doesn't move items up, there's no YP
@ -593,21 +593,21 @@ enum
E_META_NEWLEAVES_DARK_OAK_NO_DECAY = 5,
E_META_NEWLEAVES_ACACIA_CHECK_DECAY = 8,
E_META_NEWLEAVES_DARK_OAK_CHECK_DECAY = 9,
// E_BLOCK_LOG metas:
E_META_LOG_APPLE = 0,
E_META_LOG_CONIFER = 1,
E_META_LOG_BIRCH = 2,
E_META_LOG_JUNGLE = 3,
// E_BLOCK_NEW_LEAVES metas:
E_META_NEW_LEAVES_ACACIA_WOOD = 0,
E_META_NEW_LEAVES_DARK_OAK_WOOD = 1,
// E_BLOCK_NEW_LOG metas:
E_META_NEW_LOG_ACACIA_WOOD = 0,
E_META_NEW_LOG_DARK_OAK_WOOD = 1,
// E_BLOCK_PISTON metas:
E_META_PISTON_DOWN = 0,
E_META_PISTON_U = 1,
@ -629,12 +629,12 @@ enum
// E_BLOCK_(XXX_WEIGHTED)_PRESSURE_PLATE metas:
E_META_PRESSURE_PLATE_RAISED = 0,
E_META_PRESSURE_PLATE_DEPRESSED = 1,
// E_BLOCK_PRISMARINE_BLOCK metas:
E_META_PRISMARINE_BLOCK_ROUGH = 0,
E_META_PRISMARINE_BLOCK_BRICKS = 1,
E_META_PRISMARINE_BLOCK_DARK = 2,
// E_BLOCK_QUARTZ_BLOCK metas:
E_META_QUARTZ_NORMAL = 0,
E_META_QUARTZ_CHISELLED = 1,
@ -651,21 +651,21 @@ enum
E_META_RAIL_CURVED_ZP_XM = 7,
E_META_RAIL_CURVED_ZM_XM = 8,
E_META_RAIL_CURVED_ZM_XP = 9,
// E_BLOCK_RED_SANDSTONE metas:
E_META_RED_SANDSTONE_NORMAL = 0,
E_META_RED_SANDSTONE_ORNAMENT = 1,
E_META_RED_SANDSTONE_SMOOTH = 2,
// E_BLOCK_SAND metas:
E_META_SAND_NORMAL = 0,
E_META_SAND_RED = 1,
// E_BLOCK_SANDSTONE metas:
E_META_SANDSTONE_NORMAL = 0,
E_META_SANDSTONE_ORNAMENT = 1,
E_META_SANDSTONE_SMOOTH = 2,
// E_BLOCK_SAPLING metas (lowest 3 bits):
E_META_SAPLING_APPLE = 0,
E_META_SAPLING_CONIFER = 1,
@ -673,12 +673,12 @@ enum
E_META_SAPLING_JUNGLE = 3,
E_META_SAPLING_ACACIA = 4,
E_META_SAPLING_DARK_OAK = 5,
// E_BLOCK_SILVERFISH_EGG metas:
E_META_SILVERFISH_EGG_STONE = 0,
E_META_SILVERFISH_EGG_COBBLESTONE = 1,
E_META_SILVERFISH_EGG_STONE_BRICK = 2,
// E_BLOCK_SNOW metas:
E_META_SNOW_LAYER_ONE = 0,
E_META_SNOW_LAYER_TWO = 1,
@ -706,7 +706,7 @@ enum
E_META_STAINED_CLAY_GREEN = 13,
E_META_STAINED_CLAY_RED = 14,
E_META_STAINED_CLAY_BLACK = 15,
// E_BLOCK_STAINED_GLASS metas:
E_META_STAINED_GLASS_WHITE = 0,
E_META_STAINED_GLASS_ORANGE = 1,
@ -724,7 +724,7 @@ enum
E_META_STAINED_GLASS_GREEN = 13,
E_META_STAINED_GLASS_RED = 14,
E_META_STAINED_GLASS_BLACK = 15,
// E_BLOCK_STAINED_GLASS_PANE metas:
E_META_STAINED_GLASS_PANE_WHITE = 0,
E_META_STAINED_GLASS_PANE_ORANGE = 1,
@ -768,19 +768,19 @@ enum
E_META_STONE_SLAB_STONE_BRICK = 5,
E_META_STONE_SLAB_NETHER_BRICK = 6,
E_META_STONE_SLAB_QUARTZ = 7,
// E_BLOCK_STONE_BRICKS metas:
E_META_STONE_BRICK_NORMAL = 0,
E_META_STONE_BRICK_MOSSY = 1,
E_META_STONE_BRICK_CRACKED = 2,
E_META_STONE_BRICK_ORNAMENT = 3,
// E_BLOCK_TALL_GRASS metas:
E_META_TALL_GRASS_DEAD_SHRUB = 0,
E_META_TALL_GRASS_GRASS = 1,
E_META_TALL_GRASS_FERN = 2,
E_META_TALL_GRASS_BIOME = 3,
// E_BLOCK_TORCH, E_BLOCK_REDSTONE_TORCH_OFF, E_BLOCK_REDSTONE_TORCH_ON metas:
E_META_TORCH_EAST = 1, // east face of the block, pointing east
E_META_TORCH_WEST = 2,
@ -827,7 +827,7 @@ enum
E_META_WOODEN_DOUBLE_SLAB_JUNGLE = 3,
E_META_WOODEN_DOUBLE_SLAB_ACACIA = 4,
E_META_WOODEN_DOUBLE_SLAB_DARK_OAK = 5,
// E_BLOCK_WOODEN_SLAB metas:
E_META_WOODEN_SLAB_OAK = 0,
E_META_WOODEN_SLAB_SPRUCE = 1,
@ -854,10 +854,10 @@ enum
E_META_WOOL_GREEN = 13,
E_META_WOOL_RED = 14,
E_META_WOOL_BLACK = 15,
////////////////////////////////////////////////////////////////////////////////
// Item metas:
// E_ITEM_BANNER metas:
E_META_BANNER_BLACK = 0,
E_META_BANNER_RED = 1,
@ -875,11 +875,11 @@ enum
E_META_BANNER_MAGENTA = 13,
E_META_BANNER_ORANGE = 14,
E_META_BANNER_WHITE = 15,
// E_ITEM_COAL metas:
E_META_COAL_NORMAL = 0,
E_META_COAL_CHARCOAL = 1,
// E_ITEM_DYE metas:
E_META_DYE_BLACK = 0,
E_META_DYE_RED = 1,
@ -901,20 +901,20 @@ enum
// E_ITEM_GOLDEN_APPLE metas:
E_META_GOLDEN_APPLE_NORMAL = 0,
E_META_GOLDEN_APPLE_ENCHANTED = 1,
// E_ITEM_HEAD metas:
E_META_HEAD_SKELETON = 0,
E_META_HEAD_WITHER = 1,
E_META_HEAD_ZOMBIE = 2,
E_META_HEAD_PLAYER = 3,
E_META_HEAD_CREEPER = 4,
// E_ITEM_RAW_FISH metas:
E_META_RAW_FISH_FISH = 0,
E_META_RAW_FISH_SALMON = 1,
E_META_RAW_FISH_CLOWNFISH = 2,
E_META_RAW_FISH_PUFFERFISH = 3,
// E_ITEM_COOKED_FISH metas:
E_META_COOKED_FISH_FISH = 0,
E_META_COOKED_FISH_SALMON = 1,
@ -922,7 +922,7 @@ enum
// E_ITEM_MINECART_TRACKS metas:
E_META_TRACKS_X = 1,
E_META_TRACKS_Z = 0,
// E_ITEM_SPAWN_EGG metas:
// See also cMonster::eType, since monster type and spawn egg meta are the same
E_META_SPAWN_EGG_PICKUP = 1,
@ -1022,7 +1022,7 @@ enum eDamageType
dtEnderPearl, // Thrown an ender pearl, teleported by it
dtAdmin, // Damage applied by an admin command
dtExplosion, // Damage applied by an explosion
// Some common synonyms:
dtPawnAttack = dtAttack,
dtEntityAttack = dtAttack,

View File

@ -17,7 +17,7 @@ class cBlockInfo
public:
/** Returns the associated BlockInfo structure for the specified block type. */
/** This accessor makes sure that the cBlockInfo structures are properly initialized exactly once.
It does so by using the C++ singleton approximation - storing the actual singleton as the function's static variable.
It works only if it is called for the first time before the app spawns other threads. */

View File

@ -30,12 +30,12 @@ public:
public:
// Force a virtual destructor in descendants:
virtual ~cCallbacks() {}
/** Called on each block encountered along the path, including the first block (path start)
When this callback returns true, the tracing is aborted.
*/
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) = 0;
/** Called on each block encountered along the path, including the first block (path start), if chunk data is not loaded
When this callback returns true, the tracing is aborted.
*/
@ -47,7 +47,7 @@ public:
UNUSED(a_EntryFace);
return false;
}
/** Called when the path goes out of world, either below (a_BlockY < 0) or above (a_BlockY >= cChunkDef::Height)
The coords specify the exact point at which the path exited the world.
If this callback returns true, the tracing is aborted.
@ -61,7 +61,7 @@ public:
UNUSED(a_BlockZ);
return false;
}
/** Called when the path goes into the world, from either below (a_BlockY < 0) or above (a_BlockY >= cChunkDef::Height)
The coords specify the exact point at which the path entered the world.
If this callback returns true, the tracing is aborted.
@ -75,27 +75,27 @@ public:
UNUSED(a_BlockZ);
return false;
}
/** Called when the path is sure not to hit any more blocks.
Note that for some shapes this might never happen (line with constant Y)
*/
virtual void OnNoMoreHits(void) {}
/** Called when the block tracing walks into a chunk that is not allocated.
This usually means that the tracing is aborted.
*/
virtual void OnNoChunk(void) {}
} ;
/** Creates the BlockTracer parent with the specified callbacks */
cBlockTracer(cWorld & a_World, cCallbacks & a_Callbacks) :
m_World(&a_World),
m_Callbacks(&a_Callbacks)
{
}
/** Sets new world, returns the old one. Note that both need to be valid */
cWorld & SetWorld(cWorld & a_World)
{
@ -103,8 +103,8 @@ public:
m_World = &a_World;
return Old;
}
/** Sets new callbacks, returns the old ones. Note that both need to be valid */
cCallbacks & SetCallbacks(cCallbacks & a_NewCallbacks)
{
@ -112,11 +112,11 @@ public:
m_Callbacks = &a_NewCallbacks;
return Old;
}
protected:
/** The world upon which to operate */
cWorld * m_World;
/** The callback to use for reporting */
cCallbacks * m_Callbacks;
} ;

View File

@ -18,7 +18,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(E_BLOCK_ANVIL, 1, a_BlockMeta >> 2));
@ -30,7 +30,7 @@ public:
a_Player->OpenWindow(Window);
return true;
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,

View File

@ -21,7 +21,7 @@ public:
: cMetaRotator<cBlockHandler, 0x3, 0x02, 0x03, 0x00, 0x01, true>(a_BlockType)
{
}
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
@ -29,7 +29,7 @@ public:
{
return true;
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to zero

View File

@ -34,12 +34,12 @@ public:
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
NIBBLETYPE Meta = a_BlockMeta & 0x7;
if ((Meta == E_META_BIG_FLOWER_DOUBLE_TALL_GRASS) || (Meta == E_META_BIG_FLOWER_LARGE_FERN))
{
return;
}
a_Pickups.push_back(cItem(E_BLOCK_BIG_FLOWER, 1, Meta));
}
@ -50,7 +50,7 @@ public:
{
Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY - 1, a_BlockZ);
}
NIBBLETYPE FlowerMeta = Meta & 0x7;
if (!a_Player->IsGameModeCreative())
{

View File

@ -15,11 +15,11 @@ public:
: cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, true>(a_BlockType)
{
}
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
double x(a_BlockX);
double y(a_BlockY);
double z(a_BlockZ);
@ -53,7 +53,7 @@ public:
return true;
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to 0
@ -64,7 +64,7 @@ public:
{
return true;
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,

View File

@ -14,7 +14,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
@ -23,7 +23,7 @@ public:
{
return false;
}
if (Meta >= 5)
{
a_ChunkInterface.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);

View File

@ -22,7 +22,7 @@ public:
cBlockHandler(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -34,7 +34,7 @@ public:
a_BlockMeta = a_Player->GetEquippedItem().m_ItemDamage & 0x0f;
return true;
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(E_BLOCK_CARPET, 1, a_BlockMeta));

View File

@ -18,7 +18,7 @@ public:
: cMetaRotator<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -27,14 +27,14 @@ public:
) override
{
a_BlockType = m_BlockType;
// Is there a doublechest already next to this block?
if (!CanBeAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ))
{
// Yup, cannot form a triple-chest, refuse:
return false;
}
// Check if this forms a doublechest, if so, need to adjust the meta:
cBlockArea Area;
if (!Area.Read(&a_ChunkInterface, a_BlockX - 1, a_BlockX + 1, a_BlockY, a_BlockY, a_BlockZ - 1, a_BlockZ + 1))
@ -59,7 +59,7 @@ public:
a_BlockMeta = (yaw < 0) ? 4 : 5;
return true;
}
// Single chest, get meta from rotation only
a_BlockMeta = PlayerYawToMetaData(yaw);
return true;
@ -71,7 +71,7 @@ public:
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
return CanBeAt(a_ChunkInterface, BlockX, a_RelY, BlockZ);
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
{
cBlockArea Area;
@ -80,7 +80,7 @@ public:
// Cannot read the surroundings, probably at the edge of loaded chunks. Disallow.
return false;
}
int NumChestNeighbors = 0;
if (Area.GetRelBlockType(1, 0, 2) == m_BlockType)
{
@ -136,7 +136,7 @@ public:
}
return (NumChestNeighbors < 2);
}
/** Translates player yaw when placing a chest into the chest block metadata. Valid for single chests only */
static NIBBLETYPE PlayerYawToMetaData(double a_Yaw)
{
@ -163,7 +163,7 @@ public:
return 0x03;
}
}
/** If there's a chest in the a_Area in the specified coords, modifies its meta to a_NewMeta and returns true. */
bool CheckAndAdjustNeighbor(cChunkInterface & a_ChunkInterface, const cBlockArea & a_Area, int a_RelX, int a_RelZ, NIBBLETYPE a_NewMeta)
{

View File

@ -17,7 +17,7 @@ public:
: cMetaRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03, true>(a_BlockType)
{
}
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
@ -42,7 +42,7 @@ public:
{
return true;
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));

View File

@ -72,7 +72,7 @@ public:
}
}
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);

View File

@ -20,7 +20,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
if (a_BlockMeta == E_META_DIRT_COARSE)
@ -33,7 +33,7 @@ public:
a_Pickups.Add(E_BLOCK_DIRT, 1, E_META_DIRT_NORMAL);
}
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
if (m_BlockType != E_BLOCK_GRASS)
@ -50,21 +50,21 @@ public:
else if ((a_RelY < cChunkDef::Height - 1))
{
BLOCKTYPE above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
// Grass turns back to dirt when the block above is not transparent
if (!cBlockInfo::IsTransparent(above))
{
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL);
return;
}
NIBBLETYPE light = std::max(a_Chunk.GetBlockLight(a_RelX, a_RelY + 1, a_RelZ), a_Chunk.GetTimeAlteredLight(a_Chunk.GetSkyLight(a_RelX, a_RelY + 1, a_RelZ)));
// Source block is not bright enough to spread
if (light < 9)
{
return;
}
}
// Grass spreads to adjacent dirt blocks:
@ -74,7 +74,7 @@ public:
int OfsX = rand.NextInt(3) - 1; // [-1 .. 1]
int OfsY = rand.NextInt(5) - 3; // [-3 .. 1]
int OfsZ = rand.NextInt(3) - 1; // [-1 .. 1]
BLOCKTYPE DestBlock;
NIBBLETYPE DestMeta;
if (!cChunkDef::IsValidHeight(a_RelY + OfsY))

View File

@ -86,10 +86,10 @@ bool cBlockDoorHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterfac
void cBlockDoorHandler::OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
{
UNUSED(a_ChunkInterface);
a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
if (Meta & 0x8)
{
// Current block is top of the door

View File

@ -46,7 +46,7 @@ public:
{
return false;
}
a_BlockType = m_BlockType;
a_BlockMeta = PlayerYawToMetaData(a_Player->GetYaw());
return true;
@ -118,7 +118,7 @@ public:
{
// Vanilla refuses to place doors on transparent blocks, except top-half slabs and other doors
// We need to keep the door compatible with itself, otherwise the top half drops while the bottom half stays
// Doors can be placed on upside-down slabs
if (cBlockSlabHandler::IsAnySlabType(a_BlockType) && ((a_BlockMeta & 0x08) != 0))
{
@ -159,7 +159,7 @@ public:
inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw)
{
ASSERT((a_Yaw >= -180) && (a_Yaw < 180));
a_Yaw += 90 + 45;
if (a_Yaw > 360)
{

View File

@ -29,12 +29,12 @@ public:
) override
{
a_BlockType = m_BlockType;
// FIXME: Do not use cPiston class for dispenser placement!
a_BlockMeta = cBlockPistonHandler::RotationPitchToMetaData(a_Player->GetYaw(), a_Player->GetPitch());
return true;
}
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag. Lowest three bits are position. 0x08 == 1000

View File

@ -33,7 +33,7 @@ public:
a_BlockMeta = RotationToMetaData(a_Player->GetYaw());
return true;
}
static NIBBLETYPE RotationToMetaData(double a_Rotation)
{
a_Rotation += 90 + 45; // So its not aligned with axis

View File

@ -14,12 +14,12 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
return a_ChunkInterface.UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ);
}
virtual bool IsUseable() override
{
return true;

View File

@ -68,7 +68,7 @@ public:
inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw)
{
ASSERT((a_Yaw >= -180) && (a_Yaw < 180));
a_Yaw += 360 + 45;
if (a_Yaw > 360)
{

View File

@ -59,7 +59,7 @@ public:
{
return 0;
}
for (int newY = Y + 1; newY < cChunkDef::Height; newY++)
{
BLOCKTYPE Block = a_ChunkInterface.GetBlock(X, newY, Z);

View File

@ -11,24 +11,24 @@ class cBlockFluidHandler :
public cBlockHandler
{
typedef cBlockHandler super;
public:
cBlockFluidHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// No pickups
}
virtual bool DoesIgnoreBuildCollision(void) override
{
return true;
}
virtual void Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override
{
switch (m_BlockType)
@ -84,7 +84,7 @@ public:
super(a_BlockType)
{
}
/** Called to tick the block */
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
@ -97,7 +97,7 @@ public:
}
}
}
/** Tries to start a fire near the lava at given coords. Returns true if fire started. */
static bool TryStartFireNear(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk)
{
@ -106,7 +106,7 @@ public:
int x = (rnd % 3) - 1; // -1 .. 1
int y = ((rnd / 4) % 4) - 1; // -1 .. 2
int z = ((rnd / 16) % 3) - 1; // -1 .. 1
// Check if it's fuel:
BLOCKTYPE BlockType;
if (
@ -117,7 +117,7 @@ public:
{
return false;
}
// Try to set it on fire:
static struct
{

View File

@ -22,7 +22,7 @@ public:
{
a_Pickups.push_back(cItem(E_BLOCK_FURNACE, 1, 0));
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -31,10 +31,10 @@ public:
) override
{
a_BlockType = m_BlockType;
// FIXME: Do not use cPiston class for furnace placement!
a_BlockMeta = cBlockPistonHandler::RotationPitchToMetaData(a_Player->GetYaw(), 0);
return true;
}

View File

@ -136,7 +136,7 @@ public:
// CW rotation of a CCW rotation should produce no change in the meta
printf("Handler for blocktype %d (%s) fails CW(CCW) rotation test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta);
}
// Test the mirroring:
TestMeta = Handler->MetaMirrorXY(Handler->MetaMirrorXY(Meta));
if (TestMeta != Meta)
@ -156,7 +156,7 @@ public:
// Double-mirroring should produce the same meta:
printf("Handler for blocktype %d (%s) fails YZ mirror test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta);
}
// Test mirror-rotating:
TestMeta = Handler->MetaRotateCW(Handler->MetaRotateCW(Handler->MetaMirrorXY(Handler->MetaMirrorYZ(Meta))));
if (TestMeta != Meta)
@ -331,7 +331,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType)
case E_BLOCK_WOOL: return new cBlockClothHandler (a_BlockType);
case E_BLOCK_WORKBENCH: return new cBlockWorkbenchHandler (a_BlockType);
case E_BLOCK_YELLOW_FLOWER: return new cBlockFlowerHandler (a_BlockType);
default: return new cBlockHandler(a_BlockType);
}
}
@ -512,7 +512,7 @@ void cBlockHandler::DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterfac
// Allow plugins to modify the pickups:
a_BlockPluginInterface.CallHookBlockToPickups(a_Digger, a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta, Pickups);
if (!Pickups.empty())
{
MTRand r1;
@ -600,7 +600,7 @@ void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterf
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
DropBlock(a_ChunkInterface, *a_Chunk.GetWorld(), a_PluginInterface, nullptr, BlockX, a_RelY, BlockZ);
}
a_Chunk.SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0);
}
else

View File

@ -23,7 +23,7 @@ class cBlockHandler
{
public:
cBlockHandler(BLOCKTYPE a_BlockType);
virtual ~cBlockHandler() {}
/** Called when the block gets ticked either by a random tick or by a queued tick.
@ -43,71 +43,71 @@ public:
/** Called by cWorld::SetBlock() after the block has been set */
virtual void OnPlaced(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
/** Called by cPlayer::PlaceBlocks() for each block after it has been set to the world. Called after OnPlaced(). */
virtual void OnPlacedByPlayer(
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, const sSetBlock & a_BlockChange
);
/** Called before the player has destroyed a block */
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ);
/** Called before a block gets destroyed / replaced with air */
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ);
/** Called when a direct neighbor of this block has been changed (The position is the block's own position, not the changing neighbor's position)
a_WhichNeighbor indicates which neighbor has changed. For example, BLOCK_FACE_YP meant the neighbor above has changed.
BLOCK_FACE_NONE means that it is a neighbor not directly adjacent (diagonal, etc.) */
virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_WhichNeighbor) {}
/** Notifies the specified neighbor that the current block has changed.
a_NeighborXYZ coords are the coords of the neighbor
a_WhichNeighbor specifies which neighbor (relative to a_NeighborXYZ) has changed.
For example BLOCK_FACE_YP means that the block at {a_NeighborX, a_NeighborY + 1, a_NeighborZ} has changed.
BLOCK_FACE_NONE means that it is a neighbor not directly adjacent (diagonal, etc.) */
static void NeighborChanged(cChunkInterface & a_ChunkInterface, int a_NeighborX, int a_NeighborY, int a_NeighborZ, eBlockFace a_WhichNeighbor);
/** Called when the player starts digging the block. */
virtual void OnDigging(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) {}
/** Called if the user right clicks the block and the block is useable
returns true if the use was successful, return false to use the block as a "normal" block */
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) { return false; }
/** Called when a right click to this block is cancelled */
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) {}
/** Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents */
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta);
/** Handles the dropping, but not destruction, of a block based on what ConvertTo(Verbatim)Pickups() returns, including the spawning of pickups and alertion of plugins
@param a_Digger The entity causing the drop; it may be nullptr
@param a_CanDrop Informs the handler whether the block should be dropped at all. One example when this is false is when stone is destroyed by hand
@param a_DropVerbatim Calls ConvertToVerbatimPickups() instead of its counterpart, meaning the block itself is dropped by default (due to a speical tool or enchantment)
*/
virtual void DropBlock(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_BlockPluginInterface, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, bool a_CanDrop = true);
/** Checks if the block can stay at the specified relative coords in the chunk */
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk);
/** Checks whether the block has an effect on growing the plant */
virtual bool CanSustainPlant(BLOCKTYPE a_Plant) { return false; }
/** Checks if the block can be placed at this point.
Default: CanBeAt(...)
NOTE: This call doesn't actually place the block
*/
// virtual bool CanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir);
/** Called to check whether this block supports a rclk action.
If it returns true, OnUse() is called */
virtual bool IsUseable(void);
/** Indicates whether the client will click through this block.
For example digging a fire will hit the block below the fire so fire is clicked through
*/
virtual bool IsClickedThrough(void);
/** Checks if the player can build "inside" this block.
For example blocks placed "on" snow will be placed at the same position. So: Snow ignores Build collision
*/
@ -136,15 +136,15 @@ public:
/** Returns the base colour ID of the block, as will be represented on a map, as per documentation: http://minecraft.gamepedia.com/Map_item_format */
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta);
/** Rotates a given block meta counter-clockwise. Default: no change
Returns block meta following rotation */
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) { return a_Meta; }
/** Rotates a given block meta clockwise. Default: no change
Returns block meta following rotation */
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) { return a_Meta; }
/** Mirrors a given block meta around the XY plane. Default: no change
Returns block meta following rotation */
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) { return a_Meta; }
@ -156,10 +156,10 @@ public:
/** Mirros a given block meta around the YZ plane. Default: no change
Returns block meta following rotation */
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) { return a_Meta; }
protected:
BLOCKTYPE m_BlockType;
// Creates a new blockhandler for the given block type. For internal use only, use ::GetBlockHandler() instead.
static cBlockHandler * CreateBlockHandler(BLOCKTYPE a_BlockType);

View File

@ -24,7 +24,7 @@ public:
) override
{
a_BlockType = m_BlockType;
// Convert the blockface into meta:
switch (a_BlockFace)
{

View File

@ -21,14 +21,14 @@ public:
{
// No pickups
}
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
if (a_Player->IsGameModeCreative() || (a_BlockY <= 0))
{
return;
}
cEnchantments Enchantments = a_Player->GetInventory().GetEquippedItem().m_Enchantments;
if (Enchantments.GetLevel(cEnchantments::enchSilkTouch) == 0)
{

View File

@ -29,7 +29,7 @@ public:
if (!LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
{
a_BlockFace = FindSuitableBlockFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
if (a_BlockFace == BLOCK_FACE_BOTTOM)
{
return false;

View File

@ -82,7 +82,7 @@ public:
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x7);
}
}
virtual void OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
@ -159,7 +159,7 @@ bool HasNearLog(cBlockArea & a_Area, int a_BlockX, int a_BlockY, int a_BlockZ)
}
}
} // for i - Types[]
// Perform a breadth-first search to see if there's a log connected within 4 blocks of the leaves block:
// Simply replace all reachable leaves blocks with a sponge block plus iteration (in the Area) and see if we can reach a log in 4 iterations
a_Area.SetBlockType(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_SPONGE);

View File

@ -10,13 +10,13 @@ class cBlockLeverHandler :
public cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, false>
{
typedef cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, false> super;
public:
cBlockLeverHandler(BLOCKTYPE a_BlockType) :
super(a_BlockType)
{
}
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
// Flip the ON bit on / off using the XOR bitwise operation
@ -38,7 +38,7 @@ public:
{
return true;
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -93,7 +93,7 @@ public:
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
eBlockFace Face = BlockMetaDataToBlockFace(Meta);
AddFaceDirection(a_RelX, a_RelY, a_RelZ, Face, true);

View File

@ -15,7 +15,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
cFastRandom Random;

View File

@ -39,7 +39,7 @@ public:
return false;
}
cMobHeadEntity * MobHeadEntity = static_cast<cMobHeadEntity*>(a_BlockEntity);
cItems Pickups;
Pickups.Add(E_ITEM_HEAD, 1, static_cast<short>(MobHeadEntity->GetType()));
MTRand r1;
@ -58,7 +58,7 @@ public:
return false;
}
} Callback;
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
}

View File

@ -35,8 +35,8 @@ public:
{
// No pickups
}
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
cItemHandler * Handler = a_Player->GetEquippedItem().GetHandler();

View File

@ -30,9 +30,9 @@ public:
{
return false;
}
// TODO: Cannot be at too much daylight
switch (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ))
{
case E_BLOCK_GLASS:

View File

@ -14,7 +14,7 @@ class cBlockPistonHandler :
{
public:
cBlockPistonHandler(BLOCKTYPE a_BlockType);
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override;
@ -94,7 +94,7 @@ public:
}
private:
typedef std::unordered_set<Vector3i, VectorHasher<int>> Vector3iSet;
/** Returns true if the piston (specified by blocktype) is a sticky piston */
@ -153,7 +153,7 @@ private:
const Vector3i & a_BlockPos, cWorld * a_World, bool a_RequirePushable,
Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir
);
/** Moves a list of blocks in a specific direction */
static void PushBlocks(const Vector3iSet & a_BlocksToPush,
cWorld * a_World, const Vector3i & a_PushDir
@ -168,10 +168,10 @@ class cBlockPistonHeadHandler :
public cBlockHandler
{
typedef cBlockHandler super;
public:
cBlockPistonHeadHandler(void);
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override

View File

@ -14,7 +14,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,

View File

@ -28,7 +28,7 @@ class cBlockPluginInterface
{
public:
virtual ~cBlockPluginInterface() {}
virtual bool CallHookBlockSpread(int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) = 0;
virtual bool CallHookBlockToPickups(cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) = 0;
virtual bool CallHookPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;

View File

@ -112,7 +112,7 @@ public:
}
return true;
}
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);

View File

@ -15,7 +15,7 @@ public:
super(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -31,7 +31,7 @@ public:
inline static NIBBLETYPE PlayerYawToMetaData(double a_Yaw)
{
ASSERT((a_Yaw >= -180) && (a_Yaw < 180));
a_Yaw += 180 + 45;
if (a_Yaw > 360)
{

View File

@ -22,13 +22,13 @@ class cBlockRailHandler :
public cBlockHandler
{
typedef cBlockHandler super;
public:
cBlockRailHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -85,7 +85,7 @@ public:
{
super::ConvertToPickups(a_Pickups, 0);
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
if (a_RelY <= 0)
@ -279,7 +279,7 @@ public:
}
break;
}
case E_META_RAIL_XM_XP:
{
if (
@ -291,7 +291,7 @@ public:
}
break;
}
case E_META_RAIL_ASCEND_XP:
{
if (
@ -303,7 +303,7 @@ public:
}
break;
}
case E_META_RAIL_ASCEND_XM:
{
if (
@ -315,7 +315,7 @@ public:
}
break;
}
case E_META_RAIL_ASCEND_ZM:
{
if (
@ -327,7 +327,7 @@ public:
}
break;
}
case E_META_RAIL_ASCEND_ZP:
{
if (
@ -339,7 +339,7 @@ public:
}
break;
}
case E_META_RAIL_CURVED_ZP_XP:
{
if (
@ -351,7 +351,7 @@ public:
}
break;
}
case E_META_RAIL_CURVED_ZP_XM:
{
if (
@ -363,7 +363,7 @@ public:
}
break;
}
case E_META_RAIL_CURVED_ZM_XM:
{
if (
@ -375,7 +375,7 @@ public:
}
break;
}
case E_META_RAIL_CURVED_ZM_XP:
{
if (
@ -417,7 +417,7 @@ public:
{
Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
}
switch (a_BlockFace)
{
case BLOCK_FACE_NORTH:
@ -434,7 +434,7 @@ public:
}
break;
}
case BLOCK_FACE_SOUTH:
{
if (
@ -449,7 +449,7 @@ public:
}
break;
}
case BLOCK_FACE_EAST:
{
if (

View File

@ -43,7 +43,7 @@ public:
}
return false;
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Reset meta to zero

View File

@ -15,7 +15,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(E_BLOCK_REDSTONE_LAMP_OFF, 1, 0));

View File

@ -52,7 +52,7 @@ public:
{
return true;
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
if (a_RelY <= 0)

View File

@ -17,18 +17,18 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// Only the first 2 bits contain the display information and the 4th bit is for the growth indicator, but, we use 0x07 for forward compatibility
a_Pickups.push_back(cItem(E_BLOCK_SAPLING, 1, a_BlockMeta & 0x07));
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
return (a_RelY > 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ));
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);

View File

@ -15,7 +15,7 @@ public:
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,

View File

@ -13,7 +13,7 @@ class cBlockSignPostHandler :
public cBlockHandler
{
typedef cBlockHandler super;
public:
cBlockSignPostHandler(BLOCKTYPE a_BlockType) :
super(a_BlockType)
@ -43,9 +43,9 @@ public:
{
a_Rotation -= 360;
}
a_Rotation = (a_Rotation / 360) * 16;
return (static_cast<char>(a_Rotation)) % 16;
}

View File

@ -39,7 +39,7 @@ public:
{
a_BlockType = m_BlockType;
NIBBLETYPE Meta = static_cast<NIBBLETYPE>(a_Player->GetEquippedItem().m_ItemDamage);
// Set the correct metadata based on player equipped item (i.e. a_BlockMeta not initialised yet)
switch (a_BlockFace)
{
@ -84,7 +84,7 @@ public:
return true;
}
/** Returns true if the specified blocktype is one of the slabs handled by this handler */
static bool IsAnySlabType(BLOCKTYPE a_BlockType)
{
@ -101,7 +101,7 @@ public:
// Sends the slab back to the client. It's to refuse a doubleslab placement. */
a_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
/** Converts the single-slab blocktype to its equivalent double-slab blocktype */
static BLOCKTYPE GetDoubleSlabType(BLOCKTYPE a_SingleSlabBlockType)
{
@ -114,7 +114,7 @@ public:
ASSERT(!"Unhandled slab type!");
return E_BLOCK_AIR;
}
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
{
// Toggle the 4th bit - up / down:
@ -203,7 +203,7 @@ public:
BLOCKTYPE Block = GetSingleSlabType(m_BlockType);
a_Pickups.push_back(cItem(Block, 2, a_BlockMeta & 0x7));
}
inline static BLOCKTYPE GetSingleSlabType(BLOCKTYPE a_BlockType)
{
switch (a_BlockType)

View File

@ -14,7 +14,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(m_BlockType, 1, 0));

View File

@ -36,7 +36,7 @@ public:
// - Height is smaller than 7, the maximum possible height
MetaBeforePlacement++;
}
a_BlockMeta = MetaBeforePlacement;
return true;
}
@ -67,17 +67,17 @@ public:
{
BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
NIBBLETYPE MetaBelow = a_Chunk.GetMeta(a_RelX, a_RelY - 1, a_RelZ);
if (cBlockInfo::IsSnowable(BlockBelow) || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7)))
{
// If block below is snowable, or it is a thin slow block and has a meta of 7 (full thin snow block), say yay
return true;
}
}
return false;
}
virtual bool DoesDropOnUnsuitable(void) override
{
return false;

View File

@ -23,7 +23,7 @@ public:
short ItemType = (m_BlockType == E_BLOCK_MELON_STEM) ? E_ITEM_MELON_SEEDS : E_ITEM_PUMPKIN_SEEDS;
a_Pickups.push_back(cItem(ItemType, 1, 0));
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
auto Action = CanGrow(a_Chunk, a_RelX, a_RelY, a_RelZ);

View File

@ -71,7 +71,7 @@ public:
}
return false;
}
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
if (CanGrow(a_Chunk, a_RelX, a_RelY, a_RelZ) == paGrowth)

View File

@ -16,7 +16,7 @@ public:
: cMetaRotator<cBlockHandler, 0x7, 0x4, 0x1, 0x3, 0x2>(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -142,7 +142,7 @@ public:
}
}
}
/** Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure */
static eBlockFace FindSuitableFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
{

View File

@ -39,7 +39,7 @@ public:
// Flip the ON bit on / off using the XOR bitwise operation
NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04);
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
cWorld * World = static_cast<cWorld *>(&a_WorldInterface);
World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_DOOR_OPEN_CLOSE, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player->GetClientHandle());

View File

@ -14,7 +14,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
@ -117,18 +117,18 @@ public:
}
return res;
}
void Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) override
{
NIBBLETYPE CurMeta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
NIBBLETYPE MaxMeta = GetMaxMeta(a_Chunk, a_RelX, a_RelY, a_RelZ);
// Check if vine above us, add its meta to MaxMeta
if ((a_RelY < cChunkDef::Height - 1) && (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == m_BlockType))
{
MaxMeta |= a_Chunk.GetMeta(a_RelX, a_RelY + 1, a_RelZ);
}
NIBBLETYPE Common = CurMeta & MaxMeta; // Neighbors that we have and are legal
if (Common != CurMeta)
{

View File

@ -17,7 +17,7 @@ public:
: cBlockHandler(a_BlockType)
{
}
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
cWindow * Window = new cCraftingWindow(a_BlockX, a_BlockY, a_BlockZ);

View File

@ -5,7 +5,7 @@ class cBroadcastInterface
{
public:
virtual ~cBroadcastInterface() {}
virtual void BroadcastUseBed (const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
virtual void BroadcastSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = nullptr) = 0;
virtual void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = nullptr) = 0;

View File

@ -21,32 +21,32 @@ public:
NIBBLETYPE GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ);
bool GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
/** Sets the block at the specified coords to the specified value.
Full processing, incl. updating neighbors, is performed.
*/
void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData);
/** Sets the block at the specified coords to the specified value.
The replacement doesn't trigger block updates.
The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block)
*/
void FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
void FastSetBlock(const Vector3i & a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
/** Use block entity on coordinate.
returns true if the use was successful, return false to use the block as a "normal" block */
bool UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ);
virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override;
virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override;
bool DigBlock(cWorldInterface & a_WorldInterface, int a_X, int a_Y, int a_Z);
private:
cChunkMap * m_ChunkMap;
};

View File

@ -15,7 +15,7 @@ public:
cClearMetaOnDrop(BLOCKTYPE a_BlockType) :
Base(a_BlockType)
{}
virtual ~cClearMetaOnDrop() {}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{

Some files were not shown because too many files have changed in this diff Show More