diff options
Diffstat (limited to 'src')
82 files changed, 1880 insertions, 1565 deletions
diff --git a/src/Bindings/.gitignore b/src/Bindings/.gitignore index af8aa76fa..0d00dd578 100644 --- a/src/Bindings/.gitignore +++ b/src/Bindings/.gitignore @@ -1 +1,2 @@ lua51.dll +LuaState_Call.inc diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 7a5ed1425..32638df96 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -811,6 +811,18 @@ void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal) +{ + if (lua_isnumber(m_LuaState, a_StackPos)) + { + a_ReturnedVal = (eWeather)Clamp((int)tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal), (int)wSunny, (int)wThunderstorm); + } +} + + + + + bool cLuaState::CallFunction(int a_NumResults) { ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 066390e39..b1ac3578a 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -9,10 +9,11 @@ Owned lua_State is created by calling Create() and the cLuaState automatically c Or, lua_State can be attached by calling Attach(), the cLuaState doesn't close such a state Attaching a state will automatically close an owned state. -Calling a Lua function is done by pushing the function, either by PushFunction() or PushFunctionFromRegistry(), -then pushing the arguments (PushString(), PushNumber(), PushUserData() etc.) and finally -executing CallFunction(). cLuaState automatically keeps track of the number of arguments and the name of the -function (for logging purposes), which makes the call less error-prone. +Calling a Lua function is done internally by pushing the function using PushFunction(), then pushing the +arguments and finally executing CallFunction(). cLuaState automatically keeps track of the number of +arguments and the name of the function (for logging purposes). After the call the return values are read from +the stack using GetStackValue(). All of this is wrapped in a templated function overloads cLuaState::Call(), +which is generated automatically by gen_LuaState_Call.lua script file into the LuaState_Call.inc file. Reference management is provided by the cLuaState::cRef class. This is used when you need to hold a reference to any Lua object across several function calls; usually this is used for callbacks. The class is RAII-like, with @@ -30,6 +31,7 @@ extern "C" } #include "../Vector3.h" +#include "../Defines.h" @@ -222,625 +224,13 @@ public: /** Retrieve value at a_StackPos, if it is a valid number. If not, a_Value is unchanged */ void GetStackValue(int a_StackPos, double & a_Value); + /** Retrieve value at a_StackPos, if it is a valid number, converting and clamping it to eWeather. + If not, a_Value is unchanged. */ + void GetStackValue(int a_StackPos, eWeather & a_Value); + - /** Call any 0-param 0-return Lua function in a single line: */ - template <typename FnT> - bool Call(FnT a_FnName) - { - if (!PushFunction(a_FnName)) - { - return false; - } - return CallFunction(0); - } - - /** Call any 1-param 0-return Lua function in a single line: */ - template< - typename FnT, - typename ArgT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1) - { - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - return CallFunction(0); - } - - /** Call any 2-param 0-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2) - { - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - return CallFunction(0); - } - - /** Call any 3-param 0-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3) - { - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - return CallFunction(0); - } - - /** Call any 0-param 1-return Lua function in a single line: */ - template< - typename FnT, typename RetT1 - > - bool Call(FnT a_FnName, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 1-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1) - { - int InitialTop = lua_gettop(m_LuaState); - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - ASSERT(InitialTop == lua_gettop(m_LuaState)); - return true; - } - - /** Call any 2-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 3-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 4-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 5-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 6-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, - typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 7-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, - typename ArgT7, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 8-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, - typename ArgT7, typename ArgT8, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - Push(a_Arg8); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 9-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, - typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - Push(a_Arg8); - Push(a_Arg9); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 10-param 1-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6, - typename ArgT7, typename ArgT8, typename ArgT9, typename ArgT10, typename RetT1 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & a_Mark, RetT1 & a_Ret1) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - Push(a_Arg8); - Push(a_Arg9); - Push(a_Arg10); - if (!CallFunction(1)) - { - return false; - } - GetStackValue(-1, a_Ret1); - lua_pop(m_LuaState, 1); - return true; - } - - /** Call any 1-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 2-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 3-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, - typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 4-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, - typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 5-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, - typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 6-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, - typename ArgT6, - typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 7-param 2-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, - typename ArgT6, typename ArgT7, - typename RetT1, typename RetT2 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - if (!CallFunction(2)) - { - return false; - } - GetStackValue(-2, a_Ret1); - GetStackValue(-1, a_Ret2); - lua_pop(m_LuaState, 2); - return true; - } - - /** Call any 7-param 3-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, - typename ArgT6, typename ArgT7, - typename RetT1, typename RetT2, typename RetT3 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - if (!CallFunction(3)) - { - return false; - } - GetStackValue(-3, a_Ret1); - GetStackValue(-2, a_Ret2); - GetStackValue(-1, a_Ret3); - lua_pop(m_LuaState, 3); - return true; - } - - /** Call any 8-param 3-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, - typename ArgT6, typename ArgT7, typename ArgT8, - typename RetT1, typename RetT2, typename RetT3 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - Push(a_Arg8); - if (!CallFunction(3)) - { - return false; - } - GetStackValue(-3, a_Ret1); - GetStackValue(-2, a_Ret2); - GetStackValue(-1, a_Ret3); - lua_pop(m_LuaState, 3); - return true; - } - - /** Call any 9-param 5-return Lua function in a single line: */ - template< - typename FnT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, - typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9, - typename RetT1, typename RetT2, typename RetT3, typename RetT4, typename RetT5 - > - bool Call(FnT a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5) - { - UNUSED(a_Mark); - if (!PushFunction(a_FnName)) - { - return false; - } - Push(a_Arg1); - Push(a_Arg2); - Push(a_Arg3); - Push(a_Arg4); - Push(a_Arg5); - Push(a_Arg6); - Push(a_Arg7); - Push(a_Arg8); - Push(a_Arg9); - if (!CallFunction(5)) - { - return false; - } - GetStackValue(-5, a_Ret1); - GetStackValue(-4, a_Ret2); - GetStackValue(-3, a_Ret3); - GetStackValue(-2, a_Ret4); - GetStackValue(-1, a_Ret5); - lua_pop(m_LuaState, 5); - return true; - } + // Include the cLuaState::Call() overload implementation that is generated by the gen_LuaState_Call.lua script: + #include "LuaState_Call.inc" /** Returns true if the specified parameters on the stack are of the specified usertable type; also logs warning if not. Used for static functions */ diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index f52d970bf..88d40bfd9 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -4,7 +4,7 @@ #include "ManualBindings.h" #undef TOLUA_TEMPLATE_BIND #include "tolua++/include/tolua++.h" - +#include "polarssl/md5.h" #include "Plugin.h" #include "PluginLua.h" #include "PluginManager.h" @@ -25,7 +25,6 @@ #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/MobHeadEntity.h" #include "../BlockEntities/FlowerPotEntity.h" -#include "md5/md5.h" #include "../LineBlockTracer.h" #include "../WorldStorage/SchematicFileSerializer.h" #include "../CompositeChat.h" @@ -2001,9 +2000,11 @@ static int tolua_cPlugin_Call(lua_State * tolua_S) static int tolua_md5(lua_State* tolua_S) { - std::string SourceString = tolua_tostring(tolua_S, 1, 0); - std::string CryptedString = md5( SourceString ); - tolua_pushstring( tolua_S, CryptedString.c_str() ); + unsigned char Output[16]; + size_t len = 0; + const unsigned char * SourceString = (const unsigned char *)lua_tolstring(tolua_S, 1, &len); + md5(SourceString, len, Output); + lua_pushlstring(tolua_S, (const char *)Output, ARRAYCOUNT(Output)); return 1; } diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index c6461c861..8ba20c026 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -72,6 +72,7 @@ public: virtual bool OnPlayerEating (cPlayer & a_Player) = 0; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0; virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0; + virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) = 0; virtual bool OnPlayerJoined (cPlayer & a_Player) = 0; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0; virtual bool OnPlayerMoved (cPlayer & a_Player) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 96c5ccde7..104380ea4 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -715,6 +715,26 @@ bool cPluginLua::OnPlayerEating(cPlayer & a_Player) +bool cPluginLua::OnPlayerFoodLevelChange(cPlayer & a_Player, int a_NewFoodLevel) +{ + cCSLock Lock(m_CriticalSection); + bool res = false; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FOOD_LEVEL_CHANGE]; + for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) + { + m_LuaState.Call((int)(**itr), &a_Player, a_NewFoodLevel, cLuaState::Return, res); + if (res) + { + return true; + } + } + return false; +} + + + + + bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward) { cCSLock Lock(m_CriticalSection); @@ -1327,18 +1347,15 @@ bool cPluginLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather) { cCSLock Lock(m_CriticalSection); bool res = false; - int NewWeather = a_NewWeather; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_WEATHER_CHANGING]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_World, NewWeather, cLuaState::Return, res, NewWeather); + m_LuaState.Call((int)(**itr), &a_World, a_NewWeather, cLuaState::Return, res, a_NewWeather); if (res) { - a_NewWeather = (eWeather)NewWeather; return true; } } - a_NewWeather = (eWeather)NewWeather; return false; } @@ -1714,7 +1731,7 @@ bool cPluginLua::CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer ASSERT(a_FnRef != LUA_REFNIL); cCSLock Lock(m_CriticalSection); - bool res; + bool res = false; m_LuaState.Call(a_FnRef, &a_Window, &a_Player, a_CanRefuse, cLuaState::Return, res); return res; } diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 598e031c0..9c9de95c6 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -95,6 +95,7 @@ public: virtual bool OnPlayerEating (cPlayer & a_Player) override; virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override; virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override; + virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) override; virtual bool OnPlayerJoined (cPlayer & a_Player) override; virtual bool OnPlayerMoved (cPlayer & a_Player) override; virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index c50100d6f..7e6502515 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -257,18 +257,44 @@ bool cPluginManager::CallHookBlockToPickups( bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message) { - bool WasCommandForbidden = false; - if (HandleCommand(a_Player, a_Message, true, WasCommandForbidden)) // We use HandleCommand as opposed to ExecuteCommand to accomodate the need to the WasCommandForbidden bool + // Check if the message contains a command, execute it: + switch (HandleCommand(a_Player, a_Message, true)) { - return true; // Chat message was handled as command - } - else if (WasCommandForbidden) // Couldn't be handled as command, was it because of insufficient permissions? - { - return true; // Yes - message was sent in HandleCommand, abort + case crExecuted: + { + // 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 + a_Player->SendMessageFailure(Printf("Forbidden command; insufficient privileges: \"%s\"", a_Message.c_str())); + return true; + } + + case crUnknownCommand: + { + // This was not a known command, keep processing as a message + break; + } } - // Check if it was a standard command (starts with a slash) - // If it was, we know that it was completely unrecognised (WasCommandForbidden == false) + // Check if the message is a command (starts with a slash). If it is, we know that it wasn't recognised: if (!a_Message.empty() && (a_Message[0] == '/')) { AStringVector Split(StringSplit(a_Message, " ")); @@ -695,6 +721,25 @@ bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player) +bool cPluginManager::CallHookPlayerFoodLevelChange(cPlayer & a_Player, int a_NewFoodLevel) +{ + FIND_HOOK(HOOK_PLAYER_FOOD_LEVEL_CHANGE); + VERIFY_HOOK; + + for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) + { + if ((*itr)->OnPlayerFoodLevelChange(a_Player, a_NewFoodLevel)) + { + return true; + } + } + return false; +} + + + + + bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems a_Reward) { FIND_HOOK(HOOK_PLAYER_FISHED); @@ -1318,28 +1363,28 @@ bool cPluginManager::CallHookWorldTick(cWorld & a_World, float a_Dt, int a_LastT -bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden) +cPluginManager::CommandResult cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) { ASSERT(a_Player != NULL); AStringVector Split(StringSplit(a_Command, " ")); if (Split.empty()) { - return false; + return crUnknownCommand; } CommandMap::iterator cmd = m_Commands.find(Split[0]); if (cmd == m_Commands.end()) { // Command not found - return false; + return crUnknownCommand; } // Ask plugins first if a command is okay to execute the command: if (CallHookExecuteCommand(a_Player, Split)) { LOGINFO("Player %s tried executing command \"%s\" that was stopped by the HOOK_EXECUTE_COMMAND hook", a_Player->GetName().c_str(), Split[0].c_str()); - return false; + return crBlocked; } if ( @@ -1348,15 +1393,18 @@ bool cPluginManager::HandleCommand(cPlayer * a_Player, const AString & a_Command !a_Player->HasPermission(cmd->second.m_Permission) ) { - a_Player->SendMessageFailure(Printf("Forbidden command; insufficient privileges: \"%s\"", Split[0].c_str())); LOGINFO("Player %s tried to execute forbidden command: \"%s\"", a_Player->GetName().c_str(), Split[0].c_str()); - a_WasCommandForbidden = true; - return false; + return crNoPermission; } ASSERT(cmd->second.m_Plugin != NULL); - return cmd->second.m_Plugin->HandleCommand(Split, a_Player); + if (!cmd->second.m_Plugin->HandleCommand(Split, a_Player)) + { + return crError; + } + + return crExecuted; } @@ -1554,7 +1602,7 @@ AString cPluginManager::GetCommandPermission(const AString & a_Command) -bool cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Command) +cPluginManager::CommandResult cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Command) { return HandleCommand(a_Player, a_Command, true); } @@ -1563,7 +1611,7 @@ bool cPluginManager::ExecuteCommand(cPlayer * a_Player, const AString & a_Comman -bool cPluginManager::ForceExecuteCommand(cPlayer * a_Player, const AString & a_Command) +cPluginManager::CommandResult cPluginManager::ForceExecuteCommand(cPlayer * a_Player, const AString & a_Command) { return HandleCommand(a_Player, a_Command, false); } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index be40bd2f7..d435024bb 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -57,8 +57,17 @@ public: // tolua_export // Called each tick virtual void Tick(float a_Dt); - + // tolua_begin + enum CommandResult + { + crExecuted, + crUnknownCommand, + crError, + crBlocked, + crNoPermission, + } ; + enum PluginHook { HOOK_BLOCK_SPREAD, @@ -87,6 +96,7 @@ public: // tolua_export HOOK_PLAYER_EATING, HOOK_PLAYER_FISHED, HOOK_PLAYER_FISHING, + HOOK_PLAYER_FOOD_LEVEL_CHANGE, HOOK_PLAYER_JOINED, HOOK_PLAYER_LEFT_CLICK, HOOK_PLAYER_MOVING, @@ -188,6 +198,7 @@ public: // tolua_export bool CallHookPlayerEating (cPlayer & a_Player); bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward); bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward); + bool CallHookPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel); bool CallHookPlayerJoined (cPlayer & a_Player); bool CallHookPlayerMoving (cPlayer & a_Player); bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); @@ -244,11 +255,11 @@ public: // 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 true if executed. */ - bool ExecuteCommand(cPlayer * a_Player, 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 true if executed (false if not found) */ - bool ForceExecuteCommand(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); @@ -321,13 +332,8 @@ private: /** Adds the plugin into the internal list of plugins and initializes it. If initialization fails, the plugin is removed again. */ bool AddPlugin(cPlugin * a_Plugin); - /** Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns true if the command is handled. */ - bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions, bool & a_WasCommandForbidden); - bool HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions) - { - bool DummyBoolean = false; - return HandleCommand(a_Player, a_Command, a_ShouldCheckPermissions, DummyBoolean); - } + /** Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns crExecuted if the command is executed. */ + cPluginManager::CommandResult HandleCommand(cPlayer * a_Player, const AString & a_Command, bool a_ShouldCheckPermissions); } ; // tolua_export diff --git a/src/Bindings/gen_LuaState_Call.lua b/src/Bindings/gen_LuaState_Call.lua new file mode 100644 index 000000000..fb1797dc0 --- /dev/null +++ b/src/Bindings/gen_LuaState_Call.lua @@ -0,0 +1,196 @@ + +-- gen_LuaState_Call.lua + +-- Generates the cLuaState::Call() function templates that are included from LuaState.h + +--[[ +The cLuaState::Call() family of functions provides a template-based system for calling any Lua function +either by name or by reference with almost any number of parameters and return values. This is done by +providing a number of overloads of the same name with variable number of template-type parameters. To +separate the arguments from the return values, a special type of cLuaState::cRet is used. +--]] + + + + +print("Generating LuaState_Call.inc...") + + + + +-- List of combinations (# params, # returns) to generate: +local Combinations = +{ + -- no return values: + {0, 0}, + {1, 0}, + {2, 0}, + {3, 0}, + {4, 0}, + + -- 1 return value: + {0, 1}, + {1, 1}, + {2, 1}, + {3, 1}, + {4, 1}, + {5, 1}, + {6, 1}, + {7, 1}, + {8, 1}, + {9, 1}, + {10, 1}, + + -- 2 return values: + {0, 2}, + {1, 2}, + {2, 2}, + {3, 2}, + {4, 2}, + {5, 2}, + {6, 2}, + {7, 2}, + {8, 2}, + {9, 2}, + + -- Special combinations: + {7, 3}, + {8, 3}, + {9, 5}, +} + + + + +--- Writes a single overloaded function definition for the specified number of params and returns into f +--[[ +The format for the generated function is this: +/** Call the specified 3-param 2-return Lua function: +Returns true if call succeeded, false if there was an error. */ +template <typename FnT, typename ParamT1, typename ParamT2, typename ParamT3, typename RetT1, typename RetT2> +bool Call(FnT a_Function, ParamT1 a_Param1, ParamT2 a_Param2, ParamT3 a_Param3, const cLuaState::cRet & a_RetMark, RetT1 & a_Ret1, RetT2 & a_Ret2) +{ + UNUSED(a_RetMark); + if (!PushFunction(a_Function)) + { + return false; + } + Push(a_Param1); + Push(a_Param2); + Push(a_Param3); + if (!CallFunction(2)) + { + return false; + } + GetStackValue(-2, a_Ret1); + GetStackValue(-1, a_Ret2); + lua_pop(m_LuaState, 2); + return true; +} +Note especially the negative numbers in GetStackValue() calls. +--]] +local function WriteOverload(f, a_NumParams, a_NumReturns) + -- Write the function doxy-comments: + f:write("/** Call the specified ", a_NumParams, "-param ", a_NumReturns, "-return Lua function:\n") + f:write("Returns true if call succeeded, false if there was an error. */\n") + + -- Write the template <...> line: + f:write("template <typename FnT") + for i = 1, a_NumParams do + f:write(", typename ParamT", i) + end + if (a_NumReturns > 0) then + for i = 1, a_NumReturns do + f:write(", typename RetT", i) + end + end + f:write(">\n") + + -- Write the function signature: + f:write("bool Call(") + f:write("FnT a_Function") + for i = 1, a_NumParams do + f:write(", ParamT", i, " a_Param", i) + end + if (a_NumReturns > 0) then + f:write(", const cLuaState::cRet & a_RetMark") + for i = 1, a_NumReturns do + f:write(", RetT", i, " & a_Ret", i) + end + end + f:write(")\n") + + -- Common code: + f:write("{\n") + if (a_NumReturns > 0) then + f:write("\tUNUSED(a_RetMark);\n") + end + f:write("\tif (!PushFunction(a_Function))\n") + f:write("\t{\n") + f:write("\t\treturn false;\n") + f:write("\t}\n") + + -- Push the params: + for i = 1, a_NumParams do + f:write("\tPush(a_Param", i, ");\n") + end + + -- Call the function: + f:write("\tif (!CallFunction(", a_NumReturns, "))\n") + f:write("\t{\n") + f:write("\t\treturn false;\n") + f:write("\t}\n") + + -- Get the return values: + for i = 1, a_NumReturns do + f:write("\tGetStackValue(", -1 - a_NumReturns + i, ", a_Ret", i, ");\n") + end + + -- Pop the returns off the stack, if needed: + if (a_NumReturns > 0) then + f:write("\tlua_pop(m_LuaState, ", a_NumReturns, ");\n") + end + + -- Everything ok: + f:write("\treturn true;\n") + f:write("}\n") + + -- Separate from the next function: + f:write("\n\n\n\n\n") +end + + + + + +local f = assert(io.open("LuaState_Call.inc", "w")) + +-- Write file header: +f:write([[ +// LuaState_Call.inc + +// This file is auto-generated by gen_LuaState_Call.lua +// Make changes to the generator instead of to this file! + +// This file contains the various overloads for the cLuaState::Call() function +// Each overload handles a different number of parameters / return values +]]) +f:write("\n\n\n\n\n") + +-- Write out a template function for each overload: +for _, combination in ipairs(Combinations) do + WriteOverload(f, combination[1], combination[2]) +end + +-- Close the generated file +f:close() + + + + + +print("LuaState_Call.inc generated") + + + + diff --git a/src/Bindings/virtual_method_hooks.lua b/src/Bindings/virtual_method_hooks.lua index c610d424f..8ad30bf78 100644 --- a/src/Bindings/virtual_method_hooks.lua +++ b/src/Bindings/virtual_method_hooks.lua @@ -3,6 +3,20 @@ local disable_virtual_hooks = true local enable_pure_virtual = true local default_private_access = false + + + + +-- Code generators used by the build +-- Note that these are not exactly needed for the bindings, but rather we +-- misuse tolua's Lua engine to process files for us +dofile("gen_LuaState_Call.lua") + + + + + + local access = {public = 0, protected = 1, private = 2} function preparse_hook(p) diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp index e53930798..17816d63e 100644 --- a/src/BlockEntities/EnderChestEntity.cpp +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -12,9 +12,8 @@ cEnderChestEntity::cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : - super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World) + super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World) { - cBlockEntityWindowOwner::SetBlockEntity(this); } @@ -34,95 +33,63 @@ cEnderChestEntity::~cEnderChestEntity() -bool cEnderChestEntity::LoadFromJson(const Json::Value & a_Value) +void cEnderChestEntity::UsedBy(cPlayer * a_Player) { - m_PosX = a_Value.get("x", 0).asInt(); - m_PosY = a_Value.get("y", 0).asInt(); - m_PosZ = a_Value.get("z", 0).asInt(); - - Json::Value AllSlots = a_Value.get("Slots", 0); - int SlotIdx = 0; - for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr) + // If the window is not created, open it anew: + cWindow * Window = GetWindow(); + if (Window == NULL) { - cItem Item; - Item.FromJson(*itr); - SetSlot(SlotIdx, Item); - SlotIdx++; + OpenNewWindow(); + Window = GetWindow(); } - return true; -} - - - - - -void cEnderChestEntity::SaveToJson(Json::Value & a_Value) -{ - a_Value["x"] = m_PosX; - a_Value["y"] = m_PosY; - a_Value["z"] = m_PosZ; - - Json::Value AllSlots; - for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--) + + // Open the window for the player: + if (Window != NULL) { - Json::Value Slot; - m_Contents.GetSlot(i).GetJson(Slot); - AllSlots.append(Slot); + if (a_Player->GetWindow() != Window) + { + a_Player->OpenWindow(Window); + } } - a_Value["Slots"] = AllSlots; } -void cEnderChestEntity::SendTo(cClientHandle & a_Client) +void cEnderChestEntity::OpenNewWindow() { - // The chest entity doesn't need anything sent to the client when it's created / gets in the viewdistance - // All the actual handling is in the cWindow UI code that gets called when the chest is rclked - - UNUSED(a_Client); + OpenWindow(new cEnderChestWindow(this)); } -void cEnderChestEntity::UsedBy(cPlayer * a_Player) +void cEnderChestEntity::LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid) { - // If the window is not created, open it anew: - cWindow * Window = GetWindow(); - if (Window == NULL) - { - OpenNewWindow(); - Window = GetWindow(); - } - - // Open the window for the player: - if (Window != NULL) + int SlotIdx = 0; + for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr) { - if (a_Player->GetWindow() != Window) - { - a_Player->OpenWindow(Window); - } + cItem Item; + Item.FromJson(*itr); + a_Grid.SetSlot(SlotIdx, Item); + SlotIdx++; } - - // This is rather a hack - // Instead of marking the chunk as dirty upon chest contents change, we mark it dirty now - // We cannot properly detect contents change, but such a change doesn't happen without a player opening the chest first. - // The few false positives aren't much to worry about - int ChunkX, ChunkZ; - cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); - m_World->MarkChunkDirty(ChunkX, ChunkZ); } -void cEnderChestEntity::OpenNewWindow(void) +void cEnderChestEntity::SaveToJson(Json::Value & a_Value, const cItemGrid & a_Grid) { - OpenWindow(new cEnderChestWindow(this)); + for (int i = 0; i < a_Grid.GetNumSlots(); i++) + { + Json::Value Slot; + a_Grid.GetSlot(i).GetJson(Slot); + a_Value.append(Slot); + } } diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h index 45beee45f..04af67683 100644 --- a/src/BlockEntities/EnderChestEntity.h +++ b/src/BlockEntities/EnderChestEntity.h @@ -1,20 +1,9 @@ #pragma once -#include "BlockEntityWithItems.h" - - - - - -namespace Json -{ - class Value; -}; - -class cClientHandle; -class cServer; -class cNBTData; +#include "BlockEntity.h" +#include "UI/WindowOwner.h" +#include "json/json.h" @@ -22,33 +11,28 @@ class cNBTData; // tolua_begin class cEnderChestEntity : - public cBlockEntityWithItems + public cBlockEntity, + public cBlockEntityWindowOwner { - typedef cBlockEntityWithItems super; - -public: - enum { - ContentsHeight = 3, - ContentsWidth = 9, - } ; + typedef cBlockEntity super; +public: // tolua_end - /// Constructor used for normal operation - cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); - + cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); virtual ~cEnderChestEntity(); static const char * GetClassStatic(void) { return "cEnderChestEntity"; } - - bool LoadFromJson(const Json::Value & a_Value); // cBlockEntity overrides: - virtual void SaveToJson(Json::Value & a_Value) override; - virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; + virtual void SaveToJson(Json::Value & a_Value) override { UNUSED(a_Value); } + virtual void SendTo(cClientHandle & a_Client) override { UNUSED(a_Client); } + + 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 chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. + /** Opens a new enderchest window for this enderchest */ void OpenNewWindow(void); } ; // tolua_export diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 7f001c739..5856f20d1 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -294,23 +294,24 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) return false; } - int bx, by, bz; + // Get the coords of the block where to output items: + int OutX, OutY, OutZ; NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ); - if (!GetOutputBlockPos(Meta, bx, by, bz)) + if (!GetOutputBlockPos(Meta, OutX, OutY, OutZ)) { // Not attached to another container return false; } - if (by < 0) + if (OutY < 0) { // Cannot output below the zero-th block level return false; } // Convert coords to relative: - int rx = bx - a_Chunk.GetPosX() * cChunkDef::Width; - int rz = bz - a_Chunk.GetPosZ() * cChunkDef::Width; - cChunk * DestChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(rx, rz); + int OutRelX = OutX - a_Chunk.GetPosX() * cChunkDef::Width; + int OutRelZ = OutZ - a_Chunk.GetPosZ() * cChunkDef::Width; + cChunk * DestChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(OutRelX, OutRelZ); if (DestChunk == NULL) { // The destination chunk has been unloaded, don't tick @@ -319,26 +320,32 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick) // Call proper moving function, based on the blocktype present at the coords: bool res = false; - switch (DestChunk->GetBlock(rx, by, rz)) + switch (DestChunk->GetBlock(OutRelX, OutY, OutRelZ)) { case E_BLOCK_CHEST: { // Chests have special handling because of double-chests - res = MoveItemsToChest(*DestChunk, bx, by, bz); + res = MoveItemsToChest(*DestChunk, OutX, OutY, OutZ); break; } case E_BLOCK_LIT_FURNACE: case E_BLOCK_FURNACE: { // Furnaces have special handling because of the direction-to-slot relation - res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); + res = MoveItemsToFurnace(*DestChunk, OutX, OutY, OutZ, Meta); break; } case E_BLOCK_DISPENSER: case E_BLOCK_DROPPER: case E_BLOCK_HOPPER: { - res = MoveItemsToGrid(*(cBlockEntityWithItems *)DestChunk->GetBlockEntity(bx, by, bz)); + cBlockEntityWithItems * BlockEntity = (cBlockEntityWithItems *)DestChunk->GetBlockEntity(OutX, OutY, OutZ); + if (BlockEntity == NULL) + { + LOGWARNING("%s: A block entity was not found where expected at {%d, %d, %d}", __FUNCTION__, OutX, OutY, OutZ); + return false; + } + res = MoveItemsToGrid(*BlockEntity); break; } } @@ -359,7 +366,13 @@ bool cHopperEntity::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 cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) { - if (MoveItemsFromGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))) + cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); + if (Chest == NULL) + { + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); + return false; + } + if (MoveItemsFromGrid(*Chest)) { // Moved the item from the chest directly above the hopper return true; @@ -389,9 +402,17 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) { continue; } - if (MoveItemsFromGrid(*(cChestEntity *)Neighbor->GetBlockEntity(x, m_PosY, z))) + Chest = (cChestEntity *)Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); + if (Chest == NULL) { - return true; + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z); + } + else + { + if (MoveItemsFromGrid(*Chest)) + { + return true; + } } return false; } @@ -408,7 +429,11 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk) bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk) { cFurnaceEntity * Furnace = (cFurnaceEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ); - ASSERT(Furnace != NULL); + if (Furnace == NULL) + { + LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ); + return false; + } // Try move from the output slot: if (MoveItemsFromSlot(*Furnace, cFurnaceEntity::fsOutput, true)) @@ -517,7 +542,13 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) { // Try the chest directly connected to the hopper: - if (MoveItemsToGrid(*(cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))) + cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); + if (Chest == NULL) + { + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ); + return false; + } + if (MoveItemsToGrid(*Chest)) { return true; } @@ -534,19 +565,27 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block {0, 1}, {0, -1}, } ; + int RelX = a_BlockX - a_Chunk.GetPosX() * cChunkDef::Width; + int RelZ = a_BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width; for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) { - int x = m_RelX + Coords[i].x; - int z = m_RelZ + Coords[i].z; + int x = RelX + Coords[i].x; + int z = RelZ + Coords[i].z; cChunk * Neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(x, z); if ( (Neighbor == NULL) || - (Neighbor->GetBlock(x, m_PosY + 1, z) != E_BLOCK_CHEST) + (Neighbor->GetBlock(x, a_BlockY, z) != E_BLOCK_CHEST) ) { continue; } - if (MoveItemsToGrid(*(cChestEntity *)Neighbor->GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ))) + Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z); + if (Chest == NULL) + { + LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z); + continue; + } + if (MoveItemsToGrid(*Chest)) { return true; } diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 32fdec905..16314290a 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -8,12 +8,6 @@ -cBlockInfo cBlockInfo::ms_Info[256]; - - - - - cBlockInfo::cBlockInfo() : m_LightValue(0x00) , m_SpreadLightFalloff(0x0f) @@ -41,8 +35,18 @@ cBlockInfo::~cBlockInfo() +/** 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. */ cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type) { + static cBlockInfo ms_Info[256]; + static bool IsBlockInfoInitialized = false; + if (!IsBlockInfoInitialized) + { + cBlockInfo::Initialize(ms_Info); + IsBlockInfoInitialized = true; + } return ms_Info[a_Type]; } @@ -50,416 +54,410 @@ cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type) -void cBlockInfo::Initialize(void) +void cBlockInfo::Initialize(cBlockInfoArray & a_Info) { for (unsigned int i = 0; i < 256; ++i) { - if (ms_Info[i].m_Handler == NULL) + if (a_Info[i].m_Handler == NULL) { - ms_Info[i].m_Handler = cBlockHandler::CreateBlockHandler((BLOCKTYPE) i); + a_Info[i].m_Handler = cBlockHandler::CreateBlockHandler((BLOCKTYPE) i); } } // Emissive blocks - ms_Info[E_BLOCK_FIRE ].m_LightValue = 15; - ms_Info[E_BLOCK_GLOWSTONE ].m_LightValue = 15; - ms_Info[E_BLOCK_JACK_O_LANTERN ].m_LightValue = 15; - ms_Info[E_BLOCK_LAVA ].m_LightValue = 15; - ms_Info[E_BLOCK_STATIONARY_LAVA ].m_LightValue = 15; - ms_Info[E_BLOCK_END_PORTAL ].m_LightValue = 15; - ms_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_LightValue = 15; - ms_Info[E_BLOCK_TORCH ].m_LightValue = 14; - ms_Info[E_BLOCK_BURNING_FURNACE ].m_LightValue = 13; - ms_Info[E_BLOCK_NETHER_PORTAL ].m_LightValue = 11; - ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_LightValue = 9; - ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_LightValue = 9; - ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_LightValue = 7; - ms_Info[E_BLOCK_BREWING_STAND ].m_LightValue = 1; - ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_LightValue = 1; - ms_Info[E_BLOCK_DRAGON_EGG ].m_LightValue = 1; + a_Info[E_BLOCK_FIRE ].m_LightValue = 15; + a_Info[E_BLOCK_GLOWSTONE ].m_LightValue = 15; + a_Info[E_BLOCK_JACK_O_LANTERN ].m_LightValue = 15; + a_Info[E_BLOCK_LAVA ].m_LightValue = 15; + a_Info[E_BLOCK_STATIONARY_LAVA ].m_LightValue = 15; + a_Info[E_BLOCK_END_PORTAL ].m_LightValue = 15; + a_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_LightValue = 15; + a_Info[E_BLOCK_TORCH ].m_LightValue = 14; + a_Info[E_BLOCK_BURNING_FURNACE ].m_LightValue = 13; + a_Info[E_BLOCK_NETHER_PORTAL ].m_LightValue = 11; + a_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_LightValue = 9; + a_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_LightValue = 9; + a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_LightValue = 7; + a_Info[E_BLOCK_BREWING_STAND ].m_LightValue = 1; + a_Info[E_BLOCK_BROWN_MUSHROOM ].m_LightValue = 1; + a_Info[E_BLOCK_DRAGON_EGG ].m_LightValue = 1; // Spread blocks - ms_Info[E_BLOCK_AIR ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_CAKE ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_CHEST ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_COBWEB ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_CROPS ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_FENCE ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_FENCE_GATE ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_FIRE ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_GLASS ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_GLASS_PANE ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_GLOWSTONE ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_IRON_BARS ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_IRON_DOOR ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_LEAVES ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_NEW_LEAVES ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_SIGN_POST ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_TORCH ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_VINES ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_WALLSIGN ].m_SpreadLightFalloff = 1; - ms_Info[E_BLOCK_WOODEN_DOOR ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_AIR ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_CAKE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_CHEST ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_COBWEB ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_CROPS ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_FENCE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_FENCE_GATE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_FIRE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_GLASS ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_GLASS_PANE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_GLOWSTONE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_IRON_BARS ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_IRON_DOOR ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_LEAVES ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_NEW_LEAVES ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_SIGN_POST ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_TORCH ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_TRIPWIRE ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_TRIPWIRE_HOOK ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_VINES ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_WALLSIGN ].m_SpreadLightFalloff = 1; + a_Info[E_BLOCK_WOODEN_DOOR ].m_SpreadLightFalloff = 1; // Light in water and lava dissapears faster: - ms_Info[E_BLOCK_LAVA ].m_SpreadLightFalloff = 3; - ms_Info[E_BLOCK_STATIONARY_LAVA ].m_SpreadLightFalloff = 3; - ms_Info[E_BLOCK_STATIONARY_WATER ].m_SpreadLightFalloff = 3; - ms_Info[E_BLOCK_WATER ].m_SpreadLightFalloff = 3; + a_Info[E_BLOCK_LAVA ].m_SpreadLightFalloff = 3; + a_Info[E_BLOCK_STATIONARY_LAVA ].m_SpreadLightFalloff = 3; + a_Info[E_BLOCK_STATIONARY_WATER ].m_SpreadLightFalloff = 3; + a_Info[E_BLOCK_WATER ].m_SpreadLightFalloff = 3; // Transparent blocks - ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_Transparent = true; - ms_Info[E_BLOCK_AIR ].m_Transparent = true; - ms_Info[E_BLOCK_ANVIL ].m_Transparent = true; - ms_Info[E_BLOCK_BIG_FLOWER ].m_Transparent = true; - ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_Transparent = true; - ms_Info[E_BLOCK_CAKE ].m_Transparent = true; - ms_Info[E_BLOCK_CARROTS ].m_Transparent = true; - ms_Info[E_BLOCK_CHEST ].m_Transparent = true; - ms_Info[E_BLOCK_COBBLESTONE_WALL ].m_Transparent = true; - ms_Info[E_BLOCK_COBWEB ].m_Transparent = true; - ms_Info[E_BLOCK_CROPS ].m_Transparent = true; - ms_Info[E_BLOCK_DANDELION ].m_Transparent = true; - ms_Info[E_BLOCK_DETECTOR_RAIL ].m_Transparent = true; - ms_Info[E_BLOCK_ENDER_CHEST ].m_Transparent = true; - ms_Info[E_BLOCK_FENCE ].m_Transparent = true; - ms_Info[E_BLOCK_FENCE_GATE ].m_Transparent = true; - ms_Info[E_BLOCK_FIRE ].m_Transparent = true; - ms_Info[E_BLOCK_FLOWER ].m_Transparent = true; - ms_Info[E_BLOCK_FLOWER_POT ].m_Transparent = true; - ms_Info[E_BLOCK_GLASS ].m_Transparent = true; - ms_Info[E_BLOCK_GLASS_PANE ].m_Transparent = true; - ms_Info[E_BLOCK_HEAD ].m_Transparent = true; - ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; - ms_Info[E_BLOCK_ICE ].m_Transparent = true; - ms_Info[E_BLOCK_IRON_DOOR ].m_Transparent = true; - ms_Info[E_BLOCK_LADDER ].m_Transparent = true; - ms_Info[E_BLOCK_LAVA ].m_Transparent = true; - ms_Info[E_BLOCK_LEAVES ].m_Transparent = true; - ms_Info[E_BLOCK_LEVER ].m_Transparent = true; - ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; - ms_Info[E_BLOCK_MELON_STEM ].m_Transparent = true; - ms_Info[E_BLOCK_NETHER_BRICK_FENCE ].m_Transparent = true; - ms_Info[E_BLOCK_NEW_LEAVES ].m_Transparent = true; - ms_Info[E_BLOCK_POTATOES ].m_Transparent = true; - ms_Info[E_BLOCK_POWERED_RAIL ].m_Transparent = true; - ms_Info[E_BLOCK_PISTON_EXTENSION ].m_Transparent = true; - ms_Info[E_BLOCK_PUMPKIN_STEM ].m_Transparent = true; - ms_Info[E_BLOCK_RAIL ].m_Transparent = true; - ms_Info[E_BLOCK_RED_MUSHROOM ].m_Transparent = true; - ms_Info[E_BLOCK_SIGN_POST ].m_Transparent = true; - ms_Info[E_BLOCK_SNOW ].m_Transparent = true; - ms_Info[E_BLOCK_STAINED_GLASS ].m_Transparent = true; - ms_Info[E_BLOCK_STAINED_GLASS_PANE ].m_Transparent = true; - ms_Info[E_BLOCK_STATIONARY_LAVA ].m_Transparent = true; - ms_Info[E_BLOCK_STATIONARY_WATER ].m_Transparent = true; - ms_Info[E_BLOCK_STONE_BUTTON ].m_Transparent = true; - ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_Transparent = true; - ms_Info[E_BLOCK_TALL_GRASS ].m_Transparent = true; - ms_Info[E_BLOCK_TORCH ].m_Transparent = true; - ms_Info[E_BLOCK_VINES ].m_Transparent = true; - ms_Info[E_BLOCK_WALLSIGN ].m_Transparent = true; - ms_Info[E_BLOCK_WATER ].m_Transparent = true; - ms_Info[E_BLOCK_WOODEN_BUTTON ].m_Transparent = true; - ms_Info[E_BLOCK_WOODEN_DOOR ].m_Transparent = true; - ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_Transparent = true; + a_Info[E_BLOCK_ACTIVATOR_RAIL ].m_Transparent = true; + a_Info[E_BLOCK_AIR ].m_Transparent = true; + a_Info[E_BLOCK_ANVIL ].m_Transparent = true; + a_Info[E_BLOCK_BIG_FLOWER ].m_Transparent = true; + a_Info[E_BLOCK_BROWN_MUSHROOM ].m_Transparent = true; + a_Info[E_BLOCK_CAKE ].m_Transparent = true; + a_Info[E_BLOCK_CARROTS ].m_Transparent = true; + a_Info[E_BLOCK_CHEST ].m_Transparent = true; + a_Info[E_BLOCK_COBBLESTONE_WALL ].m_Transparent = true; + a_Info[E_BLOCK_COBWEB ].m_Transparent = true; + a_Info[E_BLOCK_CROPS ].m_Transparent = true; + a_Info[E_BLOCK_DANDELION ].m_Transparent = true; + a_Info[E_BLOCK_DETECTOR_RAIL ].m_Transparent = true; + a_Info[E_BLOCK_ENDER_CHEST ].m_Transparent = true; + a_Info[E_BLOCK_FENCE ].m_Transparent = true; + a_Info[E_BLOCK_FENCE_GATE ].m_Transparent = true; + a_Info[E_BLOCK_FIRE ].m_Transparent = true; + a_Info[E_BLOCK_FLOWER ].m_Transparent = true; + a_Info[E_BLOCK_FLOWER_POT ].m_Transparent = true; + a_Info[E_BLOCK_GLASS ].m_Transparent = true; + a_Info[E_BLOCK_GLASS_PANE ].m_Transparent = true; + a_Info[E_BLOCK_HEAD ].m_Transparent = true; + a_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; + a_Info[E_BLOCK_ICE ].m_Transparent = true; + a_Info[E_BLOCK_IRON_DOOR ].m_Transparent = true; + a_Info[E_BLOCK_LADDER ].m_Transparent = true; + a_Info[E_BLOCK_LAVA ].m_Transparent = true; + a_Info[E_BLOCK_LEAVES ].m_Transparent = true; + a_Info[E_BLOCK_LEVER ].m_Transparent = true; + a_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; + a_Info[E_BLOCK_MELON_STEM ].m_Transparent = true; + a_Info[E_BLOCK_NETHER_BRICK_FENCE ].m_Transparent = true; + a_Info[E_BLOCK_NEW_LEAVES ].m_Transparent = true; + a_Info[E_BLOCK_POTATOES ].m_Transparent = true; + a_Info[E_BLOCK_POWERED_RAIL ].m_Transparent = true; + a_Info[E_BLOCK_PISTON_EXTENSION ].m_Transparent = true; + a_Info[E_BLOCK_PUMPKIN_STEM ].m_Transparent = true; + a_Info[E_BLOCK_RAIL ].m_Transparent = true; + a_Info[E_BLOCK_RED_MUSHROOM ].m_Transparent = true; + a_Info[E_BLOCK_SIGN_POST ].m_Transparent = true; + a_Info[E_BLOCK_SNOW ].m_Transparent = true; + a_Info[E_BLOCK_STAINED_GLASS ].m_Transparent = true; + a_Info[E_BLOCK_STAINED_GLASS_PANE ].m_Transparent = true; + a_Info[E_BLOCK_STATIONARY_LAVA ].m_Transparent = true; + a_Info[E_BLOCK_STATIONARY_WATER ].m_Transparent = true; + a_Info[E_BLOCK_STONE_BUTTON ].m_Transparent = true; + a_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_Transparent = true; + a_Info[E_BLOCK_TRIPWIRE ].m_Transparent = true; + a_Info[E_BLOCK_TRIPWIRE_HOOK ].m_Transparent = true; + a_Info[E_BLOCK_TALL_GRASS ].m_Transparent = true; + a_Info[E_BLOCK_TORCH ].m_Transparent = true; + a_Info[E_BLOCK_VINES ].m_Transparent = true; + a_Info[E_BLOCK_WALLSIGN ].m_Transparent = true; + a_Info[E_BLOCK_WATER ].m_Transparent = true; + a_Info[E_BLOCK_WOODEN_BUTTON ].m_Transparent = true; + a_Info[E_BLOCK_WOODEN_DOOR ].m_Transparent = true; + a_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_Transparent = true; // TODO: Any other transparent blocks? // One hit break blocks: - ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_OneHitDig = true; - ms_Info[E_BLOCK_BIG_FLOWER ].m_OneHitDig = true; - ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_OneHitDig = true; - ms_Info[E_BLOCK_CARROTS ].m_OneHitDig = true; - ms_Info[E_BLOCK_CROPS ].m_OneHitDig = true; - ms_Info[E_BLOCK_DANDELION ].m_OneHitDig = true; - ms_Info[E_BLOCK_FIRE ].m_OneHitDig = true; - ms_Info[E_BLOCK_FLOWER ].m_OneHitDig = true; - ms_Info[E_BLOCK_FLOWER_POT ].m_OneHitDig = true; - ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_OneHitDig = true; - ms_Info[E_BLOCK_MELON_STEM ].m_OneHitDig = true; - ms_Info[E_BLOCK_POTATOES ].m_OneHitDig = true; - ms_Info[E_BLOCK_PUMPKIN_STEM ].m_OneHitDig = true; - ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_OneHitDig = true; - ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_OneHitDig = true; - ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_OneHitDig = true; - ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_OneHitDig = true; - ms_Info[E_BLOCK_REDSTONE_WIRE ].m_OneHitDig = true; - ms_Info[E_BLOCK_RED_MUSHROOM ].m_OneHitDig = true; - ms_Info[E_BLOCK_REEDS ].m_OneHitDig = true; - ms_Info[E_BLOCK_SAPLING ].m_OneHitDig = true; - ms_Info[E_BLOCK_TNT ].m_OneHitDig = true; - ms_Info[E_BLOCK_TALL_GRASS ].m_OneHitDig = true; - ms_Info[E_BLOCK_TORCH ].m_OneHitDig = true; + a_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_OneHitDig = true; + a_Info[E_BLOCK_BIG_FLOWER ].m_OneHitDig = true; + a_Info[E_BLOCK_BROWN_MUSHROOM ].m_OneHitDig = true; + a_Info[E_BLOCK_CARROTS ].m_OneHitDig = true; + a_Info[E_BLOCK_CROPS ].m_OneHitDig = true; + a_Info[E_BLOCK_DANDELION ].m_OneHitDig = true; + a_Info[E_BLOCK_FIRE ].m_OneHitDig = true; + a_Info[E_BLOCK_FLOWER ].m_OneHitDig = true; + a_Info[E_BLOCK_FLOWER_POT ].m_OneHitDig = true; + a_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_OneHitDig = true; + a_Info[E_BLOCK_MELON_STEM ].m_OneHitDig = true; + a_Info[E_BLOCK_POTATOES ].m_OneHitDig = true; + a_Info[E_BLOCK_PUMPKIN_STEM ].m_OneHitDig = true; + a_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_OneHitDig = true; + a_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_OneHitDig = true; + a_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_OneHitDig = true; + a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_OneHitDig = true; + a_Info[E_BLOCK_REDSTONE_WIRE ].m_OneHitDig = true; + a_Info[E_BLOCK_RED_MUSHROOM ].m_OneHitDig = true; + a_Info[E_BLOCK_REEDS ].m_OneHitDig = true; + a_Info[E_BLOCK_SAPLING ].m_OneHitDig = true; + a_Info[E_BLOCK_TNT ].m_OneHitDig = true; + a_Info[E_BLOCK_TALL_GRASS ].m_OneHitDig = true; + a_Info[E_BLOCK_TORCH ].m_OneHitDig = true; + a_Info[E_BLOCK_TRIPWIRE ].m_OneHitDig = true; // Blocks that break when pushed by piston: - ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_PistonBreakable = true; - ms_Info[E_BLOCK_AIR ].m_PistonBreakable = true; - ms_Info[E_BLOCK_BED ].m_PistonBreakable = true; - ms_Info[E_BLOCK_BIG_FLOWER ].m_PistonBreakable = true; - ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_PistonBreakable = true; - ms_Info[E_BLOCK_CAKE ].m_PistonBreakable = true; - ms_Info[E_BLOCK_COBWEB ].m_PistonBreakable = true; - ms_Info[E_BLOCK_CROPS ].m_PistonBreakable = true; - ms_Info[E_BLOCK_DANDELION ].m_PistonBreakable = true; - ms_Info[E_BLOCK_DEAD_BUSH ].m_PistonBreakable = true; - ms_Info[E_BLOCK_FIRE ].m_PistonBreakable = true; - ms_Info[E_BLOCK_FLOWER ].m_PistonBreakable = true; - ms_Info[E_BLOCK_HEAD ].m_PistonBreakable = true; - ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; - ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_PistonBreakable = true; - ms_Info[E_BLOCK_IRON_DOOR ].m_PistonBreakable = true; - ms_Info[E_BLOCK_JACK_O_LANTERN ].m_PistonBreakable = true; - ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; - ms_Info[E_BLOCK_LADDER ].m_PistonBreakable = true; - ms_Info[E_BLOCK_LAVA ].m_PistonBreakable = true; - ms_Info[E_BLOCK_LEVER ].m_PistonBreakable = true; - ms_Info[E_BLOCK_MELON ].m_PistonBreakable = true; - ms_Info[E_BLOCK_MELON_STEM ].m_PistonBreakable = true; - ms_Info[E_BLOCK_PUMPKIN ].m_PistonBreakable = true; - ms_Info[E_BLOCK_PUMPKIN_STEM ].m_PistonBreakable = true; - ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_PistonBreakable = true; - ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_PistonBreakable = true; - ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_PistonBreakable = true; - ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_PistonBreakable = true; - ms_Info[E_BLOCK_REDSTONE_WIRE ].m_PistonBreakable = true; - ms_Info[E_BLOCK_RED_MUSHROOM ].m_PistonBreakable = true; - ms_Info[E_BLOCK_REEDS ].m_PistonBreakable = true; - ms_Info[E_BLOCK_SNOW ].m_PistonBreakable = true; - ms_Info[E_BLOCK_STATIONARY_LAVA ].m_PistonBreakable = true; - ms_Info[E_BLOCK_STATIONARY_WATER ].m_PistonBreakable = true; - ms_Info[E_BLOCK_STONE_BUTTON ].m_PistonBreakable = true; - ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_PistonBreakable = true; - ms_Info[E_BLOCK_TALL_GRASS ].m_PistonBreakable = true; - ms_Info[E_BLOCK_TORCH ].m_PistonBreakable = true; - ms_Info[E_BLOCK_VINES ].m_PistonBreakable = true; - ms_Info[E_BLOCK_WATER ].m_PistonBreakable = true; - ms_Info[E_BLOCK_WOODEN_BUTTON ].m_PistonBreakable = true; - ms_Info[E_BLOCK_WOODEN_DOOR ].m_PistonBreakable = true; - ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_PistonBreakable = true; + a_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_PistonBreakable = true; + a_Info[E_BLOCK_AIR ].m_PistonBreakable = true; + a_Info[E_BLOCK_BED ].m_PistonBreakable = true; + a_Info[E_BLOCK_BIG_FLOWER ].m_PistonBreakable = true; + a_Info[E_BLOCK_BROWN_MUSHROOM ].m_PistonBreakable = true; + a_Info[E_BLOCK_CAKE ].m_PistonBreakable = true; + a_Info[E_BLOCK_COBWEB ].m_PistonBreakable = true; + a_Info[E_BLOCK_CROPS ].m_PistonBreakable = true; + a_Info[E_BLOCK_DANDELION ].m_PistonBreakable = true; + a_Info[E_BLOCK_DEAD_BUSH ].m_PistonBreakable = true; + a_Info[E_BLOCK_FIRE ].m_PistonBreakable = true; + a_Info[E_BLOCK_FLOWER ].m_PistonBreakable = true; + a_Info[E_BLOCK_HEAD ].m_PistonBreakable = true; + a_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; + a_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_PistonBreakable = true; + a_Info[E_BLOCK_IRON_DOOR ].m_PistonBreakable = true; + a_Info[E_BLOCK_JACK_O_LANTERN ].m_PistonBreakable = true; + a_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; + a_Info[E_BLOCK_LADDER ].m_PistonBreakable = true; + a_Info[E_BLOCK_LAVA ].m_PistonBreakable = true; + a_Info[E_BLOCK_LEVER ].m_PistonBreakable = true; + a_Info[E_BLOCK_MELON ].m_PistonBreakable = true; + a_Info[E_BLOCK_MELON_STEM ].m_PistonBreakable = true; + a_Info[E_BLOCK_PUMPKIN ].m_PistonBreakable = true; + a_Info[E_BLOCK_PUMPKIN_STEM ].m_PistonBreakable = true; + a_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_PistonBreakable = true; + a_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_PistonBreakable = true; + a_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_PistonBreakable = true; + a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_PistonBreakable = true; + a_Info[E_BLOCK_REDSTONE_WIRE ].m_PistonBreakable = true; + a_Info[E_BLOCK_RED_MUSHROOM ].m_PistonBreakable = true; + a_Info[E_BLOCK_REEDS ].m_PistonBreakable = true; + a_Info[E_BLOCK_SNOW ].m_PistonBreakable = true; + a_Info[E_BLOCK_STATIONARY_LAVA ].m_PistonBreakable = true; + a_Info[E_BLOCK_STATIONARY_WATER ].m_PistonBreakable = true; + a_Info[E_BLOCK_STONE_BUTTON ].m_PistonBreakable = true; + a_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_PistonBreakable = true; + a_Info[E_BLOCK_TALL_GRASS ].m_PistonBreakable = true; + a_Info[E_BLOCK_TORCH ].m_PistonBreakable = true; + a_Info[E_BLOCK_TRIPWIRE ].m_PistonBreakable = true; + a_Info[E_BLOCK_TRIPWIRE_HOOK ].m_PistonBreakable = true; + a_Info[E_BLOCK_VINES ].m_PistonBreakable = true; + a_Info[E_BLOCK_WATER ].m_PistonBreakable = true; + a_Info[E_BLOCK_WOODEN_BUTTON ].m_PistonBreakable = true; + a_Info[E_BLOCK_WOODEN_DOOR ].m_PistonBreakable = true; + a_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_PistonBreakable = true; // Blocks that cannot be snowed over: - ms_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_IsSnowable = false; - ms_Info[E_BLOCK_AIR ].m_IsSnowable = false; - ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSnowable = false; - ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSnowable = false; - ms_Info[E_BLOCK_CACTUS ].m_IsSnowable = false; - ms_Info[E_BLOCK_CHEST ].m_IsSnowable = false; - ms_Info[E_BLOCK_CROPS ].m_IsSnowable = false; - ms_Info[E_BLOCK_COBBLESTONE_WALL ].m_IsSnowable = false; - ms_Info[E_BLOCK_DANDELION ].m_IsSnowable = false; - ms_Info[E_BLOCK_FIRE ].m_IsSnowable = false; - ms_Info[E_BLOCK_FLOWER ].m_IsSnowable = false; - ms_Info[E_BLOCK_GLASS ].m_IsSnowable = false; - ms_Info[E_BLOCK_ICE ].m_IsSnowable = false; - ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_IsSnowable = false; - ms_Info[E_BLOCK_LAVA ].m_IsSnowable = false; - ms_Info[E_BLOCK_LILY_PAD ].m_IsSnowable = false; - ms_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_IsSnowable = false; - ms_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_IsSnowable = false; - ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSnowable = false; - ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSnowable = false; - ms_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSnowable = false; - ms_Info[E_BLOCK_RED_MUSHROOM ].m_IsSnowable = false; - ms_Info[E_BLOCK_REEDS ].m_IsSnowable = false; - ms_Info[E_BLOCK_SAPLING ].m_IsSnowable = false; - ms_Info[E_BLOCK_SIGN_POST ].m_IsSnowable = false; - ms_Info[E_BLOCK_SNOW ].m_IsSnowable = false; - ms_Info[E_BLOCK_STAINED_GLASS ].m_IsSnowable = false; - ms_Info[E_BLOCK_STAINED_GLASS_PANE ].m_IsSnowable = false; - ms_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSnowable = false; - ms_Info[E_BLOCK_STATIONARY_WATER ].m_IsSnowable = false; - ms_Info[E_BLOCK_TALL_GRASS ].m_IsSnowable = false; - ms_Info[E_BLOCK_TNT ].m_IsSnowable = false; - ms_Info[E_BLOCK_TORCH ].m_IsSnowable = false; - ms_Info[E_BLOCK_VINES ].m_IsSnowable = false; - ms_Info[E_BLOCK_WALLSIGN ].m_IsSnowable = false; - ms_Info[E_BLOCK_WATER ].m_IsSnowable = false; - ms_Info[E_BLOCK_RAIL ].m_IsSnowable = false; - ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSnowable = false; - ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSnowable = false; - ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSnowable = false; - ms_Info[E_BLOCK_COBWEB ].m_IsSnowable = false; - ms_Info[E_BLOCK_HEAD ].m_IsSnowable = false; + a_Info[E_BLOCK_ACTIVE_COMPARATOR ].m_IsSnowable = false; + a_Info[E_BLOCK_AIR ].m_IsSnowable = false; + a_Info[E_BLOCK_BIG_FLOWER ].m_IsSnowable = false; + a_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSnowable = false; + a_Info[E_BLOCK_CACTUS ].m_IsSnowable = false; + a_Info[E_BLOCK_CHEST ].m_IsSnowable = false; + a_Info[E_BLOCK_CROPS ].m_IsSnowable = false; + a_Info[E_BLOCK_COBBLESTONE_WALL ].m_IsSnowable = false; + a_Info[E_BLOCK_DANDELION ].m_IsSnowable = false; + a_Info[E_BLOCK_FIRE ].m_IsSnowable = false; + a_Info[E_BLOCK_FLOWER ].m_IsSnowable = false; + a_Info[E_BLOCK_GLASS ].m_IsSnowable = false; + a_Info[E_BLOCK_ICE ].m_IsSnowable = false; + a_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_IsSnowable = false; + a_Info[E_BLOCK_LAVA ].m_IsSnowable = false; + a_Info[E_BLOCK_LILY_PAD ].m_IsSnowable = false; + a_Info[E_BLOCK_REDSTONE_REPEATER_OFF].m_IsSnowable = false; + a_Info[E_BLOCK_REDSTONE_REPEATER_ON].m_IsSnowable = false; + a_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSnowable = false; + a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSnowable = false; + a_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSnowable = false; + a_Info[E_BLOCK_RED_MUSHROOM ].m_IsSnowable = false; + a_Info[E_BLOCK_REEDS ].m_IsSnowable = false; + a_Info[E_BLOCK_SAPLING ].m_IsSnowable = false; + a_Info[E_BLOCK_SIGN_POST ].m_IsSnowable = false; + a_Info[E_BLOCK_SNOW ].m_IsSnowable = false; + a_Info[E_BLOCK_STAINED_GLASS ].m_IsSnowable = false; + a_Info[E_BLOCK_STAINED_GLASS_PANE ].m_IsSnowable = false; + a_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSnowable = false; + a_Info[E_BLOCK_STATIONARY_WATER ].m_IsSnowable = false; + a_Info[E_BLOCK_TALL_GRASS ].m_IsSnowable = false; + a_Info[E_BLOCK_TNT ].m_IsSnowable = false; + a_Info[E_BLOCK_TORCH ].m_IsSnowable = false; + a_Info[E_BLOCK_TRIPWIRE ].m_IsSnowable = false; + a_Info[E_BLOCK_TRIPWIRE_HOOK ].m_IsSnowable = false; + a_Info[E_BLOCK_VINES ].m_IsSnowable = false; + a_Info[E_BLOCK_WALLSIGN ].m_IsSnowable = false; + a_Info[E_BLOCK_WATER ].m_IsSnowable = false; + a_Info[E_BLOCK_RAIL ].m_IsSnowable = false; + a_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSnowable = false; + a_Info[E_BLOCK_POWERED_RAIL ].m_IsSnowable = false; + a_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSnowable = false; + a_Info[E_BLOCK_COBWEB ].m_IsSnowable = false; + a_Info[E_BLOCK_HEAD ].m_IsSnowable = false; // Blocks that don't drop without a special tool: - ms_Info[E_BLOCK_BRICK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_CAULDRON ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_COAL_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_COBBLESTONE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_COBBLESTONE_WALL ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_COBWEB ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_DIAMOND_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_EMERALD_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_END_STONE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_GOLD_BLOCK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_GOLD_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_IRON_BLOCK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_IRON_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_LAPIS_BLOCK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_LAPIS_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_NETHERRACK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_NETHER_BRICK ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_NETHER_BRICK_STAIRS ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_OBSIDIAN ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_REDSTONE_ORE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_SANDSTONE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_SANDSTONE_STAIRS ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_SNOW ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_STONE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_STONE_BRICKS ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_STONE_BRICK_STAIRS ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_STONE_SLAB ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_VINES ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_FURNACE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_LIT_FURNACE ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_ANVIL ].m_RequiresSpecialTool = true; - ms_Info[E_BLOCK_ENCHANTMENT_TABLE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_BRICK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_CAULDRON ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_COAL_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_COBBLESTONE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_COBBLESTONE_WALL ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_COBWEB ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_DIAMOND_BLOCK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_DIAMOND_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_EMERALD_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_END_STONE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_GOLD_BLOCK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_GOLD_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_IRON_BLOCK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_IRON_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_LAPIS_BLOCK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_LAPIS_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_NETHERRACK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_NETHER_BRICK ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_NETHER_BRICK_STAIRS ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_OBSIDIAN ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_REDSTONE_ORE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_SANDSTONE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_SANDSTONE_STAIRS ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_SNOW ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_STONE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_STONE_BRICKS ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_STONE_BRICK_STAIRS ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_STONE_SLAB ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_VINES ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_FURNACE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_LIT_FURNACE ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_ANVIL ].m_RequiresSpecialTool = true; + a_Info[E_BLOCK_ENCHANTMENT_TABLE ].m_RequiresSpecialTool = true; // Nonsolid blocks: - ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSolid = false; - ms_Info[E_BLOCK_AIR ].m_IsSolid = false; - ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false; - ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false; - ms_Info[E_BLOCK_CAKE ].m_IsSolid = false; - ms_Info[E_BLOCK_CARROTS ].m_IsSolid = false; - ms_Info[E_BLOCK_COBWEB ].m_IsSolid = false; - ms_Info[E_BLOCK_CROPS ].m_IsSolid = false; - ms_Info[E_BLOCK_DANDELION ].m_IsSolid = false; - ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSolid = false; - ms_Info[E_BLOCK_END_PORTAL ].m_IsSolid = false; - ms_Info[E_BLOCK_FENCE ].m_IsSolid = false; - ms_Info[E_BLOCK_FENCE_GATE ].m_IsSolid = false; - ms_Info[E_BLOCK_FIRE ].m_IsSolid = false; - ms_Info[E_BLOCK_FLOWER ].m_IsSolid = false; - ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false; - ms_Info[E_BLOCK_LAVA ].m_IsSolid = false; - ms_Info[E_BLOCK_LEVER ].m_IsSolid = false; - ms_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false; - ms_Info[E_BLOCK_MELON_STEM ].m_IsSolid = false; - ms_Info[E_BLOCK_NETHER_PORTAL ].m_IsSolid = false; - ms_Info[E_BLOCK_PISTON_EXTENSION ].m_IsSolid = false; - ms_Info[E_BLOCK_POTATOES ].m_IsSolid = false; - ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSolid = false; - ms_Info[E_BLOCK_RAIL ].m_IsSolid = false; - ms_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSolid = false; - ms_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSolid = false; - ms_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSolid = false; - ms_Info[E_BLOCK_RED_MUSHROOM ].m_IsSolid = false; - ms_Info[E_BLOCK_REEDS ].m_IsSolid = false; - ms_Info[E_BLOCK_SAPLING ].m_IsSolid = false; - ms_Info[E_BLOCK_SIGN_POST ].m_IsSolid = false; - ms_Info[E_BLOCK_SNOW ].m_IsSolid = false; - ms_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSolid = false; - ms_Info[E_BLOCK_STATIONARY_WATER ].m_IsSolid = false; - ms_Info[E_BLOCK_STONE_BUTTON ].m_IsSolid = false; - ms_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_IsSolid = false; - ms_Info[E_BLOCK_TALL_GRASS ].m_IsSolid = false; - ms_Info[E_BLOCK_TORCH ].m_IsSolid = false; - ms_Info[E_BLOCK_TRIPWIRE ].m_IsSolid = false; - ms_Info[E_BLOCK_VINES ].m_IsSolid = false; - ms_Info[E_BLOCK_WALLSIGN ].m_IsSolid = false; - ms_Info[E_BLOCK_WATER ].m_IsSolid = false; - ms_Info[E_BLOCK_WOODEN_BUTTON ].m_IsSolid = false; - ms_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_IsSolid = false; - ms_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false; + a_Info[E_BLOCK_ACTIVATOR_RAIL ].m_IsSolid = false; + a_Info[E_BLOCK_AIR ].m_IsSolid = false; + a_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false; + a_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false; + a_Info[E_BLOCK_CAKE ].m_IsSolid = false; + a_Info[E_BLOCK_CARROTS ].m_IsSolid = false; + a_Info[E_BLOCK_COBWEB ].m_IsSolid = false; + a_Info[E_BLOCK_CROPS ].m_IsSolid = false; + a_Info[E_BLOCK_DANDELION ].m_IsSolid = false; + a_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSolid = false; + a_Info[E_BLOCK_END_PORTAL ].m_IsSolid = false; + a_Info[E_BLOCK_FENCE ].m_IsSolid = false; + a_Info[E_BLOCK_FENCE_GATE ].m_IsSolid = false; + a_Info[E_BLOCK_FIRE ].m_IsSolid = false; + a_Info[E_BLOCK_FLOWER ].m_IsSolid = false; + a_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false; + a_Info[E_BLOCK_LAVA ].m_IsSolid = false; + a_Info[E_BLOCK_LEVER ].m_IsSolid = false; + a_Info[E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE].m_IsSolid = false; + a_Info[E_BLOCK_MELON_STEM ].m_IsSolid = false; + a_Info[E_BLOCK_NETHER_PORTAL ].m_IsSolid = false; + a_Info[E_BLOCK_PISTON_EXTENSION ].m_IsSolid = false; + a_Info[E_BLOCK_POTATOES ].m_IsSolid = false; + a_Info[E_BLOCK_POWERED_RAIL ].m_IsSolid = false; + a_Info[E_BLOCK_RAIL ].m_IsSolid = false; + a_Info[E_BLOCK_REDSTONE_TORCH_OFF ].m_IsSolid = false; + a_Info[E_BLOCK_REDSTONE_TORCH_ON ].m_IsSolid = false; + a_Info[E_BLOCK_REDSTONE_WIRE ].m_IsSolid = false; + a_Info[E_BLOCK_RED_MUSHROOM ].m_IsSolid = false; + a_Info[E_BLOCK_REEDS ].m_IsSolid = false; + a_Info[E_BLOCK_SAPLING ].m_IsSolid = false; + a_Info[E_BLOCK_SIGN_POST ].m_IsSolid = false; + a_Info[E_BLOCK_SNOW ].m_IsSolid = false; + a_Info[E_BLOCK_STATIONARY_LAVA ].m_IsSolid = false; + a_Info[E_BLOCK_STATIONARY_WATER ].m_IsSolid = false; + a_Info[E_BLOCK_STONE_BUTTON ].m_IsSolid = false; + a_Info[E_BLOCK_STONE_PRESSURE_PLATE].m_IsSolid = false; + a_Info[E_BLOCK_TALL_GRASS ].m_IsSolid = false; + a_Info[E_BLOCK_TORCH ].m_IsSolid = false; + a_Info[E_BLOCK_TRIPWIRE ].m_IsSolid = false; + a_Info[E_BLOCK_VINES ].m_IsSolid = false; + a_Info[E_BLOCK_WALLSIGN ].m_IsSolid = false; + a_Info[E_BLOCK_WATER ].m_IsSolid = false; + a_Info[E_BLOCK_WOODEN_BUTTON ].m_IsSolid = false; + a_Info[E_BLOCK_WOODEN_PRESSURE_PLATE].m_IsSolid = false; + a_Info[E_BLOCK_WOODEN_SLAB ].m_IsSolid = false; // Blocks that fully occupy their voxel - used as a guide for torch placeable blocks, amongst other things: - ms_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_BLOCK_OF_REDSTONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_BOOKCASE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_BRICK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_CLAY ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_COAL_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_COBBLESTONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_COMMAND_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_CRAFTING_TABLE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DIAMOND_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DIRT ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DISPENSER ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DOUBLE_WOODEN_SLAB ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_DROPPER ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_EMERALD_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_EMERALD_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_END_STONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_FURNACE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_GLOWSTONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_GOLD_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_GOLD_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_GRASS ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_GRAVEL ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_HARDENED_CLAY ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_ICE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_JUKEBOX ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_LAPIS_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_LAPIS_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_LOG ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_MELON ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_MYCELIUM ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_NETHERRACK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_NETHER_BRICK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_NETHER_QUARTZ_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_NOTE_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_OBSIDIAN ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_PACKED_ICE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_PLANKS ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_PUMPKIN ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_QUARTZ_BLOCK ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_REDSTONE_LAMP_OFF ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_REDSTONE_ORE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_SANDSTONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_SAND ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_SILVERFISH_EGG ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_SPONGE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_STAINED_CLAY ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_WOOL ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_STONE ].m_FullyOccupiesVoxel = true; - ms_Info[E_BLOCK_STONE_BRICKS ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_NEW_LOG ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_BEDROCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_BLOCK_OF_COAL ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_BLOCK_OF_REDSTONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_BOOKCASE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_BRICK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_CLAY ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_COAL_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_COBBLESTONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_COMMAND_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_CRAFTING_TABLE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DIAMOND_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DIAMOND_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DIRT ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DISPENSER ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DOUBLE_STONE_SLAB ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DOUBLE_WOODEN_SLAB ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_DROPPER ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_EMERALD_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_EMERALD_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_END_STONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_FURNACE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_GLOWSTONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_GOLD_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_GOLD_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_GRASS ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_GRAVEL ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_HARDENED_CLAY ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_HAY_BALE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_HUGE_BROWN_MUSHROOM ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_HUGE_RED_MUSHROOM ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_ICE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_IRON_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_IRON_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_JACK_O_LANTERN ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_JUKEBOX ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_LAPIS_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_LAPIS_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_LOG ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_MELON ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_MOSSY_COBBLESTONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_MYCELIUM ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_NETHERRACK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_NETHER_BRICK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_NETHER_QUARTZ_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_NOTE_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_OBSIDIAN ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_PACKED_ICE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_PLANKS ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_PUMPKIN ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_QUARTZ_BLOCK ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_REDSTONE_LAMP_OFF ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_REDSTONE_LAMP_ON ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_REDSTONE_ORE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_REDSTONE_ORE_GLOWING].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_SANDSTONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_SAND ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_SILVERFISH_EGG ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_SPONGE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_STAINED_CLAY ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_WOOL ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_STONE ].m_FullyOccupiesVoxel = true; + a_Info[E_BLOCK_STONE_BRICKS ].m_FullyOccupiesVoxel = true; } - -// This is actually just some code that needs to run at program startup, so it is wrapped into a global var's constructor: -class cBlockInfoInitializer -{ -public: - cBlockInfoInitializer(void) - { - cBlockInfo::Initialize(); - } -} BlockInfoInitializer; - - - - - diff --git a/src/BlockInfo.h b/src/BlockInfo.h index 40c1db867..d6d4e7430 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -16,18 +16,8 @@ class cBlockHandler; class cBlockInfo { public: - // tolua_end - - cBlockInfo(); - - ~cBlockInfo(); - - /** (Re-)Initializes the internal BlockInfo structures. */ - static void Initialize(void); - // tolua_begin - - /** Returns the associated BlockInfo structure. */ + /** Returns the associated BlockInfo structure for the specified block type. */ static cBlockInfo & Get(BLOCKTYPE a_Type); @@ -79,13 +69,18 @@ public: inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler; } - protected: + /** Storage for all the BlockInfo structures. */ + typedef cBlockInfo cBlockInfoArray[256]; - // TODO xdot: Change to std::vector to support dynamic block IDs - static cBlockInfo ms_Info[256]; + /** Creates a default BlockInfo structure, initializes all values to their defaults */ + cBlockInfo(); + /** Cleans up the stored values */ + ~cBlockInfo(); + /** Initializes the specified BlockInfo structures with block-specific values. */ + static void Initialize(cBlockInfoArray & a_BlockInfos); }; // tolua_export diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 4b2f6f618..ada7d58f7 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -23,6 +23,7 @@ public: NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_WorldInterface.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); // Queue a button reset (unpress) @@ -102,7 +103,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); - return (a_RelY > 0) && (cBlockInfo::IsSolid(BlockIsOn)); + return (a_RelY > 0) && (cBlockInfo::FullyOccupiesVoxel(BlockIsOn)); } } ; diff --git a/src/Blocks/BlockDoor.cpp b/src/Blocks/BlockDoor.cpp index fb2d6f2dc..934a01994 100644 --- a/src/Blocks/BlockDoor.cpp +++ b/src/Blocks/BlockDoor.cpp @@ -45,9 +45,16 @@ void cBlockDoorHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldIn void cBlockDoorHandler::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) { + UNUSED(a_WorldInterface); + UNUSED(a_BlockFace); + UNUSED(a_CursorX); + UNUSED(a_CursorY); + UNUSED(a_CursorZ); + if (a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_WOODEN_DOOR) { ChangeDoor(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ); + a_Player->GetWorld()->BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player->GetClientHandle()); } } diff --git a/src/Blocks/BlockFenceGate.h b/src/Blocks/BlockFenceGate.h index e202c6610..e992870d4 100644 --- a/src/Blocks/BlockFenceGate.h +++ b/src/Blocks/BlockFenceGate.h @@ -45,6 +45,7 @@ public: // Standing aside - use last direction a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, OldMetaData); } + a_Player->GetWorld()->BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0, a_Player->GetClientHandle()); } diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index a7b89fcb7..3ddb7531d 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -65,6 +65,8 @@ #include "BlockRedstoneRepeater.h" #include "BlockRedstoneTorch.h" #include "BlockTNT.h" +#include "BlockTripwire.h" +#include "BlockTripwireHook.h" #include "BlockSand.h" #include "BlockSapling.h" #include "BlockSideways.h" @@ -85,6 +87,91 @@ +/* +// Tests the meta rotation and mirroring. +// Note that the cMetaRotator needs to have its assert paths disabled for this test to work! +static class cBlockHandlerRotationTester +{ +public: + cBlockHandlerRotationTester(void) + { + printf("Performing block handlers test...\n"); + for (BLOCKTYPE Type = 0; Type < E_BLOCK_MAX_TYPE_ID; Type++) + { + cBlockHandler * Handler = cBlockInfo::GetHandler(Type); + if (Handler == NULL) + { + printf("NULL handler for block type %d!\n", Type); + continue; + } + AString BlockName = ItemTypeToString(Type); + for (NIBBLETYPE Meta = 0; Meta < 16; Meta++) + { + // Test the CW / CCW rotations: + NIBBLETYPE TestMeta; + TestMeta = Handler->MetaRotateCW(Handler->MetaRotateCW(Handler->MetaRotateCW(Handler->MetaRotateCW(Meta)))); + if (TestMeta != Meta) + { + // 4 CW rotations should produce no change in the meta + printf("Handler for blocktype %d (%s) fails CW 4-rotation test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta); + } + TestMeta = Handler->MetaRotateCCW(Handler->MetaRotateCCW(Handler->MetaRotateCCW(Handler->MetaRotateCCW(Meta)))); + if (TestMeta != Meta) + { + // 4 CCW rotations should produce no change in the meta + printf("Handler for blocktype %d (%s) fails CCW 4-rotation test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta); + } + TestMeta = Handler->MetaRotateCCW(Handler->MetaRotateCW(Meta)); + if (TestMeta != Meta) + { + // CCW rotation of a CW rotation should produce no change in the meta + printf("Handler for blocktype %d (%s) fails CCW(CW) rotation test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta); + } + TestMeta = Handler->MetaRotateCW(Handler->MetaRotateCCW(Meta)); + if (TestMeta != Meta) + { + // 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) + { + // Double-mirroring should produce the same meta: + printf("Handler for blocktype %d (%s) fails XY mirror test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta); + } + TestMeta = Handler->MetaMirrorXZ(Handler->MetaMirrorXZ(Meta)); + if (TestMeta != Meta) + { + // Double-mirroring should produce the same meta: + printf("Handler for blocktype %d (%s) fails XZ mirror test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta); + } + TestMeta = Handler->MetaMirrorYZ(Handler->MetaMirrorYZ(Meta)); + if (TestMeta != Meta) + { + // 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) + { + // 2 CW rotations should be the same as XY, YZ mirroring: + printf("Handler for blocktype %d (%s) fails rotation-mirror test for meta %d: got back %d\n", Type, BlockName.c_str(), Meta, TestMeta); + } + } + } // for Type + printf("Block handlers test complete.\n"); + } +} g_BlockHandlerRotationTester; +//*/ + + + + + cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) { switch(a_BlockType) @@ -175,7 +262,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_QUARTZ_BLOCK: return new cBlockQuartzHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); - case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); // We need this to change pickups to an off lamp; else 1.7+ clients crash + case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE_GLOWING: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_REPEATER_OFF: return new cBlockRedstoneRepeaterHandler(a_BlockType); @@ -206,8 +293,10 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_TORCH: return new cBlockTorchHandler (a_BlockType); case E_BLOCK_TRAPDOOR: return new cBlockTrapdoorHandler (a_BlockType); case E_BLOCK_TNT: return new cBlockTNTHandler (a_BlockType); + case E_BLOCK_TRIPWIRE: return new cBlockTripwireHandler (a_BlockType); + case E_BLOCK_TRIPWIRE_HOOK: return new cBlockTripwireHookHandler (a_BlockType); case E_BLOCK_VINES: return new cBlockVineHandler (a_BlockType); - case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType); + case E_BLOCK_WALLSIGN: return new cBlockSignHandler (a_BlockType); // TODO: This needs a special handler case E_BLOCK_WATER: return new cBlockFluidHandler (a_BlockType); case E_BLOCK_WOODEN_BUTTON: return new cBlockButtonHandler (a_BlockType); case E_BLOCK_WOODEN_DOOR: return new cBlockDoorHandler (a_BlockType); diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index ad2ae29e5..4e745d413 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -7,12 +7,13 @@ class cBlockLeverHandler : - public cMetaRotator<cBlockHandler, 0x07, 0x04, 0x02, 0x03, 0x01, false> + public cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, false> { - typedef cMetaRotator<cBlockHandler, 0x07, 0x04, 0x02, 0x03, 0x01, false> super; + typedef cMetaRotator<cBlockHandler, 0x07, 0x04, 0x01, 0x03, 0x02, false> super; + public: - cBlockLeverHandler(BLOCKTYPE a_BlockType) - : cMetaRotator<cBlockHandler, 0x07, 0x04, 0x02, 0x03, 0x01, false>(a_BlockType) + cBlockLeverHandler(BLOCKTYPE a_BlockType) : + super(a_BlockType) { } @@ -21,7 +22,8 @@ public: // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x08); - a_ChunkInterface.SetBlock(a_WorldInterface, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_LEVER, Meta); // SetMeta doesn't work for unpowering levers, so setblock + a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); + a_WorldInterface.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); } @@ -103,7 +105,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); - return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn); + return (a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn); } @@ -132,7 +134,7 @@ public: case 0x05: return 0x06; // Ground rotation case 0x06: return 0x05; - default: return super::MetaRotateCCW(a_Meta); // Wall Rotation + default: return super::MetaRotateCW(a_Meta); // Wall Rotation } } } ; diff --git a/src/Blocks/BlockSign.h b/src/Blocks/BlockSign.h index 9d6fede21..f5630bdb0 100644 --- a/src/Blocks/BlockSign.h +++ b/src/Blocks/BlockSign.h @@ -75,13 +75,13 @@ public: virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override { - return (++a_Meta) & 0x0F; + return (a_Meta + 4) & 0x0f; } virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override { - return (--a_Meta) & 0x0F; + return (a_Meta + 12) & 0x0f; } virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override @@ -90,7 +90,7 @@ public: // There are 16 meta values which correspond to different directions. // These values are equated to angles on a circle; 0x08 = 180 degrees. - return (a_Meta < 0x08) ? 0x08 + a_Meta : 0x08 - a_Meta; + return (a_Meta < 0x08) ? (0x08 + a_Meta) : (0x08 - a_Meta); } diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index f3f2366fd..6c861be86 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -124,6 +124,12 @@ public: return E_BLOCK_AIR; } + + virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override + { + // Toggle the 4th bit - up / down: + return (a_Meta ^ 0x08); + } } ; @@ -167,15 +173,6 @@ public: ASSERT(!"Unhandled double slab type!"); return ""; } - - - virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override - { - NIBBLETYPE OtherMeta = a_Meta & 0x07; // Contains unrelated meta data. - - // 8th bit is up/down. 1 right-side-up, 0 is up-side-down. - return (a_Meta & 0x08) ? 0x00 + OtherMeta : 0x01 + OtherMeta; - } } ; diff --git a/src/Blocks/BlockStone.h b/src/Blocks/BlockStone.h index af4c6509a..cd5230f49 100644 --- a/src/Blocks/BlockStone.h +++ b/src/Blocks/BlockStone.h @@ -2,8 +2,6 @@ #pragma once #include "BlockHandler.h" -#include "../MersenneTwister.h" -#include "../World.h" diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 8ddec8de1..44c33c429 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -154,7 +154,11 @@ public: if ( (BlockInQuestion == E_BLOCK_GLASS) || + (BlockInQuestion == E_BLOCK_STAINED_GLASS) || (BlockInQuestion == E_BLOCK_FENCE) || + (BlockInQuestion == E_BLOCK_SOULSAND) || + (BlockInQuestion == E_BLOCK_MOB_SPAWNER) || + (BlockInQuestion == E_BLOCK_END_PORTAL_FRAME) || // Actual vanilla behaviour (BlockInQuestion == E_BLOCK_NETHER_BRICK_FENCE) || (BlockInQuestion == E_BLOCK_COBBLESTONE_WALL) ) diff --git a/src/Blocks/BlockTripwire.h b/src/Blocks/BlockTripwire.h new file mode 100644 index 000000000..3ab17bf4a --- /dev/null +++ b/src/Blocks/BlockTripwire.h @@ -0,0 +1,32 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockTripwireHandler : + public cBlockHandler +{ +public: + cBlockTripwireHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_ITEM_STRING, 1, 0)); + } + + virtual const char * GetStepSound(void) override + { + return ""; + } +}; + + + + diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h new file mode 100644 index 000000000..f849fb8ad --- /dev/null +++ b/src/Blocks/BlockTripwireHook.h @@ -0,0 +1,82 @@ +#pragma once + +#include "BlockHandler.h" +#include "MetaRotator.h" + + + + + +class cBlockTripwireHookHandler : + public cMetaRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01> +{ +public: + cBlockTripwireHookHandler(BLOCKTYPE a_BlockType) + : cMetaRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01>(a_BlockType) + { + } + + virtual bool GetPlacementBlockTypeMeta( + cChunkInterface & a_ChunkInterface, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = m_BlockType; + + a_BlockMeta = DirectionToMetadata(a_BlockFace); + + return true; + } + + inline static NIBBLETYPE DirectionToMetadata(eBlockFace a_Direction) + { + switch (a_Direction) + { + case BLOCK_FACE_XM: return 0x1; + case BLOCK_FACE_XP: return 0x3; + case BLOCK_FACE_ZM: return 0x2; + case BLOCK_FACE_ZP: return 0x0; + default: ASSERT(!"Unhandled tripwire hook direction!"); return 0x0; + } + } + + inline static eBlockFace MetadataToDirection(NIBBLETYPE a_Meta) + { + switch (a_Meta & 0x03) + { + case 0x1: return BLOCK_FACE_XM; + case 0x3: return BLOCK_FACE_XP; + case 0x2: return BLOCK_FACE_ZM; + case 0x0: return BLOCK_FACE_ZP; + default: ASSERT(!"Unhandled tripwire hook metadata!"); return BLOCK_FACE_NONE; + } + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // Reset meta to 0 + a_Pickups.push_back(cItem(E_BLOCK_TRIPWIRE_HOOK, 1, 0)); + } + + virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override + { + NIBBLETYPE Meta; + a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta); + + AddFaceDirection(a_RelX, a_RelY, a_RelZ, MetadataToDirection(Meta), true); + BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); + + return (a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn); + } + + virtual const char * GetStepSound(void) override + { + return "step.wood"; + } +}; + + + + diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index 650a216c0..251b28d03 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -46,4 +46,7 @@ public: virtual void SetTimeOfDay(Int64 a_TimeOfDay) = 0; + /** Wakes up the simulators for the specified block */ + virtual void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) = 0; + }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 335ce8315..5ff1c4e3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required (VERSION 2.8.2) project (MCServer) -include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/") -include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/jsoncpp/include") -include_directories (SYSTEM "${PROJECT_SOURCE_DIR}/../lib/polarssl/include") +include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/") +include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/jsoncpp/include") +include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/polarssl/include") set(FOLDERS OSSupport HTTPServer Items Blocks Protocol Generating PolarSSL++) set(FOLDERS ${FOLDERS} WorldStorage Mobs Entities Simulator UI BlockEntities Generating/Prefabs) @@ -12,6 +12,7 @@ set(BINDING_DEPENDECIES tolua ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/virtual_method_hooks.lua ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/AllToLua.pkg + Bindings/gen_LuaState_Call.lua Bindings/LuaFunctions.h Bindings/LuaWindow.h Bindings/Plugin.h @@ -79,16 +80,22 @@ set(BINDING_DEPENDECIES World.h ) +# List all the files that are generated as part of the Bindings build process +set (BINDING_OUTPUTS + ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.h + ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/LuaState_Call.inc +) + include_directories(Bindings) include_directories(.) if (WIN32) ADD_CUSTOM_COMMAND( - # add any new generated bindings here - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/Bindings.h + OUTPUT ${BINDING_OUTPUTS} # Copy the Lua DLL into the Bindings folder, so that tolua can run from there: - COMMAND copy /y ..\\..\\MCServer\\lua51.dll . + COMMAND ${CMAKE_COMMAND} -E copy_if_different ../../MCServer/lua51.dll ./lua51.dll # Regenerate bindings: COMMAND tolua -L virtual_method_hooks.lua -o Bindings.cpp -H Bindings.h AllToLua.pkg @@ -119,7 +126,8 @@ if (NOT MSVC) # lib dependencies are not included - + include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/polarssl/include") + #add cpp files here add_library(Bindings Bindings/Bindings @@ -134,7 +142,7 @@ if (NOT MSVC) Bindings/WebPlugin ) - target_link_libraries(Bindings lua sqlite tolualib) + target_link_libraries(Bindings lua sqlite tolualib polarssl) #clear file file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependecies.txt) @@ -260,4 +268,4 @@ endif () if (WIN32) target_link_libraries(${EXECUTABLE} expat tolualib ws2_32.lib Psapi.lib) endif() -target_link_libraries(${EXECUTABLE} md5 luaexpat iniFile jsoncpp polarssl zlib lua sqlite) +target_link_libraries(${EXECUTABLE} luaexpat iniFile jsoncpp polarssl zlib sqlite lua) diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 6ab49036d..0fee40cac 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1616,6 +1616,12 @@ void cChunk::AddBlockEntity(cBlockEntity * a_BlockEntity) cBlockEntity * cChunk::GetBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ) { + // Check that the query coords are within chunk bounds: + ASSERT(a_BlockX >= m_PosX * cChunkDef::Width); + ASSERT(a_BlockX < m_PosX * cChunkDef::Width + cChunkDef::Width); + ASSERT(a_BlockZ >= m_PosZ * cChunkDef::Width); + ASSERT(a_BlockZ < m_PosZ * cChunkDef::Width + cChunkDef::Width); + for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr) { if ( @@ -2695,7 +2701,7 @@ void cChunk::BroadcastChunkData(cChunkDataSerializer & a_Serializer, const cClie -void cChunk::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude) +void cChunk::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude) { for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) { @@ -2703,7 +2709,7 @@ void cChunk::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_ { continue; } - (*itr)->SendCollectPickup(a_Pickup, a_Player); + (*itr)->SendCollectEntity(a_Entity, a_Player); } // for itr - LoadedByClient[] } diff --git a/src/Chunk.h b/src/Chunk.h index 7664a7afd..e9d964e05 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -279,7 +279,7 @@ public: void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); void BroadcastChunkData (cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); - void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); + void BroadcastCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL); void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index d2ccca94e..c9fb0b59e 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -419,16 +419,16 @@ void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSeriali -void cChunkMap::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude) +void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Pickup.GetChunkX(), ZERO_CHUNK_Y, a_Pickup.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); if (Chunk == NULL) { return; } // It's perfectly legal to broadcast packets even to invalid chunks! - Chunk->BroadcastCollectPickup(a_Pickup, a_Player, a_Exclude); + Chunk->BroadcastCollectEntity(a_Entity, a_Player, a_Exclude); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 3ee0bab3c..433516490 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -70,6 +70,7 @@ public: void BroadcastBlockBreakAnimation(int a_entityID, int a_blockX, int a_blockY, int a_blockZ, char a_stage, const cClientHandle * a_Exclude = NULL); void BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude); void BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); + void BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL); diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 46083a8f1..efa734b44 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -30,7 +30,7 @@ #include "CompositeChat.h" #include "Items/ItemSword.h" -#include "md5/md5.h" +#include "polarssl/md5.h" @@ -239,18 +239,16 @@ AString cClientHandle::GenerateOfflineUUID(const AString & a_Username) // xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B // Generate an md5 checksum, and use it as base for the ID: - MD5 Checksum(a_Username); - AString UUID = Checksum.hexdigest(); - UUID[12] = '3'; // Version 3 UUID - UUID[16] = '8'; // Variant 1 UUID - - // Now the digest doesn't have the UUID slashes, but the client requires them, so add them into the appropriate positions: - UUID.insert(8, "-"); - UUID.insert(13, "-"); - UUID.insert(18, "-"); - UUID.insert(23, "-"); - - return UUID; + unsigned char MD5[16]; + md5((const unsigned char *)a_Username.c_str(), a_Username.length(), MD5); + MD5[6] &= 0x0f; // Need to trim to 4 bits only... + MD5[8] &= 0x0f; // ... otherwise %01x overflows into two chars + return Printf("%02x%02x%02x%02x-%02x%02x-3%01x%02x-8%01x%02x-%02x%02x%02x%02x%02x%02x", + MD5[0], MD5[1], MD5[2], MD5[3], + MD5[4], MD5[5], MD5[6], MD5[7], + MD5[8], MD5[9], MD5[10], MD5[11], + MD5[12], MD5[13], MD5[14], MD5[15] + ); } @@ -365,6 +363,9 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID) // Send scoreboard data World->GetScoreBoard().SendTo(*this); + // Send statistics + SendStatistics(m_Player->GetStatManager()); + // Delay the first ping until the client "settles down" // This should fix #889, "BadCast exception, cannot convert bit to fm" error in client cTimer t1; @@ -1085,12 +1086,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo void cClientHandle::FinishDigAnimation() { - if ( - !m_HasStartedDigging || // Hasn't received the DIG_STARTED packet - (m_LastDigBlockX == -1) || - (m_LastDigBlockY == -1) || - (m_LastDigBlockZ == -1) - ) + if (!m_HasStartedDigging) // Hasn't received the DIG_STARTED packet { return; } @@ -1227,9 +1223,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e { // A plugin won't let us eat, abort (send the proper packets to the client, too): m_Player->AbortEating(); - return; } - return; } else { @@ -2077,9 +2071,9 @@ void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializ -void cClientHandle::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) +void cClientHandle::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { - m_Protocol->SendCollectPickup(a_Pickup, a_Player); + m_Protocol->SendCollectEntity(a_Entity, a_Player); } @@ -2401,9 +2395,9 @@ void cClientHandle::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effec -void cClientHandle::SendRespawn(const cWorld & a_World) +void cClientHandle::SendRespawn(const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks) { - m_Protocol->SendRespawn(a_World); + m_Protocol->SendRespawn(a_World, a_ShouldIgnoreDimensionChecks); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 3e18cbdad..6f2c86b27 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -123,7 +123,7 @@ public: void SendChat (const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData = ""); void SendChat (const cCompositeChat & a_Message); void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer); - void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player); + void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player); void SendDestroyEntity (const cEntity & a_Entity); void SendDisconnect (const AString & a_Reason); void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ); @@ -156,7 +156,7 @@ public: void SendPlayerSpawn (const cPlayer & a_Player); void SendPluginMessage (const AString & a_Channel, const AString & a_Message); // Exported in ManualBindings.cpp void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID); - void SendRespawn (const cWorld & a_World); + void SendRespawn (const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks = false); void SendExperience (void); void SendExperienceOrb (const cExpOrb & a_ExpOrb); void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode); diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 1d539679c..47a0876fc 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -3,6 +3,7 @@ #include "Player.h" #include "ArrowEntity.h" #include "../Chunk.h" +#include "FastRandom.h" @@ -24,9 +25,9 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a SetYawFromSpeed(); SetPitchFromSpeed(); LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", - m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetYaw(), GetPitch() - ); + m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), + GetYaw(), GetPitch() + ); } @@ -44,6 +45,10 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) : m_bIsCollected(false), m_HitBlockPos(0, 0, 0) { + if (a_Player.IsGameModeCreative()) + { + m_PickupState = psInCreative; + } } @@ -101,7 +106,14 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1); // Broadcast successful hit sound - m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect( + "random.successful_hit", + (int)std::floor(GetPosX() * 8.0), + (int)std::floor(GetPosY() * 8.0), + (int)std::floor(GetPosZ() * 8.0), + 0.5f, + 0.75f + ((float)((GetUniqueID() * 23) % 32)) / 64.0f + ); Destroy(); } @@ -112,16 +124,33 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) void cArrowEntity::CollectedBy(cPlayer * a_Dest) { - if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest))) + if (m_IsInGround && !m_bIsCollected && CanPickup(*a_Dest)) { - int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); - if (NumAdded > 0) // Only play effects if there was space in inventory + // Do not add the arrow to the inventory when the player is in creative: + if (!a_Dest->IsGameModeCreative()) { - m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest); - // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) - m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - m_bIsCollected = true; + int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW); + if (NumAdded == 0) + { + // No space in the inventory + return; + } } + + // TODO: BroadcastCollectPickup needs a cPickup, which we don't have + // m_World->BroadcastCollectPickup(*this, *a_Dest); + + m_bIsCollected = true; + + cFastRandom Random; + m_World->BroadcastSoundEffect( + "random.pop", + (int)std::floor(GetPosX() * 8.0), + (int)std::floor(GetPosY() * 8), + (int)std::floor(GetPosZ() * 8), + 0.2F, + ((Random.NextFloat(1.0F) - Random.NextFloat(1.0F)) * 0.7F + 1.0F) * 2.0F + ); } } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 1683aa209..26823924f 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1090,7 +1090,10 @@ void cEntity::HandleAir(void) if (IsSubmerged()) { - SetSpeedY(1); // Float in the water + if (!IsPlayer()) // Players control themselves + { + SetSpeedY(1); // Float in the water + } // Either reduce air level or damage player if (m_AirLevel < 1) diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 0fd006485..10b6bbd5c 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -30,7 +30,7 @@ public: virtual bool Item(cEntity * a_Entity) override { - if (!a_Entity->IsPickup() || (a_Entity->GetUniqueID() == m_Pickup->GetUniqueID()) || a_Entity->IsDestroyed()) + if (!a_Entity->IsPickup() || (a_Entity->GetUniqueID() <= m_Pickup->GetUniqueID()) || a_Entity->IsDestroyed()) { return false; } @@ -38,10 +38,31 @@ public: Vector3d EntityPos = a_Entity->GetPosition(); double Distance = (EntityPos - m_Position).Length(); - if ((Distance < 1.2) && ((cPickup *)a_Entity)->GetItem().IsEqual(m_Pickup->GetItem())) + cItem & Item = ((cPickup *)a_Entity)->GetItem(); + if ((Distance < 1.2) && Item.IsEqual(m_Pickup->GetItem())) { - m_Pickup->GetItem().AddCount(((cPickup *)a_Entity)->GetItem().m_ItemCount); - a_Entity->Destroy(); + short CombineCount = Item.m_ItemCount; + if ((CombineCount + m_Pickup->GetItem().m_ItemCount) > Item.GetMaxStackSize()) + { + CombineCount = Item.GetMaxStackSize() - m_Pickup->GetItem().m_ItemCount; + } + + if (CombineCount <= 0) + { + return false; + } + + m_Pickup->GetItem().AddCount((char)CombineCount); + Item.m_ItemCount -= CombineCount; + + if (Item.m_ItemCount <= 0) + { + a_Entity->Destroy(); + } + else + { + a_Entity->GetWorld()->BroadcastEntityMetadata(*a_Entity); + } m_FoundMatchingPickup = true; } return false; @@ -129,7 +150,7 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) } } - if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + if (!IsDestroyed() && (m_Item.m_ItemCount < m_Item.GetMaxStackSize())) // Don't combine into an already full pickup { cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries @@ -206,7 +227,7 @@ bool cPickup::CollectedBy(cPlayer * a_Dest) m_World->BroadcastCollectPickup(*this, *a_Dest); // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) m_World->BroadcastSoundEffect("random.pop",(int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); - if (m_Item.m_ItemCount == 0) + if (m_Item.m_ItemCount <= 0) { // All of the pickup has been collected, schedule the pickup for destroying m_bCollected = true; diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index e1e03fded..dbb8cd26c 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1,4 +1,4 @@ - + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Player.h" @@ -8,6 +8,7 @@ #include "../World.h" #include "../Bindings/PluginManager.h" #include "../BlockEntities/BlockEntity.h" +#include "../BlockEntities/EnderChestEntity.h" #include "../GroupManager.h" #include "../Group.h" #include "../Root.h" @@ -37,15 +38,16 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : super(etPlayer, 0.6, 1.8) , m_bVisible(true) , m_FoodLevel(MAX_FOOD_LEVEL) - , m_FoodSaturationLevel(5) + , m_FoodSaturationLevel(5.0) , m_FoodTickTimer(0) - , m_FoodExhaustionLevel(0) + , m_FoodExhaustionLevel(0.0) , m_FoodPoisonedTicksRemaining(0) , m_LastJumpHeight(0) , m_LastGroundHeight(0) , m_bTouchGround(false) , m_Stance(0.0) , m_Inventory(*this) + , m_EnderChestContents(9, 3) , m_CurrentWindow(NULL) , m_InventoryWindow(NULL) , m_Color('-') @@ -71,6 +73,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_FloaterID(-1) , m_Team(NULL) , m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL) + , m_bIsTeleporting(false) { LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d", a_PlayerName.c_str(), a_Client->GetIPString().c_str(), @@ -225,7 +228,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) SendExperience(); } - if (GetPosition() != m_LastPos) // Change in position from last tick? + if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); @@ -412,6 +415,7 @@ void cPlayer::StartChargingBow(void) LOGD("Player \"%s\" started charging their bow", GetName().c_str()); m_IsChargingBow = true; m_BowCharge = 0; + m_World->BroadcastEntityMetadata(*this, m_ClientHandle); } @@ -424,6 +428,8 @@ int cPlayer::FinishChargingBow(void) int res = m_BowCharge; m_IsChargingBow = false; m_BowCharge = 0; + m_World->BroadcastEntityMetadata(*this, m_ClientHandle); + return res; } @@ -436,6 +442,7 @@ void cPlayer::CancelChargingBow(void) LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge); m_IsChargingBow = false; m_BowCharge = 0; + m_World->BroadcastEntityMetadata(*this, m_ClientHandle); } @@ -517,7 +524,15 @@ void cPlayer::Heal(int a_Health) void cPlayer::SetFoodLevel(int a_FoodLevel) { - m_FoodLevel = std::max(0, std::min(a_FoodLevel, (int)MAX_FOOD_LEVEL)); + int FoodLevel = std::max(0, std::min(a_FoodLevel, (int)MAX_FOOD_LEVEL)); + + if (cRoot::Get()->GetPluginManager()->CallHookPlayerFoodLevelChange(*this, FoodLevel)) + { + m_FoodSaturationLevel = 5.0; + return; + } + + m_FoodLevel = FoodLevel; SendHealth(); } @@ -567,11 +582,9 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) { return false; } - - m_FoodLevel = std::min(a_Food + m_FoodLevel, (int)MAX_FOOD_LEVEL); - m_FoodSaturationLevel = std::min(m_FoodSaturationLevel + a_Saturation, (double)m_FoodLevel); - - SendHealth(); + + SetFoodSaturationLevel(m_FoodSaturationLevel + a_Saturation); + SetFoodLevel(m_FoodLevel + a_Food); return true; } @@ -965,14 +978,15 @@ void cPlayer::Respawn(void) // Reset food level: m_FoodLevel = MAX_FOOD_LEVEL; - m_FoodSaturationLevel = 5; + m_FoodSaturationLevel = 5.0; + m_FoodExhaustionLevel = 0.0; // Reset Experience m_CurrentXp = 0; m_LifetimeTotalXp = 0; // ToDo: send score to client? How? - m_ClientHandle->SendRespawn(*m_World); + m_ClientHandle->SendRespawn(*m_World, true); // Extinguish the fire: StopBurning(); @@ -1222,6 +1236,7 @@ void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) SetPosition(a_PosX, a_PosY, a_PosZ); m_LastGroundHeight = (float)a_PosY; m_LastJumpHeight = (float)a_PosY; + m_bIsTeleporting = true; m_World->BroadcastTeleportEntity(*this, GetClientHandle()); m_ClientHandle->SendPlayerMoveLook(); @@ -1739,6 +1754,7 @@ bool cPlayer::LoadFromDisk() } m_Inventory.LoadFromJson(root["inventory"]); + cEnderChestEntity::LoadFromJson(root["enderchestinventory"], m_EnderChestContents); m_LoadedWorldName = root.get("world", "world").asString(); @@ -1776,20 +1792,24 @@ bool cPlayer::SaveToDisk() Json::Value JSON_Inventory; m_Inventory.SaveToJson(JSON_Inventory); + Json::Value JSON_EnderChestInventory; + cEnderChestEntity::SaveToJson(JSON_EnderChestInventory, m_EnderChestContents); + Json::Value root; - root["position"] = JSON_PlayerPosition; - root["rotation"] = JSON_PlayerRotation; - root["inventory"] = JSON_Inventory; - root["health"] = m_Health; - root["xpTotal"] = m_LifetimeTotalXp; - root["xpCurrent"] = m_CurrentXp; - root["air"] = m_AirLevel; - root["food"] = m_FoodLevel; - root["foodSaturation"] = m_FoodSaturationLevel; - root["foodTickTimer"] = m_FoodTickTimer; - root["foodExhaustion"] = m_FoodExhaustionLevel; - root["world"] = GetWorld()->GetName(); - root["isflying"] = IsFlying(); + root["position"] = JSON_PlayerPosition; + root["rotation"] = JSON_PlayerRotation; + root["inventory"] = JSON_Inventory; + root["enderchestinventory"] = JSON_EnderChestInventory; + root["health"] = m_Health; + root["xpTotal"] = m_LifetimeTotalXp; + root["xpCurrent"] = m_CurrentXp; + root["air"] = m_AirLevel; + root["food"] = m_FoodLevel; + root["foodSaturation"] = m_FoodSaturationLevel; + root["foodTickTimer"] = m_FoodTickTimer; + root["foodExhaustion"] = m_FoodExhaustionLevel; + root["world"] = GetWorld()->GetName(); + root["isflying"] = IsFlying(); if (m_GameMode == GetWorld()->GetGameMode()) { @@ -1891,16 +1911,13 @@ void cPlayer::TickBurning(cChunk & a_Chunk) void cPlayer::HandleFood(void) { // Ref.: http://www.minecraftwiki.net/wiki/Hunger - + if (IsGameModeCreative()) { // Hunger is disabled for Creative return; } - - // Remember the food level before processing, for later comparison - int LastFoodLevel = m_FoodLevel; - + // Heal or damage, based on the food level, using the m_FoodTickTimer: if ((m_FoodLevel > 17) || (m_FoodLevel <= 0)) { @@ -1909,11 +1926,11 @@ void cPlayer::HandleFood(void) { m_FoodTickTimer = 0; - if (m_FoodLevel >= 17) + if ((m_FoodLevel > 17) && (GetHealth() < GetMaxHealth())) { // Regenerate health from food, incur 3 pts of food exhaustion: Heal(1); - m_FoodExhaustionLevel += 3; + m_FoodExhaustionLevel += 3.0; } else if ((m_FoodLevel <= 0) && (m_Health > 1)) { @@ -1922,7 +1939,7 @@ void cPlayer::HandleFood(void) } } } - + // Apply food poisoning food exhaustion: if (m_FoodPoisonedTicksRemaining > 0) { @@ -1935,24 +1952,19 @@ void cPlayer::HandleFood(void) } // Apply food exhaustion that has accumulated: - if (m_FoodExhaustionLevel >= 4) + if (m_FoodExhaustionLevel >= 4.0) { - m_FoodExhaustionLevel -= 4; + m_FoodExhaustionLevel -= 4.0; - if (m_FoodSaturationLevel >= 1) + if (m_FoodSaturationLevel >= 1.0) { - m_FoodSaturationLevel -= 1; + m_FoodSaturationLevel -= 1.0; } else { - m_FoodLevel = std::max(m_FoodLevel - 1, 0); + SetFoodLevel(m_FoodLevel - 1); } } - - if (m_FoodLevel != LastFoodLevel) - { - SendHealth(); - } } @@ -2075,6 +2087,11 @@ void cPlayer::ApplyFoodExhaustionFromMovement() { return; } + if (m_bIsTeleporting) + { + m_bIsTeleporting = false; + return; + } // If riding anything, apply no food exhaustion if (m_AttachedTo != NULL) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index b2142a18b..f247ac2f9 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -124,6 +124,9 @@ public: inline double GetStance(void) const { return GetPosY() + 1.62; } // tolua_export // TODO: Proper stance when crouching etc. inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export inline const cInventory & GetInventory(void) const { return m_Inventory; } + + /** Gets the contents of the player's associated enderchest */ + cItemGrid & GetEnderChestContents(void) { return m_EnderChestContents; } inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); } // tolua_export @@ -404,7 +407,7 @@ public: // cEntity overrides: virtual bool IsCrouched (void) const { return m_IsCrouched; } virtual bool IsSprinting(void) const { return m_IsSprinting; } - virtual bool IsRclking (void) const { return IsEating(); } + virtual bool IsRclking (void) const { return IsEating() || IsChargingBow(); } virtual void Detach(void); @@ -449,7 +452,13 @@ protected: float m_LastGroundHeight; bool m_bTouchGround; double m_Stance; + + /** Stores the player's inventory, consisting of crafting grid, hotbar, and main slots */ cInventory m_Inventory; + + /** An item grid that stores the player specific enderchest contents */ + cItemGrid m_EnderChestContents; + cWindow * m_CurrentWindow; cWindow * m_InventoryWindow; @@ -510,8 +519,6 @@ protected: cStatManager m_Stats; - - /** Sets the speed and sends it to the client, so that they are forced to move so. */ virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; @@ -546,6 +553,11 @@ protected: Default save interval is #defined in PLAYER_INVENTORY_SAVE_INTERVAL */ unsigned int m_TicksUntilNextSave; + /** Flag used by food handling system to determine whether a teleport has just happened + Will not apply food penalties if found to be true; will set to false after processing + */ + bool m_bIsTeleporting; + } ; // tolua_export diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index 2cb204ccf..8add9610c 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -5,7 +5,8 @@ #include "Item.h" #include <fstream> -#include <sstream> + +#define FURNACE_RECIPE_FILE "furnace.txt" @@ -54,128 +55,207 @@ void cFurnaceRecipe::ReloadRecipes(void) ClearRecipes(); LOGD("Loading furnace recipes..."); - std::ifstream f; - char a_File[] = "furnace.txt"; - f.open(a_File, std::ios::in); - + std::ifstream f(FURNACE_RECIPE_FILE, std::ios::in); if (!f.good()) { - f.close(); - LOG("Could not open the furnace recipes file \"%s\"", a_File); + LOG("Could not open the furnace recipes file \"%s\". No furnace recipes are available.", FURNACE_RECIPE_FILE); return; } + + unsigned int LineNum = 0; + AString ParsingLine; - // TODO: Replace this messy parse with a high-level-structured one (ReadLine / ProcessLine) - bool bSyntaxError = false; - while (f.good()) + while (std::getline(f, ParsingLine)) { - char c; + LineNum++; + ParsingLine.erase(std::remove_if(ParsingLine.begin(), ParsingLine.end(), isspace), ParsingLine.end()); // Remove ALL whitespace from the line + if (ParsingLine.empty()) + { + continue; + } - ////////////////////////////////////////////////////////////////////////// - // comments - f >> c; - f.unget(); - if( c == '#' ) + switch (ParsingLine[0]) { - while( f.good() && c != '\n' ) + case '#': { - f.get( c ); + // Comment + break; } - continue; - } + + case '!': + { + AddFuelFromLine(ParsingLine, LineNum); + break; + } + + default: + { + AddRecipeFromLine(ParsingLine, LineNum); + break; + } + } // switch (ParsingLine[0]) + } // while (getline(ParsingLine)) + + LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); +} + + + + + +void cFurnaceRecipe::AddFuelFromLine(const AString & a_Line, int a_LineNum) +{ + // Fuel + int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0; + AString::size_type BeginPos = 1; // Begin at one after exclamation mark (bang) + + if ( + !ReadMandatoryNumber(BeginPos, ":", a_Line, a_LineNum, IItemID) || // Read item ID + !ReadOptionalNumbers(BeginPos, ":", "=", a_Line, a_LineNum, IItemCount, IItemHealth) || // Read item count (and optionally health) + !ReadMandatoryNumber(BeginPos, "0123456789", a_Line, a_LineNum, IBurnTime, true) // Read item burn time - last value + ) + { + return; + } + + // Add to fuel list: + Fuel F; + F.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth); + F.BurnTime = IBurnTime; + m_pState->Fuel.push_back(F); +} + + + + + +void cFurnaceRecipe::AddRecipeFromLine(const AString & a_Line, int a_LineNum) +{ + int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0; + int OItemID = 0, OItemCount = 0, OItemHealth = 0; + AString::size_type BeginPos = 0; // Begin at start of line + + if ( + !ReadMandatoryNumber(BeginPos, ":", a_Line, a_LineNum, IItemID) || // Read item ID + !ReadOptionalNumbers(BeginPos, ":", "@", a_Line, a_LineNum, IItemCount, IItemHealth) || // Read item count (and optionally health) + !ReadMandatoryNumber(BeginPos, "=", a_Line, a_LineNum, IBurnTime) || // Read item burn time + !ReadMandatoryNumber(BeginPos, ":", a_Line, a_LineNum, OItemID) || // Read result ID + !ReadOptionalNumbers(BeginPos, ":", "012456789", a_Line, a_LineNum, OItemCount, OItemHealth, true) // Read result count (and optionally health) - last value + ) + { + return; + } + + // Add to recipe list + Recipe R; + R.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth); + R.Out = new cItem((ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth); + R.CookTime = IBurnTime; + m_pState->Recipes.push_back(R); +} + + + - ////////////////////////////////////////////////////////////////////////// - // Line breaks - f.get( c ); - while( f.good() && ( c == '\n' || c == '\r' ) ) { f.get( c ); } - if (f.eof()) +void cFurnaceRecipe::PrintParseError(unsigned int a_Line, size_t a_Position, const AString & a_CharactersMissing) +{ + LOGWARN("Error parsing furnace recipes at line %i pos " SIZE_T_FMT ": missing '%s'", a_Line, a_Position, a_CharactersMissing.c_str()); +} + + + + + +bool cFurnaceRecipe::ReadMandatoryNumber(AString::size_type & a_Begin, const AString & a_Delimiter, const AString & a_Text, unsigned int a_Line, int & a_Value, bool a_IsLastValue) +{ + // TODO: replace atoi with std::stoi + AString::size_type End; + if (a_IsLastValue) + { + End = a_Text.find_first_not_of(a_Delimiter, a_Begin); + } + else + { + End = a_Text.find_first_of(a_Delimiter, a_Begin); + if (End == AString::npos) { - break; + PrintParseError(a_Line, a_Begin, a_Delimiter); + return false; } - f.unget(); + } + + // stoi won't throw an exception if the string is alphanumeric, we should check for this + if (!DoesStringContainOnlyNumbers(a_Text.substr(a_Begin, End - a_Begin))) + { + PrintParseError(a_Line, a_Begin, "number"); + return false; + } + a_Value = atoi(a_Text.substr(a_Begin, End - a_Begin).c_str()); + + a_Begin = End + 1; // Jump over delimiter + return true; +} + + + + - ////////////////////////////////////////////////////////////////////////// - // Check for fuel - f >> c; - if( c == '!' ) // It's fuel :) +bool cFurnaceRecipe::ReadOptionalNumbers(AString::size_type & a_Begin, const AString & a_DelimiterOne, const AString & a_DelimiterTwo, const AString & a_Text, unsigned int a_Line, int & a_ValueOne, int & a_ValueTwo, bool a_IsLastValue) +{ + // TODO: replace atoi with std::stoi + AString::size_type End, Begin = a_Begin; + + End = a_Text.find_first_of(a_DelimiterOne, Begin); + if (End != AString::npos) + { + if (DoesStringContainOnlyNumbers(a_Text.substr(Begin, End - Begin))) { - // Read item - int IItemID = 0, IItemCount = 0, IItemHealth = 0; - f >> IItemID; - f >> c; if( c != ':' ) { bSyntaxError = true; break; } - f >> IItemCount; - - // Optional health - f >> c; - if( c != ':' ) - f.unget(); + a_ValueOne = std::atoi(a_Text.substr(Begin, End - Begin).c_str()); + Begin = End + 1; + + if (a_IsLastValue) + { + End = a_Text.find_first_not_of(a_DelimiterTwo, Begin); + } else { - f >> IItemHealth; + End = a_Text.find_first_of(a_DelimiterTwo, Begin); + if (End == AString::npos) + { + PrintParseError(a_Line, Begin, a_DelimiterTwo); + return false; + } } - // Burn time - int BurnTime; - f >> c; if( c != '=' ) { bSyntaxError = true; break; } - f >> BurnTime; + // stoi won't throw an exception if the string is alphanumeric, we should check for this + if (!DoesStringContainOnlyNumbers(a_Text.substr(Begin, End - Begin))) + { + PrintParseError(a_Line, Begin, "number"); + return false; + } + a_ValueTwo = atoi(a_Text.substr(Begin, End - Begin).c_str()); - // Add to fuel list - Fuel F; - F.In = new cItem( (ENUM_ITEM_ID) IItemID, (char)IItemCount, (short)IItemHealth ); - F.BurnTime = BurnTime; - m_pState->Fuel.push_back( F ); - continue; + a_Begin = End + 1; // Jump over delimiter + return true; } - f.unget(); - - ////////////////////////////////////////////////////////////////////////// - // Read items - int IItemID = 0, IItemCount = 0, IItemHealth = 0; - f >> IItemID; - f >> c; if( c != ':' ) { bSyntaxError = true; break; } - f >> IItemCount; - - // Optional health - f >> c; - if( c != ':' ) - f.unget(); else { - f >> IItemHealth; + return ReadMandatoryNumber(a_Begin, a_DelimiterTwo, a_Text, a_Line, a_ValueOne, a_IsLastValue); } + } + + return ReadMandatoryNumber(a_Begin, a_DelimiterTwo, a_Text, a_Line, a_ValueOne, a_IsLastValue); +} - int CookTime; - f >> c; if( c != '@' ) { bSyntaxError = true; break; } - f >> CookTime; - int OItemID = 0, OItemCount = 0, OItemHealth = 0; - f >> c; if( c != '=' ) { bSyntaxError = true; break; } - f >> OItemID; - f >> c; if( c != ':' ) { bSyntaxError = true; break; } - f >> OItemCount; - // Optional health - f >> c; - if( c != ':' ) - f.unget(); - else - { - f >> OItemHealth; - } - // Add to recipe list - Recipe R; - R.In = new cItem( (ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth ); - R.Out = new cItem( (ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth ); - R.CookTime = CookTime; - m_pState->Recipes.push_back( R ); - } - if (bSyntaxError) - { - LOGERROR("ERROR: FurnaceRecipe, syntax error" ); - } - LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size()); + +bool cFurnaceRecipe::DoesStringContainOnlyNumbers(const AString & a_String) +{ + // TODO: replace this with std::all_of(a_String.begin(), a_String.end(), isdigit) + return (a_String.find_first_not_of("0123456789") == AString::npos); } diff --git a/src/FurnaceRecipe.h b/src/FurnaceRecipe.h index 2f91e9bcb..77ed35a57 100644 --- a/src/FurnaceRecipe.h +++ b/src/FurnaceRecipe.h @@ -41,6 +41,36 @@ public: private: void ClearRecipes(void); + /** Parses the fuel contained in the line, adds it to m_pState's fuels. + Logs a warning to the console on input error. */ + void AddFuelFromLine(const AString & a_Line, int a_LineNum); + + /** Parses the recipe contained in the line, adds it to m_pState's recipes. + Logs a warning to the console on input error. */ + void AddRecipeFromLine(const AString & a_Line, int a_LineNum); + + /** Calls LOGWARN with the line, position, and error */ + static void PrintParseError(unsigned int a_Line, size_t a_Position, const AString & a_CharactersMissing); + + /** Reads a number from a string given, starting at a given position and ending at a delimiter given + Updates beginning position to the delimiter found + 1, and updates the value to the one read + If it encounters a substring that is not fully numeric, it will call SetParseError() and return false; the caller should abort processing + Otherwise, the function will return true + */ + static bool ReadMandatoryNumber(AString::size_type & a_Begin, const AString & a_Delimiter, const AString & a_Text, unsigned int a_Line, int & a_Value, bool a_IsLastValue = false); + + /** Reads two numbers from a string given, starting at a given position and ending at the first delimiter given, then again (with an updated position) until the second delimiter given + Updates beginning position to the second delimiter found + 1, and updates the values to the ones read + If it encounters a substring that is not fully numeric whilst reading the second value, it will call SetParseError() and return false; the caller should abort processing + If this happens whilst reading the first value, it will call ReadMandatoryNumber() with the appropriate position, as this may legitimately occur with the optional value and AString::find_first_of finding the incorrect delimiter. It will return the result of ReadMandatoryNumber() + True will be returned definitively for an optional value that is valid + */ + static bool ReadOptionalNumbers(AString::size_type & a_Begin, const AString & a_DelimiterOne, const AString & a_DelimiterTwo, const AString & a_Text, unsigned int a_Line, int & a_ValueOne, int & a_ValueTwo, bool a_IsLastValue = false); + + /** Uses std::all_of to determine if a string contains only digits */ + static bool DoesStringContainOnlyNumbers(const AString & a_String); + + struct sFurnaceRecipeState; sFurnaceRecipeState * m_pState; }; diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 2ab1455b9..7d876909a 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -211,6 +211,17 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const Vector3i & a_Placement, int a_NumR int ChunkStartZ = a_Dest.GetChunkZ() * cChunkDef::Width; Placement.Move(-ChunkStartX, 0, -ChunkStartZ); const cBlockArea & Image = m_BlockArea[a_NumRotations]; + + // If the placement is outside this chunk, bail out: + if ( + (Placement.x > cChunkDef::Width) || (Placement.x + Image.GetSizeX() < 0) || + (Placement.z > cChunkDef::Width) || (Placement.z + Image.GetSizeZ() < 0) + ) + { + return; + } + + // Write the image: a_Dest.WriteBlockArea(Image, Placement.x, Placement.y, Placement.z, m_MergeStrategy); // If requested, draw the floor (from the bottom of the prefab down to the nearest non-air) diff --git a/src/Generating/Prefabs/AlchemistVillagePrefabs.cpp b/src/Generating/Prefabs/AlchemistVillagePrefabs.cpp index 5cb864d53..976f8490e 100644 --- a/src/Generating/Prefabs/AlchemistVillagePrefabs.cpp +++ b/src/Generating/Prefabs/AlchemistVillagePrefabs.cpp @@ -58,9 +58,9 @@ const cPrefab::sDef g_AlchemistVillagePrefabs[] = "o: 50: 4\n" /* torch */ "p: 13: 0\n" /* gravel */ "q: 5: 0\n" /* wood */ - "r: 96:12\n" /* trapdoor */ + "r: 96: 8\n" /* trapdoor */ "s:128: 5\n" /* sandstonestairs */ - "t:107: 0\n" /* fencegate */ + "t:107: 2\n" /* fencegate */ "u:128: 4\n" /* sandstonestairs */ "v:134: 3\n" /* 134 */ "w: 85: 0\n" /* fence */ @@ -288,7 +288,7 @@ const cPrefab::sDef g_AlchemistVillagePrefabs[] = "d: 13: 0\n" /* gravel */ "e: 5: 0\n" /* wood */ "f:128: 5\n" /* sandstonestairs */ - "g:107: 0\n" /* fencegate */ + "g:107: 2\n" /* fencegate */ "h:128: 4\n" /* sandstonestairs */ "i:134: 1\n" /* 134 */ "j:134: 3\n" /* 134 */ @@ -298,7 +298,7 @@ const cPrefab::sDef g_AlchemistVillagePrefabs[] = "n:134: 5\n" /* 134 */ "o:134: 7\n" /* 134 */ "p:134: 4\n" /* 134 */ - "q:107: 5\n" /* fencegate */ + "q:107: 1\n" /* fencegate */ "r: 64: 1\n" /* wooddoorblock */ "s: 65: 3\n" /* ladder */ "t: 50: 3\n" /* torch */ @@ -2195,7 +2195,7 @@ const cPrefab::sDef g_AlchemistVillagePrefabs[] = 0, // MoveToGround: - false, + true, }, // LittleHouse8 diff --git a/src/Generating/Prefabs/JapaneseVillagePrefabs.cpp b/src/Generating/Prefabs/JapaneseVillagePrefabs.cpp index 79f7a5272..d22153d87 100644 --- a/src/Generating/Prefabs/JapaneseVillagePrefabs.cpp +++ b/src/Generating/Prefabs/JapaneseVillagePrefabs.cpp @@ -294,7 +294,7 @@ const cPrefab::sDef g_JapaneseVillagePrefabs[] = 0, // MoveToGround: - false, + true, }, // Farm diff --git a/src/Generating/Prefabs/PlainsVillagePrefabs.cpp b/src/Generating/Prefabs/PlainsVillagePrefabs.cpp index 9e5e06769..bba493bf1 100644 --- a/src/Generating/Prefabs/PlainsVillagePrefabs.cpp +++ b/src/Generating/Prefabs/PlainsVillagePrefabs.cpp @@ -356,6 +356,7 @@ const cPrefab::sDef g_PlainsVillagePrefabs[] = "e: 8: 0\n" /* water */ "f: 50: 5\n" /* torch */ "g: 59: 7\n" /* crops */ + "h:111: 0\n" /* lilypad */ "m: 19: 0\n" /* sponge */, // Block data: @@ -407,7 +408,7 @@ const cPrefab::sDef g_PlainsVillagePrefabs[] = /* 3 */ ".g.......gg.gg." /* 4 */ ".gg..g...gg.gg." /* 5 */ ".gg..g...gg.gg." - /* 6 */ "..g..g...gg.gg." + /* 6 */ "..g..g...gghgg." /* 7 */ "..g.g....gg.gg." /* 8 */ "f.....f.f.....f" diff --git a/src/Globals.h b/src/Globals.h index c5768facf..0c11429bd 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -71,9 +71,24 @@ #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex))) - #define SIZE_T_FMT "%zu" - #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" - #define SIZE_T_FMT_HEX "%zx" + #if defined(_WIN32) + // We're compiling on MinGW, which uses an old MSVCRT library that has no support for size_t printfing. + // We need direct size formats: + #if defined(_WIN64) + #define SIZE_T_FMT "%I64u" + #define SIZE_T_FMT_PRECISION(x) "%" #x "I64u" + #define SIZE_T_FMT_HEX "%I64x" + #else + #define SIZE_T_FMT "%u" + #define SIZE_T_FMT_PRECISION(x) "%" #x "u" + #define SIZE_T_FMT_HEX "%x" + #endif + #else + // We're compiling on Linux, so we can use libc's size_t printf format: + #define SIZE_T_FMT "%zu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" + #define SIZE_T_FMT_HEX "%zx" + #endif #define NORETURN __attribute((__noreturn__)) diff --git a/src/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp index d288c83c9..036b2e042 100644 --- a/src/HTTPServer/HTTPServer.cpp +++ b/src/HTTPServer/HTTPServer.cpp @@ -179,6 +179,8 @@ bool cHTTPServer::Initialize(const AString & a_PortsIPv4, const AString & a_Port // Open up requested ports: bool HasAnyPort; + m_ListenThreadIPv4.SetReuseAddr(true); + m_ListenThreadIPv6.SetReuseAddr(true); HasAnyPort = m_ListenThreadIPv4.Initialize(a_PortsIPv4); HasAnyPort = m_ListenThreadIPv6.Initialize(a_PortsIPv6) || HasAnyPort; if (!HasAnyPort) diff --git a/src/Item.cpp b/src/Item.cpp index d6e8b224a..56ceae0b7 100644 --- a/src/Item.cpp +++ b/src/Item.cpp @@ -1,4 +1,4 @@ - + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Item.h" diff --git a/src/Items/ItemBow.h b/src/Items/ItemBow.h index 821e2ab26..940338d0f 100644 --- a/src/Items/ItemBow.h +++ b/src/Items/ItemBow.h @@ -46,20 +46,17 @@ public: { // Actual shot - produce the arrow with speed based on the ticks that the bow was charged ASSERT(a_Player != NULL); - + int BowCharge = a_Player->FinishChargingBow(); - double Force = (double)BowCharge / 20; - Force = (Force * Force + 2 * Force) / 3; // This formula is used by the 1.6.2 client + double Force = (double)BowCharge / 20.0; + Force = (Force * Force + 2.0 * Force) / 3.0; // This formula is used by the 1.6.2 client if (Force < 0.1) { // Too little force, ignore the shot return; } - if (Force > 1) - { - Force = 1; - } - + Force = std::max(Force, 1.0); + // Create the arrow entity: cArrowEntity * Arrow = new cArrowEntity(*a_Player, Force * 2); if (Arrow == NULL) @@ -72,8 +69,16 @@ public: Arrow = NULL; return; } - a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow); - a_Player->GetWorld()->BroadcastSoundEffect("random.bow", (int)a_Player->GetPosX() * 8, (int)a_Player->GetPosY() * 8, (int)a_Player->GetPosZ() * 8, 0.5, (float)Force); + + cFastRandom Random; + a_Player->GetWorld()->BroadcastSoundEffect( + "random.bow", + (int)std::floor(a_Player->GetPosX() * 8.0), + (int)std::floor(a_Player->GetPosY() * 8.0), + (int)std::floor(a_Player->GetPosZ() * 8.0), + 1.0F, + 1.0F / (Random.NextFloat(1.0F) * 0.4F + 1.2F) + (float)Force * 0.5F + ); if (!a_Player->IsGameModeCreative()) { diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index f639423ae..423039cf4 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -44,6 +44,7 @@ #include "ItemSign.h" #include "ItemMobHead.h" #include "ItemSpawnEgg.h" +#include "ItemString.h" #include "ItemSugarcane.h" #include "ItemSword.h" @@ -62,7 +63,7 @@ cItemHandler * cItemHandler::m_ItemHandler[2268]; cItemHandler * cItemHandler::GetItemHandler(int a_ItemType) { - if (a_ItemType < 0) + if ((a_ItemType < 0) || ((unsigned long)a_ItemType >= ARRAYCOUNT(m_ItemHandler))) { // Either nothing (-1), or bad value, both cases should return the air handler if (a_ItemType < -1) @@ -129,6 +130,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_HEAD: return new cItemMobHeadHandler(a_ItemType); case E_ITEM_SNOWBALL: return new cItemSnowballHandler(); case E_ITEM_SPAWN_EGG: return new cItemSpawnEggHandler(a_ItemType); + case E_ITEM_STRING: return new cItemStringHandler(a_ItemType); case E_ITEM_SUGARCANE: return new cItemSugarcaneHandler(a_ItemType); case E_ITEM_WOODEN_HOE: diff --git a/src/Items/ItemString.h b/src/Items/ItemString.h new file mode 100644 index 000000000..a97fbe0ce --- /dev/null +++ b/src/Items/ItemString.h @@ -0,0 +1,39 @@ + +#pragma once + +#include "ItemHandler.h" + + + + + +class cItemStringHandler : + public cItemHandler +{ +public: + cItemStringHandler(int a_ItemType) : + cItemHandler(a_ItemType) + { + } + + virtual bool IsPlaceable(void) override + { + return true; + } + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = E_BLOCK_TRIPWIRE; + a_BlockMeta = 0; + return true; + } +}; + + + + diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 5843ca5a6..aaef7580d 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -46,8 +46,8 @@ static const struct {cMonster::mtSheep, "sheep"}, {cMonster::mtSilverfish, "silverfish"}, {cMonster::mtSkeleton, "skeleton"}, - {cMonster::mtSnowGolem, "snowgolem"}, {cMonster::mtSlime, "slime"}, + {cMonster::mtSnowGolem, "snowgolem"}, {cMonster::mtSpider, "spider"}, {cMonster::mtSquid, "squid"}, {cMonster::mtVillager, "villager"}, diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index e862f5aaa..1f77cf613 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -78,3 +78,23 @@ void cPig::OnRightClicked(cPlayer & a_Player) + + +void cPig::Tick(float a_Dt, cChunk & a_Chunk) +{ + super::Tick(a_Dt, a_Chunk); + + // If the attachee player is holding a carrot-on-stick, let them drive this pig: + if (m_bIsSaddled && (m_Attachee != NULL)) + { + if (m_Attachee->IsPlayer() && (m_Attachee->GetEquippedWeapon().m_ItemType == E_ITEM_CARROT_ON_STICK)) + { + MoveToPosition((m_Attachee->GetPosition()) + (m_Attachee->GetLookVector()*10)); + m_bMovingToDestination = true; + } + } +} + + + + diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h index d434324c1..313af2f44 100644 --- a/src/Mobs/Pig.h +++ b/src/Mobs/Pig.h @@ -19,6 +19,7 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual void OnRightClicked(cPlayer & a_Player) override; + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); } diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp index 6b8fccde2..72bce4c3c 100644 --- a/src/OSSupport/Event.cpp +++ b/src/OSSupport/Event.cpp @@ -18,7 +18,7 @@ cEvent::cEvent(void) m_Event = CreateEvent(NULL, FALSE, FALSE, NULL); if (m_Event == NULL) { - LOGERROR("cEvent: cannot create event, GLE = %d. Aborting server.", GetLastError()); + LOGERROR("cEvent: cannot create event, GLE = %u. Aborting server.", (unsigned)GetLastError()); abort(); } #else // *nix @@ -86,7 +86,7 @@ void cEvent::Wait(void) DWORD res = WaitForSingleObject(m_Event, INFINITE); if (res != WAIT_OBJECT_0) { - LOGWARN("cEvent: waiting for the event failed: %d, GLE = %d. Continuing, but server may be unstable.", res, GetLastError()); + LOGWARN("cEvent: waiting for the event failed: %u, GLE = %u. Continuing, but server may be unstable.", (unsigned)res, (unsigned)GetLastError()); } #else int res = sem_wait(m_Event); @@ -107,7 +107,7 @@ void cEvent::Set(void) #ifdef _WIN32 if (!SetEvent(m_Event)) { - LOGWARN("cEvent: Could not set cEvent: GLE = %d", GetLastError()); + LOGWARN("cEvent: Could not set cEvent: GLE = %u", (unsigned)GetLastError()); } #else int res = sem_post(m_Event); diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index 8c24fa541..addf8f928 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -7,6 +7,9 @@ #include "File.h" #include <fstream> +#ifdef _WIN32 + #include <share.h> // for _SH_DENYWRITE +#endif // _WIN32 diff --git a/src/OSSupport/IsThread.cpp b/src/OSSupport/IsThread.cpp index 67f336c97..1a436623a 100644 --- a/src/OSSupport/IsThread.cpp +++ b/src/OSSupport/IsThread.cpp @@ -90,7 +90,7 @@ bool cIsThread::Start(void) m_Handle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &m_ThreadID); if (m_Handle == NULL) { - LOGERROR("ERROR: Could not create thread \"%s\", GLE = %d!", m_ThreadName.c_str(), GetLastError()); + LOGERROR("ERROR: Could not create thread \"%s\", GLE = %u!", m_ThreadName.c_str(), (unsigned)GetLastError()); return false; } ResumeThread(m_Handle); diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index c6e569919..ac872a2f2 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -64,7 +64,7 @@ public: virtual void SendChat (const AString & a_Message) = 0; virtual void SendChat (const cCompositeChat & a_Message) = 0; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0; - virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) = 0; + virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) = 0; virtual void SendDestroyEntity (const cEntity & a_Entity) = 0; virtual void SendDisconnect (const AString & a_Reason) = 0; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; ///< Request the client to open up the sign editor for the sign (1.6+) @@ -100,7 +100,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) = 0; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) = 0; - virtual void SendRespawn (const cWorld & a_World) = 0; + virtual void SendRespawn (const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks = false) = 0; virtual void SendExperience (void) = 0; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) = 0; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 491058919..6dc2e918d 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -274,11 +274,11 @@ void cProtocol125::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize -void cProtocol125::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) +void cProtocol125::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_COLLECT_PICKUP); - WriteInt (a_Pickup.GetUniqueID()); + WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Player.GetUniqueID()); Flush(); } @@ -833,12 +833,12 @@ void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect -void cProtocol125::SendRespawn(const cWorld & a_World) +void cProtocol125::SendRespawn(const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks) { cCSLock Lock(m_CSPacket); - if (m_LastSentDimension == a_World.GetDimension()) + if ((m_LastSentDimension == a_World.GetDimension()) && !a_ShouldIgnoreDimensionChecks) { - // Must not send a respawn for the world with the same dimension, the client goes cuckoo if we do + // Must not send a respawn for the world with the same dimension, the client goes cuckoo if we do (unless we are respawning from death) return; } cPlayer * Player = m_Client->GetPlayer(); diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 85418f71f..9dbefd3a3 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -36,7 +36,7 @@ public: virtual void SendChat (const AString & a_Message) override; virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; - virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; + virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; virtual void SendDisconnect (const AString & a_Reason) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) @@ -72,7 +72,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; - virtual void SendRespawn (const cWorld & a_World) override; + virtual void SendRespawn (const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks = false) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp index 1e3fc8de8..31cf99f53 100644 --- a/src/Protocol/Protocol132.cpp +++ b/src/Protocol/Protocol132.cpp @@ -188,19 +188,19 @@ void cProtocol132::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize -void cProtocol132::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) +void cProtocol132::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_COLLECT_PICKUP); - WriteInt (a_Pickup.GetUniqueID()); + WriteInt (a_Entity.GetUniqueID()); WriteInt (a_Player.GetUniqueID()); Flush(); // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;) SendSoundEffect( "random.pop", - (int)(a_Pickup.GetPosX() * 8), (int)(a_Pickup.GetPosY() * 8), (int)(a_Pickup.GetPosZ() * 8), - 0.5, (float)(0.75 + ((float)((a_Pickup.GetUniqueID() * 23) % 32)) / 64) + (int)(a_Entity.GetPosX() * 8), (int)(a_Entity.GetPosY() * 8), (int)(a_Entity.GetPosZ() * 8), + 0.5, (float)(0.75 + ((float)((a_Entity.GetUniqueID() * 23) % 32)) / 64) ); } diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h index 32bc7d581..e5d3ee80c 100644 --- a/src/Protocol/Protocol132.h +++ b/src/Protocol/Protocol132.h @@ -48,7 +48,7 @@ public: virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override; virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; - virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; + virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; diff --git a/src/Protocol/Protocol16x.cpp b/src/Protocol/Protocol16x.cpp index 9e0f3f852..eba795f61 100644 --- a/src/Protocol/Protocol16x.cpp +++ b/src/Protocol/Protocol16x.cpp @@ -158,10 +158,10 @@ void cProtocol161::SendPlayerMaxSpeed(void) -void cProtocol161::SendRespawn(const cWorld & a_World) +void cProtocol161::SendRespawn(const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks) { // Besides sending the respawn, we need to also send the player max speed, otherwise the client reverts to super-fast - super::SendRespawn(a_World); + super::SendRespawn(a_World, a_ShouldIgnoreDimensionChecks); SendPlayerMaxSpeed(); } diff --git a/src/Protocol/Protocol16x.h b/src/Protocol/Protocol16x.h index e91dc8a1c..e6e79027e 100644 --- a/src/Protocol/Protocol16x.h +++ b/src/Protocol/Protocol16x.h @@ -42,7 +42,7 @@ protected: virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; virtual void SendPlayerMaxSpeed(void) override; - virtual void SendRespawn (const cWorld & a_World) override; + virtual void SendRespawn (const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks = false) override; virtual void SendWindowOpen (const cWindow & a_Window) override; virtual int ParseEntityAction (void) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 109e5a67b..855687269 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -351,12 +351,12 @@ void cProtocol172::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize -void cProtocol172::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) +void cProtocol172::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x0d); // Collect Item packet - Pkt.WriteInt(a_Pickup.GetUniqueID()); + Pkt.WriteInt(a_Entity.GetUniqueID()); Pkt.WriteInt(a_Player.GetUniqueID()); } @@ -986,11 +986,11 @@ void cProtocol172::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect -void cProtocol172::SendRespawn(const cWorld & a_World) +void cProtocol172::SendRespawn(const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks) { - if (m_LastSentDimension == a_World.GetDimension()) + if ((m_LastSentDimension == a_World.GetDimension()) && !a_ShouldIgnoreDimensionChecks) { - // Must not send a respawn for the world with the same dimension, the client goes cuckoo if we do + // Must not send a respawn for the world with the same dimension, the client goes cuckoo if we do (unless we are respawning from death) return; } @@ -1221,10 +1221,9 @@ void cProtocol172::SendStatistics(const cStatManager & a_Manager) cPacketizer Pkt(*this, 0x37); Pkt.WriteVarInt(statCount); // TODO 2014-05-11 xdot: Optimization: Send "dirty" statistics only - for (unsigned int i = 0; i < (unsigned int)statCount; ++i) + for (size_t i = 0; i < (size_t)statCount; ++i) { StatValue Value = a_Manager.GetValue((eStatistic) i); - const AString & StatName = cStatInfo::GetName((eStatistic) i); Pkt.WriteString(StatName); diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 8be1d9211..1a65cfa1c 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -68,7 +68,7 @@ public: virtual void SendChat (const AString & a_Message) override; virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; - virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; + virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; virtual void SendDisconnect (const AString & a_Reason) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) @@ -104,7 +104,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; - virtual void SendRespawn (const cWorld & a_World) override; + virtual void SendRespawn (const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks = false) override; virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8 virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 80f5da25a..c0c9e08ee 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -181,10 +181,10 @@ void cProtocolRecognizer::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSe -void cProtocolRecognizer::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) +void cProtocolRecognizer::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player) { ASSERT(m_Protocol != NULL); - m_Protocol->SendCollectPickup(a_Pickup, a_Player); + m_Protocol->SendCollectEntity(a_Entity, a_Player); } @@ -556,10 +556,10 @@ void cProtocolRecognizer::SendRemoveEntityEffect(const cEntity & a_Entity, int a -void cProtocolRecognizer::SendRespawn(const cWorld & a_World) +void cProtocolRecognizer::SendRespawn(const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks) { ASSERT(m_Protocol != NULL); - m_Protocol->SendRespawn(a_World); + m_Protocol->SendRespawn(a_World, a_ShouldIgnoreDimensionChecks); } diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 5e178447c..0a9a42e93 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -71,7 +71,7 @@ public: virtual void SendChat (const AString & a_Message) override; virtual void SendChat (const cCompositeChat & a_Message) override; virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override; - virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; + virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; virtual void SendDisconnect (const AString & a_Reason) override; virtual void SendEditSign (int a_BlockX, int a_BlockY, int a_BlockZ) override; ///< Request the client to open up the sign editor for the sign (1.6+) @@ -107,7 +107,7 @@ public: virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPluginMessage (const AString & a_Channel, const AString & a_Message) override; virtual void SendRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID) override; - virtual void SendRespawn (const cWorld & a_World) override; + virtual void SendRespawn (const cWorld & a_World, bool a_ShouldIgnoreDimensionChecks = false) override; virtual void SendExperience (void) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override; diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index e95af3a1c..4ffda2365 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -217,14 +217,20 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i { ASSERT(a_NewMeta <= 8); // Invalid meta values ASSERT(a_NewMeta > 0); // Source blocks aren't spread - - BLOCKTYPE BlockType; - NIBBLETYPE BlockMeta; - if (!a_NearChunk->UnboundedRelGetBlock(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta)) + + a_NearChunk = a_NearChunk->GetRelNeighborChunkAdjustCoords(a_RelX, a_RelZ); + if ((a_NearChunk == NULL) || (!a_NearChunk->IsValid())) { // Chunk not available return; } + + const int BlockX = a_NearChunk->GetPosX() * cChunkDef::Width + a_RelX; + const int BlockZ = a_NearChunk->GetPosZ() * cChunkDef::Width + a_RelZ; + + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + a_NearChunk->GetBlockTypeMeta(a_RelX, a_RelY, a_RelZ, BlockType, BlockMeta); if (IsAllowedBlock(BlockType)) { @@ -246,15 +252,9 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i a_RelX, a_RelY, a_RelZ, ItemTypeToString(NewBlock).c_str() ); - a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); + a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - int BaseX = a_NearChunk->GetPosX() * cChunkDef::Width; - int BaseZ = a_NearChunk->GetPosZ() * cChunkDef::Width; - - BaseX += a_RelX; - BaseZ += a_RelZ; - - a_NearChunk->BroadcastSoundEffect("random.fizz", BaseX * 8, a_RelY * 8, BaseZ * 8, 0.5f, 1.5f); + a_NearChunk->BroadcastSoundEffect("random.fizz", BlockX * 8, a_RelY * 8, BlockZ * 8, 0.5f, 1.5f); return; } } @@ -267,15 +267,9 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i FLOG(" Water flowing into lava, turning lava at rel {%d, %d, %d} into %s", a_RelX, a_RelY, a_RelZ, ItemTypeToString(NewBlock).c_str() ); - a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - - int BaseX = a_NearChunk->GetPosX() * cChunkDef::Width; - int BaseZ = a_NearChunk->GetPosZ() * cChunkDef::Width; - - BaseX += a_RelX; - BaseZ += a_RelZ; + a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - a_NearChunk->BroadcastSoundEffect("random.fizz", BaseX * 8, a_RelY * 8, BaseZ * 8, 0.5f, 1.5f); + a_NearChunk->BroadcastSoundEffect("random.fizz", BlockX * 8, a_RelY * 8, BlockZ * 8, 0.5f, 1.5f); return; } } @@ -303,21 +297,17 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i m_World, PluginInterface, NULL, - a_NearChunk->GetPosX() * cChunkDef::Width + a_RelX, + BlockX, a_RelY, - a_NearChunk->GetPosZ() * cChunkDef::Width + a_RelZ + BlockZ ); } } // if (CanWashAway) - + // Spread: - FLOG(" Spreading to {%d, %d, %d} with meta %d", - a_NearChunk->GetPosX() * cChunkDef::Width + a_RelX, - a_RelY, - a_NearChunk->GetPosZ() * cChunkDef::Width + a_RelZ, - a_NewMeta - ); - a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta); + FLOG(" Spreading to {%d, %d, %d} with meta %d", BlockX, a_RelY, BlockZ, a_NewMeta); + a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta); + m_World.GetSimulatorManager()->WakeUp(BlockX, a_RelY, BlockZ, a_NearChunk); HardenBlock(a_NearChunk, a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta); } @@ -409,13 +399,13 @@ bool cFloodyFluidSimulator::HardenBlock(cChunk * a_Chunk, int a_RelX, int a_RelY if (a_Meta == 0) { // Source lava block - a_Chunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_OBSIDIAN, 0); + a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_OBSIDIAN, 0); return true; } // Ignore last lava level else if (a_Meta <= 4) { - a_Chunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_COBBLESTONE, 0); + a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_COBBLESTONE, 0); return true; } } diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 1de0d2c34..5af9a295d 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "IncrementalRedstoneSimulator.h" +#include "BoundingBox.h" #include "../BlockEntities/DropSpenserEntity.h" #include "../BlockEntities/NoteEntity.h" #include "../BlockEntities/CommandBlockEntity.h" @@ -12,10 +13,13 @@ #include "../Blocks/BlockButton.h" #include "../Blocks/BlockLever.h" #include "../Blocks/BlockPiston.h" +#include "../Blocks/BlockTripwireHook.h" + +#define WAKE_SIMULATOR_IF_DIRTY(a_Chunk, a_BlockX, a_BlockY, a_BlockZ) if (a_Chunk->IsRedstoneDirty()) WakeUp(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); + - cIncrementalRedstoneSimulator::cIncrementalRedstoneSimulator(cWorld & a_World) : super(a_World), @@ -99,10 +103,11 @@ void cIncrementalRedstoneSimulator::RedstoneAddBlock(int a_BlockX, int a_BlockY, // Changeable sources ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || - ((Block == E_BLOCK_DETECTOR_RAIL) && (Meta & 0x08) == 0) || + ((Block == E_BLOCK_DETECTOR_RAIL) && ((Meta & 0x08) == 0)) || (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) || (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) || - (((Block == E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE) || (Block == E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE)) && (Meta == 0)) + (((Block == E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE) || (Block == E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE)) && (Meta == 0)) || + ((Block == E_BLOCK_TRIPWIRE_HOOK) && ((Meta & 0x08) == 0)) ) { LOGD("cIncrementalRedstoneSimulator: Erased block @ {%i, %i, %i} from powered blocks list due to present/past metadata mismatch", itr->a_BlockPos.x, itr->a_BlockPos.y, itr->a_BlockPos.z); @@ -289,6 +294,9 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int switch (dataitr->Data) { case E_BLOCK_DAYLIGHT_SENSOR: HandleDaylightSensor(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_TRIPWIRE: HandleTripwire(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_TRIPWIRE_HOOK: HandleTripwireHook(dataitr->x, dataitr->y, dataitr->z); break; + case E_BLOCK_WOODEN_PRESSURE_PLATE: case E_BLOCK_STONE_PRESSURE_PLATE: case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE: @@ -526,8 +534,11 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_RelBlockX, int a_RelBl { if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true)) { - m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MetaData | 0x4); - m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + if ((MetaData & 0x4) == 0) + { + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MetaData | 0x4); + m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + } SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, true); } } @@ -535,8 +546,11 @@ void cIncrementalRedstoneSimulator::HandleFenceGate(int a_RelBlockX, int a_RelBl { if (!AreCoordsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false)) { - m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MetaData & 0xFFFFFFFB); - m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + if ((MetaData & 0x4) != 0) + { + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, MetaData & ~0x04); + m_Chunk->BroadcastSoundParticleEffect(1003, BlockX, a_RelBlockY, BlockZ, 0); + } SetPlayerToggleableBlockAsSimulated(a_RelBlockX, a_RelBlockY, a_RelBlockZ, false); } } @@ -1114,7 +1128,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R case E_BLOCK_STONE_PRESSURE_PLATE: { // MCS feature - stone pressure plates can only be triggered by players :D - cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(BlockX + 0.5f, (float)a_RelBlockY, BlockZ + 0.5f), 0.7f, false); + cPlayer * a_Player = m_World.FindClosestPlayer(Vector3f(BlockX + 0.5f, (float)a_RelBlockY, BlockZ + 0.5f), 0.5f, false); if (a_Player != NULL) { @@ -1125,7 +1139,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R else { m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, 0x0); - m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); } break; } @@ -1149,7 +1163,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); double Distance = (EntityPos - BlockPos).Length(); - if (Distance <= 0.7) + if (Distance <= 0.5) { m_NumberOfEntities++; } @@ -1171,7 +1185,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R }; cPressurePlateCallback PressurePlateCallback(BlockX, a_RelBlockY, BlockZ); - m_World.ForEachEntity(PressurePlateCallback); + m_World.ForEachEntityInChunk(m_Chunk->GetPosX(), m_Chunk->GetPosZ(), PressurePlateCallback); unsigned char Power; NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); @@ -1192,7 +1206,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.6F); } m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_RAISED); - m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); } break; @@ -1217,7 +1231,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); double Distance = (EntityPos - BlockPos).Length(); - if (Distance <= 0.7) + if (Distance <= 0.5) { m_NumberOfEntities++; } @@ -1226,7 +1240,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R bool GetPowerLevel(unsigned char & a_PowerLevel) const { - a_PowerLevel = std::min((int)ceil(m_NumberOfEntities / (float)10), MAX_POWER_LEVEL); + a_PowerLevel = std::min((int)ceil(m_NumberOfEntities / 10.f), MAX_POWER_LEVEL); return (a_PowerLevel > 0); } @@ -1239,7 +1253,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R }; cPressurePlateCallback PressurePlateCallback(BlockX, a_RelBlockY, BlockZ); - m_World.ForEachEntity(PressurePlateCallback); + m_World.ForEachEntityInChunk(m_Chunk->GetPosX(), m_Chunk->GetPosZ(), PressurePlateCallback); unsigned char Power; NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); @@ -1260,7 +1274,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.6F); } m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_RAISED); - m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); } break; @@ -1285,7 +1299,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R Vector3f BlockPos(m_X + 0.5f, (float)m_Y, m_Z + 0.5f); double Distance = (EntityPos - BlockPos).Length(); - if (Distance <= 0.7) + if (Distance <= 0.5) { m_FoundEntity = true; return true; // Break out, we only need to know for plates that at least one entity is on top @@ -1307,7 +1321,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R } ; cPressurePlateCallback PressurePlateCallback(BlockX, a_RelBlockY, BlockZ); - m_World.ForEachEntity(PressurePlateCallback); + m_World.ForEachEntityInChunk(m_Chunk->GetPosX(), m_Chunk->GetPosZ(), PressurePlateCallback); NIBBLETYPE Meta = m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ); if (PressurePlateCallback.FoundEntity()) @@ -1327,7 +1341,7 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R m_Chunk->BroadcastSoundEffect("random.click", (int)((BlockX + 0.5) * 8.0), (int)((a_RelBlockY + 0.1) * 8.0), (int)((BlockZ + 0.5) * 8.0), 0.3F, 0.6F); } m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, E_META_PRESSURE_PLATE_RAISED); - m_World.WakeUpSimulators(BlockX, a_RelBlockY, BlockZ); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); } break; } @@ -1343,6 +1357,131 @@ void cIncrementalRedstoneSimulator::HandlePressurePlate(int a_RelBlockX, int a_R +void cIncrementalRedstoneSimulator::HandleTripwireHook(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) +{ + int BlockX = m_Chunk->GetPosX() * cChunkDef::Width + a_RelBlockX; + int BlockZ = m_Chunk->GetPosZ() * cChunkDef::Width + a_RelBlockZ; + int RelX = a_RelBlockX, RelZ = a_RelBlockZ; + bool FoundActivated = false; + eBlockFace FaceToGoTowards = cBlockTripwireHookHandler::MetadataToDirection(m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ)); + + for (int i = 0; i < 40; ++i) // Tripwires can be connected up to 40 blocks + { + BLOCKTYPE Type; + NIBBLETYPE Meta; + + AddFaceDirection(RelX, a_RelBlockY, RelZ, FaceToGoTowards); + m_Chunk->UnboundedRelGetBlock(RelX, a_RelBlockY, RelZ, Type, Meta); + + if (Type == E_BLOCK_TRIPWIRE) + { + if (Meta == 0x1) + { + FoundActivated = true; + } + } + else if (Type == E_BLOCK_TRIPWIRE_HOOK) + { + if (ReverseBlockFace(cBlockTripwireHookHandler::MetadataToDirection(Meta)) == FaceToGoTowards) + { + // Other hook not facing in opposite direction + break; + } + else + { + // Tripwire hook not connected at all, AND away all the power state bits + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x3); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); + return; + } + } + else + { + // Tripwire hook not connected at all, AND away all the power state bits + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x3); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); + return; + } + } + + if (FoundActivated) + { + // Connected and activated, set the 3rd and 4th highest bits + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) | 0xC); + SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); + } + else + { + // Connected but not activated, AND away the highest bit + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, (m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x7) | 0x4); + WAKE_SIMULATOR_IF_DIRTY(m_Chunk, BlockX, a_RelBlockY, BlockZ); + } +} + + + + + +void cIncrementalRedstoneSimulator::HandleTripwire(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) +{ + int BlockX = m_Chunk->GetPosX() * cChunkDef::Width + a_RelBlockX; + int BlockZ = m_Chunk->GetPosZ() * cChunkDef::Width + a_RelBlockZ; + + class cTripwireCallback : + public cEntityCallback + { + public: + cTripwireCallback(int a_BlockX, int a_BlockY, int a_BlockZ) : + m_FoundEntity(false), + m_X(a_BlockX), + m_Y(a_BlockY), + m_Z(a_BlockZ) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + cBoundingBox bbWire(m_X, m_X + 1, m_Y, m_Y + 0.1, m_Z, m_Z + 1); + cBoundingBox bbEntity(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + + if (bbEntity.DoesIntersect(bbWire)) + { + m_FoundEntity = true; + return true; // One entity is sufficient to trigger the wire + } + return false; + } + + bool FoundEntity(void) const + { + return m_FoundEntity; + } + + protected: + bool m_FoundEntity; + + int m_X; + int m_Y; + int m_Z; + }; + + cTripwireCallback TripwireCallback(BlockX, a_RelBlockY, BlockZ); + m_World.ForEachEntityInChunk(m_Chunk->GetPosX(), m_Chunk->GetPosZ(), TripwireCallback); + + if (TripwireCallback.FoundEntity()) + { + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, 0x1); + } + else + { + m_Chunk->SetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ, 0x0); + } +} + + + + + bool cIncrementalRedstoneSimulator::AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { int BlockX = (m_Chunk->GetPosX() * cChunkDef::Width) + a_RelBlockX; @@ -1561,7 +1700,7 @@ bool cIncrementalRedstoneSimulator::IsWirePowered(int a_RelBlockX, int a_RelBloc { continue; } - a_PowerLevel = itr->a_PowerLevel; + a_PowerLevel = std::max(itr->a_PowerLevel , a_PowerLevel); // Get the highest power level (a_PowerLevel is initialised already and there CAN be multiple levels for one block) } for (LinkedBlocksList::const_iterator itr = m_LinkedPoweredBlocks->begin(); itr != m_LinkedPoweredBlocks->end(); ++itr) // Check linked powered list @@ -1570,7 +1709,7 @@ bool cIncrementalRedstoneSimulator::IsWirePowered(int a_RelBlockX, int a_RelBloc { continue; } - a_PowerLevel = itr->a_PowerLevel; + a_PowerLevel = std::max(itr->a_PowerLevel, a_PowerLevel); } return (a_PowerLevel != 0); // Answer the inital question: is the wire powered? diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index 9c1f9460c..6cefdebf2 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -102,6 +102,11 @@ private: void HandleDaylightSensor(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles pressure plates */ void HandlePressurePlate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, BLOCKTYPE a_MyType); + /** Handles tripwire hooks + Performs correct meta and power setting for self by going in the direction it faces and looking for a continous line of tripwire bounded by another oppositely facing hook + If this line is complete, it verifies that at least on wire reports an entity is on top (via its meta), and performs its task + */ + void HandleTripwireHook(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /* ==================== */ /* ====== CARRIERS ====== */ @@ -134,6 +139,8 @@ private: void HandleFenceGate(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /** Handles noteblocks */ void HandleNoteBlock(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); + /** Handles tripwires */ + void HandleTripwire(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ); /* ===================== */ /* ====== Helper functions ====== */ @@ -271,6 +278,7 @@ private: case E_BLOCK_TNT: case E_BLOCK_TRAPDOOR: case E_BLOCK_TRIPWIRE_HOOK: + case E_BLOCK_TRIPWIRE: case E_BLOCK_WOODEN_BUTTON: case E_BLOCK_WOODEN_DOOR: case E_BLOCK_WOODEN_PRESSURE_PLATE: diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 728692f2a..4df04c9e2 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -468,6 +468,20 @@ void cSlotAreaCrafting::OnPlayerRemoved(cPlayer & a_Player) +void cSlotAreaCrafting::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) +{ + // Update the recipe after setting the slot, if the slot is not the result slot: + super::SetSlot(a_SlotNum, a_Player, a_Item); + if (a_SlotNum != 0) + { + UpdateRecipe(a_Player); + } +} + + + + + void cSlotAreaCrafting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) { UNUSED(a_ItemStack); @@ -545,16 +559,20 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) // Distribute the result, this time for real: ResultCopy = Result; m_ParentWindow.DistributeStack(ResultCopy, a_Player, this, true); - + // Remove the ingredients from the crafting grid and update the recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); UpdateRecipe(a_Player); + + // Broadcast the window, we sometimes move items to different locations than Vanilla, causing needless desyncs: + m_ParentWindow.BroadcastWholeWindow(); + + // If the recipe has changed, bail out: if (!Recipe.GetResult().IsEqual(Result)) { - // The recipe has changed, bail out return; } } @@ -1341,8 +1359,7 @@ cSlotAreaEnderChest::cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWind const cItem * cSlotAreaEnderChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const { - // a_SlotNum ranges from 0 to 26, use that to index the chest entity's inventory directly: - return &(m_EnderChest->GetSlot(a_SlotNum)); + return &(a_Player.GetEnderChestContents().GetSlot(a_SlotNum)); } @@ -1351,7 +1368,7 @@ const cItem * cSlotAreaEnderChest::GetSlot(int a_SlotNum, cPlayer & a_Player) co void cSlotAreaEnderChest::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) { - m_EnderChest->SetSlot(a_SlotNum, a_Item); + a_Player.GetEnderChestContents().SetSlot(a_SlotNum, a_Item); } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index b4b693cf6..e271ea454 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -232,6 +232,7 @@ public: virtual void Clicked (cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void DblClicked (cPlayer & a_Player, int a_SlotNum); virtual void OnPlayerRemoved(cPlayer & a_Player) override; + virtual void SetSlot (int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; // Distributing items into this area is completely disabled virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 98a9a0cec..381c6e121 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -145,8 +145,7 @@ void cWindow::GetSlots(cPlayer & a_Player, cItems & a_Slots) const { int NumSlots = (*itr)->GetNumSlots(); for (int i = 0; i < NumSlots; i++) - { - + { const cItem * Item = (*itr)->GetSlot(i, a_Player); if (Item == NULL) { @@ -170,7 +169,7 @@ void cWindow::Clicked( const cItem & a_ClickedItem ) { - cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); + cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); if (a_WindowID != m_WindowID) { LOGWARNING("%s: Wrong window ID (exp %d, got %d) received from \"%s\"; ignoring click.", __FUNCTION__, m_WindowID, a_WindowID, a_Player.GetName().c_str()); @@ -1017,6 +1016,7 @@ cEnderChestWindow::~cEnderChestWindow() // Send out the chest-close packet: m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, E_BLOCK_ENDER_CHEST); + // Play the closing sound m_World->BroadcastSoundEffect("random.chestclosed", m_BlockX * 8, m_BlockY * 8, m_BlockZ * 8, 1, 1); } diff --git a/src/VoronoiMap.cpp b/src/VoronoiMap.cpp index 9c3ca7e65..5efd09c01 100644 --- a/src/VoronoiMap.cpp +++ b/src/VoronoiMap.cpp @@ -14,7 +14,9 @@ cVoronoiMap::cVoronoiMap(int a_Seed, int a_CellSize) : m_Noise1(a_Seed + 1), m_Noise2(a_Seed + 2), m_Noise3(a_Seed + 3), - m_CellSize(a_CellSize) + m_CellSize(a_CellSize), + m_CurrentCellX(9999999), // Cell coords that are definitely out of the range for normal generator, so that the first query will overwrite them + m_CurrentCellZ(9999999) { } diff --git a/src/World.cpp b/src/World.cpp index 5b067b386..48c3448a3 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1877,9 +1877,18 @@ void cWorld::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer +void cWorld::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastCollectEntity(a_Entity, a_Player, a_Exclude); +} + + + + + void cWorld::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude) { - m_ChunkMap->BroadcastCollectPickup(a_Pickup, a_Player, a_Exclude); + m_ChunkMap->BroadcastCollectEntity(a_Pickup, a_Player, a_Exclude); } @@ -2767,10 +2776,8 @@ bool cWorld::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunk void cWorld::SaveAllChunks(void) { - LOGINFO("Saving all chunks..."); m_LastSave = m_WorldAge; m_ChunkMap->SaveAllChunks(); - m_Storage.QueueSavedMessage(); } diff --git a/src/World.h b/src/World.h index 2b7f78760..32e64c8e0 100644 --- a/src/World.h +++ b/src/World.h @@ -206,6 +206,7 @@ public: // tolua_end void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); + void BroadcastCollectEntity (const cEntity & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude = NULL); @@ -485,7 +486,7 @@ public: double GetSpawnZ(void) const { return m_SpawnZ; } /** Wakes up the simulators for the specified block */ - void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ) override; /** Wakes up the simulators for the specified area of blocks */ void WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ); diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 2dcae51ce..317ace795 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -345,6 +345,7 @@ void cNBTChunkSerializer::AddBasicEntity(cEntity * a_Entity, const AString & a_C m_Writer.AddDouble("", a_Entity->GetYaw()); m_Writer.AddDouble("", a_Entity->GetPitch()); m_Writer.EndList(); + m_Writer.AddShort("Health", a_Entity->GetHealth()); } @@ -575,7 +576,6 @@ void cNBTChunkSerializer::AddPickupEntity(cPickup * a_Pickup) m_Writer.BeginCompound(""); AddBasicEntity(a_Pickup, "Item"); AddItem(a_Pickup->GetItem(), -1, "Item"); - m_Writer.AddShort("Health", (Int16)(unsigned char)a_Pickup->GetHealth()); m_Writer.AddShort("Age", (Int16)a_Pickup->GetAge()); m_Writer.EndCompound(); } @@ -674,7 +674,6 @@ void cNBTChunkSerializer::AddExpOrbEntity(cExpOrb * a_ExpOrb) { m_Writer.BeginCompound(""); AddBasicEntity(a_ExpOrb, "XPOrb"); - m_Writer.AddShort("Health", (Int16)(unsigned char)a_ExpOrb->GetHealth()); m_Writer.AddShort("Age", (Int16)a_ExpOrb->GetAge()); m_Writer.AddShort("Value", (Int16)a_ExpOrb->GetReward()); m_Writer.EndCompound(); @@ -817,6 +816,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break; case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break; case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break; + case E_BLOCK_ENDER_CHEST: /* No need to be saved */ break; case E_BLOCK_FLOWER_POT: AddFlowerPotEntity ((cFlowerPotEntity *) a_Entity); break; case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 1e9ce80cc..f13c4d4d2 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1461,13 +1461,6 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } - - // Load health: - int Health = a_NBT.FindChildByName(a_TagIdx, "Health"); - if (Health > 0) - { - Pickup->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF)); - } // Load age: int Age = a_NBT.FindChildByName(a_TagIdx, "Age"); @@ -1513,13 +1506,6 @@ void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a return; } - // Load Health: - int Health = a_NBT.FindChildByName(a_TagIdx, "Health"); - if (Health > 0) - { - ExpOrb->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF)); - } - // Load Age: int Age = a_NBT.FindChildByName(a_TagIdx, "Age"); if (Age > 0) @@ -2446,6 +2432,13 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N } a_Entity.SetYaw(Rotation[0]); a_Entity.SetRoll(Rotation[1]); + + // Load health: + int Health = a_NBT.FindChildByName(a_TagIdx, "Health"); + if (Health > 0) + { + a_Entity.SetHealth(a_NBT.GetShort(Health)); + } return true; } diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 6867ad5bc..d3f35384b 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -17,13 +17,6 @@ -/// If a chunk with this Y coord is de-queued, it is a signal to emit the saved-all message (cWorldStorage::QueueSavedMessage()) -#define CHUNK_Y_MESSAGE 2 - - - - - /// Example storage schema - forgets all chunks ;) class cWSSForgetful : public cWSSchema @@ -168,17 +161,6 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) -void cWorldStorage::QueueSavedMessage(void) -{ - // Pushes a special coord pair into the queue, signalizing a message instead - m_SaveQueue.EnqueueItem(cChunkCoords(0, CHUNK_Y_MESSAGE, 0)); - m_Event.Set(); -} - - - - - void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ,true)); @@ -286,19 +268,12 @@ bool cWorldStorage::SaveOneChunk(void) { cChunkCoords ToSave(0, 0, 0); bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave); - if(ShouldSave) { - if (ToSave.m_ChunkY == CHUNK_Y_MESSAGE) - { - LOGINFO("Saved all chunks in world %s", m_World->GetName().c_str()); - return ShouldSave; - } - if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ)) + if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ)) + { + m_World->MarkChunkSaving(ToSave.m_ChunkX, ToSave.m_ChunkZ); + if (m_SaveSchema->SaveChunk(ToSave)) { - m_World->MarkChunkSaving(ToSave.m_ChunkX, ToSave.m_ChunkZ); - if (m_SaveSchema->SaveChunk(ToSave)) - { - m_World->MarkChunkSaved(ToSave.m_ChunkX, ToSave.m_ChunkZ); - } + m_World->MarkChunkSaved(ToSave.m_ChunkX, ToSave.m_ChunkZ); } } return ShouldSave; diff --git a/src/WorldStorage/WorldStorage.h b/src/WorldStorage/WorldStorage.h index bb189b6c9..1204b4310 100644 --- a/src/WorldStorage/WorldStorage.h +++ b/src/WorldStorage/WorldStorage.h @@ -67,9 +67,6 @@ public: void QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true void QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); - /// Signals that a message should be output to the console when all the chunks have been saved - void QueueSavedMessage(void); - /// Loads the chunk specified; returns true on success, false on failure bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); |