]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Extended ClientObjectRef; Improved CrystalPvP
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 18 Oct 2020 14:18:07 +0000 (16:18 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 18 Oct 2020 14:18:07 +0000 (16:18 +0200)
builtin/client/cheats/combat.lua [new file with mode: 0644]
builtin/client/cheats/init.lua
builtin/client/util.lua
builtin/common/misc_helpers.lua
builtin/game/item.lua
builtin/settingtypes.txt
doc/client_lua_api.txt
src/defaultsettings.cpp
src/script/common/c_content.cpp
src/script/lua_api/l_clientobject.cpp
src/script/lua_api/l_clientobject.h

diff --git a/builtin/client/cheats/combat.lua b/builtin/client/cheats/combat.lua
new file mode 100644 (file)
index 0000000..25aaaec
--- /dev/null
@@ -0,0 +1,47 @@
+local placed_crystal
+local switched_to_totem = 0
+local used_sneak = true
+
+core.register_globalstep(function(dtime)
+       if not minetest.settings:get_bool("crystal_pvp") then return end
+       local player = core.localplayer
+       if not player then return end
+       local control = player:get_control()
+       local pointed = core.get_pointed_thing()
+       local item = player:get_wielded_item():get_name()
+       if placed_crystal then
+               if core.switch_to_item("mobs_mc:totem") then
+                       switched_to_totem = 5
+               end
+               placed_crystal = false
+       elseif switched_to_totem > 0 then
+               if item ~= "mobs_mc:totem"  then
+                       switched_to_totem = 0
+               elseif pointed and pointed.type == "object" then
+                       pointed.ref:punch()
+                       switched_to_totem = 0
+               else
+                       switched_to_totem = switched_to_totem
+               end
+       elseif control.RMB and item == "mcl_end:crystal" then
+               placed_crystal = true
+       elseif control.sneak then
+               if used_sneak then
+                       core.switch_to_item("mobs_mc:totem")
+                       return
+               end
+               core.switch_to_item("mcl_end:crystal")
+               if pointed and pointed.type == "node" then
+                       local pos = core.get_pointed_thing_position(pointed)
+                       local node = core.get_node_or_nil(pos)
+                       if node and (node.name == "mcl_core:obsidian" or node.name == "mcl_core:bedrock") then
+                               core.place_node(pos)
+                               placed_crystal = true
+                       end
+               end
+               used_sneak = true
+       else
+               used_sneak = false
+       end
+end)
+
index 9eb2594a0502004d4828041108ac913fa0239e2b..cdeae78c813bc6f434b72d592acc1fc48c9b1014 100644 (file)
@@ -4,6 +4,7 @@ core.cheats = {
                ["AntiKnockback"] = "antiknockback",
                ["FastHit"] = "spamclick",
                ["AttachmentFloat"] = "float_above_parent",
+               ["CrystalPvP"] = "crystal_pvp",
        },
        ["Movement"] = {
                ["Freecam"] = "freecam",
@@ -70,6 +71,7 @@ end
 local cheatpath = core.get_builtin_path() .. "client" .. DIR_DELIM .. "cheats" .. DIR_DELIM
 
 dofile(cheatpath .. "chat.lua")
+dofile(cheatpath .. "combat.lua")
 dofile(cheatpath .. "inventory.lua")
 dofile(cheatpath .. "movement.lua")
 dofile(cheatpath .. "player.lua")
index 8956092885de844485a37a75968196134d450a65..4a6a72d72e6ee4de96abd934161b298fea0cdda5 100644 (file)
@@ -20,3 +20,21 @@ function core.parse_relative_pos(param)
        if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end
        return success, pos
 end 
+
+function core.switch_to_item(item)
+       for index, stack in ipairs(core.get_inventory("current_player").main) do
+               if stack:get_name() == item then
+                       core.localplayer:set_wield_index(index - 1)
+                       return true
+               end
+       end
+       return false
+end
+
+function core.get_pointed_thing()
+       local pos = core.camera:get_pos()
+       local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 5))
+       local ray = core.raycast(pos, pos2, true, true)
+       
+       return ray:next()
+end    
index f6ceda54dd049b533cd8cbc287eda70e0cbcb499..64d67bc72672f324f71834cde33be84ea30f3821 100644 (file)
@@ -708,6 +708,19 @@ function core.get_translator(textdomain)
        return function(str, ...) return core.translate(textdomain or "", str, ...) end
 end
 
+function core.get_pointed_thing_position(pointed_thing, above)
+       if pointed_thing.type == "node" then
+               if above then
+                       -- The position where a node would be placed
+                       return pointed_thing.above
+               end
+               -- The position where a node would be dug
+               return pointed_thing.under
+       elseif pointed_thing.type == "object" then
+               return pointed_thing.ref and pointed_thing.ref:get_pos()
+       end
+end
+
 --------------------------------------------------------------------------------
 -- Returns the exact coordinate of a pointed surface
 --------------------------------------------------------------------------------
index f680ce0d4bd9eb1e13be985665ffb709d670b122..2c43a8548ba3b5d084422d0f2382393c39132aa2 100644 (file)
@@ -24,19 +24,6 @@ function core.inventorycube(img1, img2, img3)
                        .. "{" .. img3:gsub("%^", "&")
 end
 
-function core.get_pointed_thing_position(pointed_thing, above)
-       if pointed_thing.type == "node" then
-               if above then
-                       -- The position where a node would be placed
-                       return pointed_thing.above
-               end
-               -- The position where a node would be dug
-               return pointed_thing.under
-       elseif pointed_thing.type == "object" then
-               return pointed_thing.ref and pointed_thing.ref:get_pos()
-       end
-end
-
 function core.dir_to_facedir(dir, is6d)
        --account for y if requested
        if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
index 13603c726971cba6767e300660100ad67569dc78..f30a167892cfeeb89ae85dec9224babfb0603e77 100644 (file)
@@ -2296,3 +2296,5 @@ block_water (BlockWater) bool false
 autotnt (PlaceOnTop) bool false
 
 replace (Replace) bool false
+
+crystal_pvp (CrystalPvP) bool false
index 599ce0b839463436a85c84763004eea5d6d5bda6..735173580eb8d467e403f8f0fd4eeceff3ae211a 100644 (file)
@@ -219,7 +219,7 @@ For helper functions see "Vector helpers".
 ### pointed_thing
 * `{type="nothing"}`
 * `{type="node", under=pos, above=pos}`
-* `{type="object", id=ObjectID}`
+* `{type="object", ref=ClientObjectRef}`
 
 Flag Specifier Format
 ---------------------
@@ -843,6 +843,13 @@ Call these functions only at load time!
     * `pos2`: end of the ray
     * `objects`: if false, only nodes will be returned. Default is `true`.
     * `liquids`: if false, liquid nodes won't be returned. Default is `false`.
+* `minetest.get_pointed_thing()` returns `PointedThing`
+    * Returns the thing currently pointed by player
+* `minetest.get_pointed_thing_position(pointed_thing, above)`
+    * Returns the position of a `pointed_thing` or `nil` if the `pointed_thing`
+      does not refer to a node or entity.
+    * If the optional `above` parameter is true and the `pointed_thing` refers
+      to a node, then it will return the `above` position of the `pointed_thing`.
 * `minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)`
     * returns table containing path that can be walked on
     * returns a table of 3D points representing a path from `pos1` to `pos2` or
@@ -897,6 +904,9 @@ Call these functions only at load time!
 ### Client Environment
 * `minetest.get_player_names()`
     * Returns list of player names on server (nil if CSM_RF_READ_PLAYERINFO is enabled by server)
+* `minetest.get_objects_inside_radius(pos, radius)`: returns a list of
+  ClientObjectRefs.
+    * `radius`: using an euclidean metric
 * `minetest.disconnect()`
     * Disconnect from the server and exit to main menu.
     * Returns `false` if the client is already disconnecting otherwise returns `true`.
@@ -1002,6 +1012,10 @@ Passed to `HTTPApiTable.fetch` callback. Returned by
     * e.g. minetest.set_keypress("jump", true) will cause te player to jump until minetest.set_keypress("jump", false) is called or the player presses & releases the space bar himself
 * `minetest.get_inventory(location)`
     * Returns the inventory at location
+* `minetest.switch_to_item(item)`
+    * `item` is an Itemstring
+    * searches to item in inventory, sets the wield index to it if found
+    * returns true on success, false if item was not found
 * `minetest.register_cheat(name, category, setting | function)`
     * Register an entry for the cheat menu
     * If the Category is nonexistant, it will be created
@@ -1307,6 +1321,25 @@ Can be obtained via `minetest.get_meta(pos)`.
     * `fields`: key-value storage
     * `inventory`: `{list1 = {}, ...}}`
 
+### ClientObjectRef
+
+Moving things in the game are generally these.
+This is basically a reference to a C++ `GenericCAO`.
+
+#### Methods
+
+* `get_pos()`: returns `{x=num, y=num, z=num}`
+* `get_velocity()`: returns the velocity, a vector
+* `get_acceleration()`: returns the acceleration, a vector
+* `get_rotation()`: returns the rotation, a vector (radians)
+* `is_player()`: returns true if the object is a player
+* `get_attach()`: returns parent or nil if it isn't attached.
+* `get_nametag()`: returns the nametag (string)
+* `get_item_textures()`: returns the textures
+* `get_max_hp()`: returns the maximum heath
+* `punch()`: punches the object
+* `rightclick()`: rightclicks the object
+    
 ### `Raycast`
 
 A raycast on the map. It works with selection boxes.
index 96c4e0688f7d83f762747a8615861f8c53be7fa3..530bfcd8ab9357b33f140be27af0fa650c98f5a4 100644 (file)
@@ -108,6 +108,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("block_water", "false");
        settings->setDefault("autotnt", "false");
        settings->setDefault("replace", "false");
+       settings->setDefault("crystal_pvp", "false");
 
        // Keymap
        settings->setDefault("remote_port", "30000");
index 9efa2c57f5d3177c0b8ad6192de935e653cc2401..7d4c1e748e0f5fac18b150d14ff71c4fee76db28 100644 (file)
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "object_properties.h"
 #include "collision.h"
 #include "cpp_api/s_node.h"
+#include "lua_api/l_clientobject.h"
 #include "lua_api/l_object.h"
 #include "lua_api/l_item.h"
 #include "common/c_internal.h"
@@ -1838,12 +1839,12 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm,
                lua_setfield(L, -2, "type");
 
                if (csm) {
-                       lua_pushinteger(L, pointed.object_id);
-                       lua_setfield(L, -2, "id");
+                       ClientObjectRef::create(L, pointed.object_id);
                } else {
                        push_objectRef(L, pointed.object_id);
-                       lua_setfield(L, -2, "ref");
                }
+               
+               lua_setfield(L, -2, "ref");
        } else {
                lua_pushstring(L, "nothing");
                lua_setfield(L, -2, "type");
index 462de1a09e13e93c2f244b2016408b55b9b0ab17..90f0bcd15043e8fa6ccf6899ac92b530b08929ac 100644 (file)
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "common/c_converter.h"
 #include "client/client.h"
 #include "object_properties.h"
+#include "util/pointedthing.h"
 
 ClientObjectRef *ClientObjectRef::checkobject(lua_State *L, int narg)
 {
@@ -133,6 +134,24 @@ int ClientObjectRef::l_get_max_hp(lua_State *L)
        return 1;
 }
 
+int ClientObjectRef::l_punch(lua_State *L)
+{
+       ClientObjectRef *ref = checkobject(L, 1);
+       GenericCAO *gcao = get_generic_cao(ref, L);
+       PointedThing pointed(gcao->getId(), v3f(0,0,0), v3s16(0,0,0), 0);
+       getClient(L)->interact(INTERACT_START_DIGGING, pointed);
+       return 0;
+}
+
+int ClientObjectRef::l_rightclick(lua_State *L)
+{
+       ClientObjectRef *ref = checkobject(L, 1);
+       GenericCAO *gcao = get_generic_cao(ref, L);
+       PointedThing pointed(gcao->getId(), v3f(0,0,0), v3s16(0,0,0), 0);
+       getClient(L)->interact(INTERACT_PLACE, pointed);
+       return 0;
+}
+
 ClientObjectRef::ClientObjectRef(ClientActiveObject *object) : m_object(object)
 {
 }
@@ -147,6 +166,11 @@ void ClientObjectRef::create(lua_State *L, ClientActiveObject *object)
        }
 }
 
+void ClientObjectRef::create(lua_State *L, s16 id)
+{
+       create(L, ((ClientEnvironment *)getEnv(L))->getActiveObject(id));
+}
+
 int ClientObjectRef::gc_object(lua_State *L)
 {
        ClientObjectRef *obj = *(ClientObjectRef **)(lua_touserdata(L, 1));
@@ -190,4 +214,6 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos),
                luamethod(ClientObjectRef, get_attach),
                luamethod(ClientObjectRef, get_nametag),
                luamethod(ClientObjectRef, get_item_textures),
-               luamethod(ClientObjectRef, get_max_hp), {0, 0}};
+               luamethod(ClientObjectRef, get_max_hp),
+               luamethod(ClientObjectRef, punch),
+               luamethod(ClientObjectRef, rightclick), {0, 0}};
index 3022555f5df5293650aab6e41c41a64f6b5dfb90..88a6956bc4a0868f7ab5f79366c84335cab91ac6 100644 (file)
@@ -31,6 +31,7 @@ class ClientObjectRef : public ModApiBase
        static void Register(lua_State *L);
 
        static void create(lua_State *L, ClientActiveObject *object);
+       static void create(lua_State *L, s16 id);
 
        static ClientObjectRef *checkobject(lua_State *L, int narg);
 
@@ -74,4 +75,10 @@ class ClientObjectRef : public ModApiBase
 
        // get_hp(self)
        static int l_get_max_hp(lua_State *L);
+
+       // punch(self)
+       static int l_punch(lua_State *L);
+
+       // rightclick(self)
+       static int l_rightclick(lua_State *L);
 };