diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2020-10-18 16:18:07 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2020-10-18 16:18:07 +0200 |
commit | 1a7d3d8188d3f484b6c3f0f05fd057d543a34725 (patch) | |
tree | eeb487998aa86e01c9a7d55d4ff1156cc598b349 /builtin | |
parent | 1e4f3549292472323d49ffad4e856ba60dd81e0c (diff) | |
download | dragonfireclient-1a7d3d8188d3f484b6c3f0f05fd057d543a34725.tar.xz |
Extended ClientObjectRef; Improved CrystalPvP
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/client/cheats/combat.lua | 47 | ||||
-rw-r--r-- | builtin/client/cheats/init.lua | 2 | ||||
-rw-r--r-- | builtin/client/util.lua | 18 | ||||
-rw-r--r-- | builtin/common/misc_helpers.lua | 13 | ||||
-rw-r--r-- | builtin/game/item.lua | 13 | ||||
-rw-r--r-- | builtin/settingtypes.txt | 2 |
6 files changed, 82 insertions, 13 deletions
diff --git a/builtin/client/cheats/combat.lua b/builtin/client/cheats/combat.lua new file mode 100644 index 000000000..25aaaec34 --- /dev/null +++ b/builtin/client/cheats/combat.lua @@ -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) + diff --git a/builtin/client/cheats/init.lua b/builtin/client/cheats/init.lua index 9eb2594a0..cdeae78c8 100644 --- a/builtin/client/cheats/init.lua +++ b/builtin/client/cheats/init.lua @@ -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") diff --git a/builtin/client/util.lua b/builtin/client/util.lua index 895609288..4a6a72d72 100644 --- a/builtin/client/util.lua +++ b/builtin/client/util.lua @@ -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 diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index f6ceda54d..64d67bc72 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -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 -------------------------------------------------------------------------------- diff --git a/builtin/game/item.lua b/builtin/game/item.lua index f680ce0d4..2c43a8548 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -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 diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 13603c726..f30a16789 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2296,3 +2296,5 @@ block_water (BlockWater) bool false autotnt (PlaceOnTop) bool false replace (Replace) bool false + +crystal_pvp (CrystalPvP) bool false |