From 2d197e147e4ede9b2b38692a88f620e78feba437 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Sat, 5 Sep 2020 17:07:01 +0200 Subject: Use pitch lookup in noteblock block entity (#4826) - Removed the calculation in the noteblock block entity I did the calculation in python if anyone is interested where the numbers are from Co-authored-by: 12xx12 <12xx12100@gmail.com> --- src/Bindings/DeprecatedBindings.cpp | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'src/Bindings') diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 0d216f94b..3704551eb 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -10,6 +10,7 @@ #include "../Entities/Player.h" #include "LuaState.h" #include "../BlockInfo.h" +#include "../BlockEntities/NoteEntity.h" @@ -468,6 +469,105 @@ static int tolua_set_cItem_m_Lore(lua_State * tolua_S) +/** function: cNoteEntity: GetNote */ +static int tolua_cNoteEntity_GetPitch(lua_State * tolua_S) +{ + cLuaState LuaState(tolua_S); + + if ( + !LuaState.CheckParamUserType(1, "cNoteEntity") || + !LuaState.CheckParamEnd(2) + ) + { + return 0; + } + + cNoteEntity * Self = nullptr; + + if (!LuaState.GetStackValues(1, Self)) + { + tolua_error(LuaState, "Failed to read parameters", nullptr); + } + if (Self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'GetPitch'", nullptr); + } + LuaState.Push(Self->GetNote()); + LOGWARNING("Warning: 'cNoteEntity:GetPitch' function is deprecated. Please use 'cNoteEntity:GetNote' instead."); + LuaState.LogStackTrace(0); + return 1; +} + + + + +/** function: cNoteEntity: IncrementNote */ +static int tolua_cNoteEntity_IncrementPitch(lua_State * tolua_S) +{ + cLuaState LuaState(tolua_S); + + if ( + !LuaState.CheckParamUserType(1, "cNoteEntity") || + !LuaState.CheckParamEnd(2) + ) + { + return 0; + } + + cNoteEntity * Self = nullptr; + + if (!LuaState.GetStackValues(1, Self)) + { + tolua_error(LuaState, "Failed to read parameters", nullptr); + } + if (Self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'SetPitch'", nullptr); + } + + Self->IncrementNote(); + LOGWARNING("Warning: 'cNoteEntity:IncrementPitch' function is deprecated. Please use 'cNoteEntity:IncrementNote' instead."); + LuaState.LogStackTrace(0); + return 1; +} + + + + +/** function: cNoteEntity: SetNote */ +static int tolua_cNoteEntity_SetPitch(lua_State * tolua_S) +{ + cLuaState LuaState(tolua_S); + + if ( + !LuaState.CheckParamUserType(1, "cNoteEntity") || + !LuaState.CheckParamNumber(2) || + !LuaState.CheckParamEnd(3) + ) + { + return 0; + } + + cNoteEntity * Self = nullptr; + int Note = -1; + + if (!LuaState.GetStackValues(1, Self, Note)) + { + tolua_error(LuaState, "Failed to read parameters", nullptr); + } + if (Self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'SetPitch'", nullptr); + } + + Self->SetNote(Note % 25); + LOGWARNING("Warning: 'cNoteEntity:SetPitch' function is deprecated. Please use 'cNoteEntity:SetNote' instead."); + LuaState.LogStackTrace(0); + return 1; +} + + + /** function: cWorld:SetSignLines */ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) @@ -708,6 +808,12 @@ void DeprecatedBindings::Bind(lua_State * tolua_S) tolua_variable(tolua_S, "m_Lore", tolua_get_cItem_m_Lore, tolua_set_cItem_m_Lore); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cNoteEntity"); + tolua_function(tolua_S, "GetPitch", tolua_cNoteEntity_GetPitch); + tolua_function(tolua_S, "IncrementPitch", tolua_cNoteEntity_IncrementPitch); + tolua_function(tolua_S, "SetPitch", tolua_cNoteEntity_SetPitch); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cWorld"); tolua_function(tolua_S, "GrowTree", tolua_cWorld_GrowTree); tolua_function(tolua_S, "GrowTreeByBiome", tolua_cWorld_GrowTreeByBiome); -- cgit v1.2.3