]> git.lizzy.rs Git - crystalpvp.git/blob - init.lua
80de047f167c6911e9f7642cfd5807cbaf1a5a3e
[crystalpvp.git] / init.lua
1 local placed_crystal
2 local switched_to_totem = 0
3 local used_sneak = true
4 local totem_move_action = InventoryAction("move")
5 totem_move_action:to("current_player", "main", 9)
6
7 minetest.register_globalstep(function(dtime)
8         local player = minetest.localplayer
9         if not player then return end
10         local control = player:get_control()
11         local pointed = minetest.get_pointed_thing()
12         local item = player:get_wielded_item():get_name()
13         if minetest.settings:get_bool("crystal_pvp") then
14                 if placed_crystal then
15                         if minetest.switch_to_item("mobs_mc:totem") then
16                                 switched_to_totem = 5
17                         end
18                         placed_crystal = false
19                 elseif switched_to_totem > 0 then
20                         if item ~= "mobs_mc:totem"  then
21                                 switched_to_totem = 0
22                         elseif pointed and pointed.type == "object" then
23                                 pointed.ref:punch()
24                                 switched_to_totem = 0
25                         else
26                                 switched_to_totem = switched_to_totem
27                         end
28                 elseif control.place and item == "mcl_end:crystal" then
29                         placed_crystal = true
30                 elseif control.sneak then
31                         if pointed and pointed.type == "node" and not used_sneak then
32                                 local pos = minetest.get_pointed_thing_position(pointed)
33                                 local node = minetest.get_node_or_nil(pos)
34                                 if node and (node.name == "mcl_core:obsidian" or node.name == "mcl_core:bedrock") then
35                                         minetest.switch_to_item("mcl_end:crystal")
36                                         minetest.place_node(pos)
37                                         placed_crystal = true
38                                 end     
39                         end
40                         used_sneak = true
41                 else
42                         used_sneak = false
43                 end
44         end
45         
46         if minetest.settings:get_bool("autototem") then
47                 local totem_stack = minetest.get_inventory("current_player").main[9]
48                 if totem_stack and totem_stack:get_name() ~= "mobs_mc:totem" then
49                         local totem_index = minetest.find_item("mobs_mc:totem")
50                         if totem_index then
51                                 totem_move_action:from("current_player", "main", totem_index)
52                                 totem_move_action:apply()
53                                 player:set_wield_index(9)
54                         end
55                 end
56         end
57 end)
58  
59 minetest.register_cheat("CrystalPvP", "Combat", "crystal_pvp")
60 minetest.register_cheat("AutoTotem", "Combat", "autototem")