From ecc2010fe5820caf81b9ae5982ecf6da2ab047aa Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 3 May 2021 11:22:47 +0200 Subject: [PATCH 1/6] Make compasses work in itemframes --- mods/ITEMS/mcl_compass/init.lua | 43 +++++++++++++++--------------- mods/ITEMS/mcl_itemframes/init.lua | 3 +++ mods/ITEMS/mcl_itemframes/mod.conf | 2 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/mods/ITEMS/mcl_compass/init.lua b/mods/ITEMS/mcl_compass/init.lua index f15459303..2c71eeac0 100644 --- a/mods/ITEMS/mcl_compass/init.lua +++ b/mods/ITEMS/mcl_compass/init.lua @@ -12,6 +12,27 @@ local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Inc local random_frame = math.random(0, compass_frames-1) +function mcl_compass.get_compass_image(pos, dir) + -- Compasses do not work in certain zones + if mcl_worlds.compass_works(pos) then + local spawn = {x=0,y=0,z=0} + local ssp = minetest.setting_get_pos("static_spawnpoint") + if ssp then + spawn = ssp + if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then + spawn = {x=0,y=0,z=0} + end + end + local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z)) + if angle_north < 0 then angle_north = angle_north + 360 end + local angle_dir = -math.deg(dir) + local angle_relative = (angle_north - angle_dir + 180) % 360 + return math.floor((angle_relative/11.25) + 0.5) % compass_frames + else + return random_frame + end +end + minetest.register_globalstep(function(dtime) random_timer = random_timer + dtime @@ -30,27 +51,7 @@ minetest.register_globalstep(function(dtime) end if has_compass(player) then local pos = player:get_pos() - local dim = mcl_worlds.pos_to_dimension(pos) - local compass_image - -- Compasses do not work in certain zones - if not mcl_worlds.compass_works(pos) then - compass_image = random_frame - else - local spawn = {x=0,y=0,z=0} - local ssp = minetest.setting_get_pos("static_spawnpoint") - if ssp then - spawn = ssp - if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then - spawn = {x=0,y=0,z=0} - end - end - local dir = player:get_look_horizontal() - local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z)) - if angle_north < 0 then angle_north = angle_north + 360 end - local angle_dir = -math.deg(dir) - local angle_relative = (angle_north - angle_dir + 180) % 360 - compass_image = math.floor((angle_relative/11.25) + 0.5) % compass_frames - end + local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal()) for j,stack in pairs(player:get_inventory():get_list("main")) do if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 073933fcf..4afb1d042 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -188,6 +188,9 @@ minetest.register_node("mcl_itemframes:item_frame",{ end local put_itemstack = ItemStack(itemstack) put_itemstack:set_count(1) + if minetest.get_item_group(put_itemstack:get_name(), "compass") > 0 then + put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2)))) + end inv:set_stack("main", 1, put_itemstack) update_item_entity(pos, node) -- Add node infotext when item has been named diff --git a/mods/ITEMS/mcl_itemframes/mod.conf b/mods/ITEMS/mcl_itemframes/mod.conf index 39f4370aa..98906bfb7 100644 --- a/mods/ITEMS/mcl_itemframes/mod.conf +++ b/mods/ITEMS/mcl_itemframes/mod.conf @@ -1,3 +1,3 @@ name = mcl_itemframes -depends = mcl_core, mcl_sounds +depends = mcl_core, mcl_sounds, mcl_compass optional_depends = screwdriver From 74e3c6555d3a481a600950a45fe4056d0a8e16cb Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 3 May 2021 13:43:46 +0200 Subject: [PATCH 2/6] Globalize mcl_clock API --- mods/ITEMS/mcl_clock/init.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/mods/ITEMS/mcl_clock/init.lua b/mods/ITEMS/mcl_clock/init.lua index d53d75076..30753f43a 100644 --- a/mods/ITEMS/mcl_clock/init.lua +++ b/mods/ITEMS/mcl_clock/init.lua @@ -1,7 +1,7 @@ local S = minetest.get_translator("mcl_clock") --[[ - mcl_clock, renew of the renew of the watch mod + mcl_clock, renew of the renew of the mcl_clock mod Original from Echo, here: http://forum.minetest.net/viewtopic.php?id=3795 ]]-- @@ -11,8 +11,7 @@ mcl_clock = {} -- This is the itemstring of the default clock item. It is used for the default inventory image, help entries, and the like mcl_clock.stereotype = "mcl_clock:clock" -local watch = {} -watch.old_time = -1 +mcl_clock.old_time = -1 local clock_frames = 64 @@ -22,20 +21,20 @@ local random_timer_trigger = 1.0 -- random clock spinning tick in seconds. Incre local random_frame = math.random(0, clock_frames-1) -- Image of all possible faces -watch.images = {} +mcl_clock.images = {} for frame=0, clock_frames-1 do local sframe = tostring(frame) if string.len(sframe) == 1 then sframe = "0" .. sframe end - table.insert(watch.images, "mcl_clock_clock_"..sframe..".png") + table.insert(mcl_clock.images, "mcl_clock_clock_"..sframe..".png") end local function round(num) return math.floor(num + 0.5) end -function watch.get_clock_frame() +function mcl_clock.get_clock_frame() local t = clock_frames * minetest.get_timeofday() t = round(t) if t == clock_frames then t = 0 end @@ -45,7 +44,7 @@ end local doc_mod = minetest.get_modpath("doc") ~= nil -- Register items -function watch.register_item(name, image, creative, frame) +function mcl_clock.register_item(name, image, creative, frame) local g = 1 if creative then g = 0 @@ -78,7 +77,7 @@ end local force_clock_update_timer = 0 minetest.register_globalstep(function(dtime) - local now = watch.get_clock_frame() + local now = mcl_clock.get_clock_frame() force_clock_update_timer = force_clock_update_timer + dtime random_timer = random_timer + dtime -- This causes the random spinning of the clock @@ -87,12 +86,12 @@ minetest.register_globalstep(function(dtime) random_timer = 0 end - if watch.old_time == now and force_clock_update_timer < 60 then + if mcl_clock.old_time == now and force_clock_update_timer < 60 then return end force_clock_update_timer = 0 - watch.old_time = now + mcl_clock.old_time = now for p, player in pairs(minetest.get_connected_players()) do for s, stack in pairs(player:get_inventory():get_list("main")) do @@ -117,7 +116,7 @@ end) -- Immediately set correct clock time after crafting minetest.register_on_craft(function(itemstack) if itemstack:get_name() == mcl_clock.stereotype then - itemstack:set_name("mcl_clock:clock_"..watch.get_clock_frame()) + itemstack:set_name("mcl_clock:clock_"..mcl_clock.get_clock_frame()) end end) @@ -132,7 +131,7 @@ minetest.register_craft({ }) -- Clock tool -watch.register_item(mcl_clock.stereotype, watch.images[1], true, 1) +mcl_clock.register_item(mcl_clock.stereotype, mcl_clock.images[1], true, 1) -- Faces for a=0,clock_frames-1,1 do @@ -142,6 +141,6 @@ for a=0,clock_frames-1,1 do else b = b + 32 end - watch.register_item("mcl_clock:clock_"..tostring(a), watch.images[b+1], false, a+1) + mcl_clock.register_item("mcl_clock:clock_"..tostring(a), mcl_clock.images[b+1], false, a+1) end From 2c5eca399928567e6423ff733b472721393ed99f Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 4 May 2021 08:49:21 +0200 Subject: [PATCH 3/6] Make clocks work in itemframes --- mods/ITEMS/mcl_clock/init.lua | 3 +++ mods/ITEMS/mcl_itemframes/init.lua | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_clock/init.lua b/mods/ITEMS/mcl_clock/init.lua index 30753f43a..0f6978447 100644 --- a/mods/ITEMS/mcl_clock/init.lua +++ b/mods/ITEMS/mcl_clock/init.lua @@ -92,10 +92,12 @@ minetest.register_globalstep(function(dtime) force_clock_update_timer = 0 mcl_clock.old_time = now + mcl_clock.random_frame = random_frame for p, player in pairs(minetest.get_connected_players()) do for s, stack in pairs(player:get_inventory():get_list("main")) do local dim = mcl_worlds.pos_to_dimension(player:get_pos()) + local frame -- Clocks do not work in certain zones if not mcl_worlds.clock_works(player:get_pos()) then @@ -103,6 +105,7 @@ minetest.register_globalstep(function(dtime) else frame = now end + local count = stack:get_count() if stack:get_name() == mcl_clock.stereotype then player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count) diff --git a/mods/ITEMS/mcl_itemframes/init.lua b/mods/ITEMS/mcl_itemframes/init.lua index 4afb1d042..07779e544 100644 --- a/mods/ITEMS/mcl_itemframes/init.lua +++ b/mods/ITEMS/mcl_itemframes/init.lua @@ -148,6 +148,21 @@ minetest.register_node("mcl_itemframes:item_frame",{ groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 }, sounds = mcl_sounds.node_sound_defaults(), node_placement_prediction = "", + on_timer = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + local stack = inv:get_stack("main", 1) + local itemname = stack:get_name() + if minetest.get_item_group(itemname, "clock") > 0 then + local new_name = "mcl_clock:clock_" .. (mcl_worlds.clock_works(pos) and mcl_clock.old_time or mcl_clock.random_frame) + if itemname ~= new_name then + stack:set_name(new_name) + inv:set_stack("main", 1, stack) + local node = minetest.get_node(pos) + update_item_entity(pos, node, node.param2) + end + minetest.get_node_timer(pos):start(1.0) + end + end, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return itemstack @@ -188,9 +203,13 @@ minetest.register_node("mcl_itemframes:item_frame",{ end local put_itemstack = ItemStack(itemstack) put_itemstack:set_count(1) - if minetest.get_item_group(put_itemstack:get_name(), "compass") > 0 then + local itemname = put_itemstack:get_name() + if minetest.get_item_group(itemname, "compass") > 0 then put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2)))) end + if minetest.get_item_group(itemname, "clock") > 0 then + minetest.get_node_timer(pos):start(1.0) + end inv:set_stack("main", 1, put_itemstack) update_item_entity(pos, node) -- Add node infotext when item has been named From 3b3d67a99c63fddbe4fded25d080b4f649c435f7 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 4 May 2021 09:16:42 +0200 Subject: [PATCH 4/6] Make clocks work when dropped --- mods/ENTITIES/mcl_item_entity/init.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index b65585a15..b05e92ce2 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -98,7 +98,7 @@ end minetest.register_globalstep(function(dtime) - + tick = not tick for _,player in pairs(minetest.get_connected_players()) do @@ -106,7 +106,7 @@ minetest.register_globalstep(function(dtime) local name = player:get_player_name() - + local pos = player:get_pos() if tick == true and pool[name] > 0 then @@ -124,7 +124,7 @@ minetest.register_globalstep(function(dtime) end - + local inv = player:get_inventory() local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z} @@ -428,6 +428,7 @@ minetest.register_entity(":__builtin:item", { description = def.description glow = def.light_source end + self.is_clock = minetest.get_item_group(itemname, "clock") > 0 local s = 0.2 + 0.1 * (count / max_count) local wield_scale = (def and def.wield_scale and def.wield_scale.x) or 1 local c = s @@ -593,6 +594,12 @@ minetest.register_entity(":__builtin:item", { local node = minetest.get_node_or_nil(p) local in_unloaded = (node == nil) + if self.is_clock then + self.object:set_properties({ + textures = {"mcl_clock:clock_" .. (mcl_worlds.clock_works(p) and mcl_clock.old_time or mcl_clock.random_frame)} + }) + end + -- If no collector was found for a long enough time, declare the magnet as disabled if self._magnet_active and (self._collector_timer == nil or (self._collector_timer > item_drop_settings.magnet_time)) then self._magnet_active = false From 78ce97aaf624c6c1a7390b0415f1e03bac38ed27 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 4 May 2021 09:53:28 +0200 Subject: [PATCH 5/6] Fix creeper explosion values --- mods/ENTITIES/mobs_mc/creeper.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 4552d79d1..4d0539996 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -43,10 +43,10 @@ mobs:register_mob("mobs_mc:creeper", { eye_height = 1.25, --hssssssssssss - explosion_strength = 10, - explosion_radius = 4, - explosion_damage_radius = 6, - explosiontimer_reset_radius = 6, + explosion_strength = 3, + --explosion_radius = 3, + --explosion_damage_radius = 6, + --explosiontimer_reset_radius = 6, reach = 1.5, defuse_reach = 4, explosion_timer = 0.3, @@ -148,7 +148,7 @@ mobs:register_mob("mobs_mc:creeper", { }) mobs:register_mob("mobs_mc:creeper_charged", { - description = S("Creeper"), + description = S("Charged Creeper"), type = "monster", spawn_class = "hostile", hp_min = 20, @@ -182,10 +182,10 @@ mobs:register_mob("mobs_mc:creeper_charged", { runaway_from = { "mobs_mc:ocelot", "mobs_mc:cat" }, attack_type = "explode", - explosion_strength = 24, - explosion_radius = 12, - explosion_damage_radius = 18, - explosiontimer_reset_radius = 10, + explosion_strength = 6, + --explosion_radius = 3, + --explosion_damage_radius = 6, + --explosiontimer_reset_radius = 3, reach = 1.5, defuse_reach = 4, explosion_timer = 0.3, From 75d94500026355f8bb23fc739fde34489c99cc9c Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 4 May 2021 10:24:08 +0200 Subject: [PATCH 6/6] Make compasses point upwards when dropped as an item --- mods/ENTITIES/mcl_item_entity/init.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index b05e92ce2..895bfc892 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -406,6 +406,14 @@ minetest.register_entity(":__builtin:item", { return end local stack = ItemStack(itemstring) + if minetest.get_item_group(stack:get_name(), "compass") > 0 then + stack:set_name("mcl_compass:16") + itemstring = stack:to_string() + self.itemstring = itemstring + end + if minetest.get_item_group(stack:get_name(), "clock") > 0 then + self.is_clock = true + end local count = stack:get_count() local max_count = stack:get_stack_max() if count > max_count then @@ -428,7 +436,6 @@ minetest.register_entity(":__builtin:item", { description = def.description glow = def.light_source end - self.is_clock = minetest.get_item_group(itemname, "clock") > 0 local s = 0.2 + 0.1 * (count / max_count) local wield_scale = (def and def.wield_scale and def.wield_scale.x) or 1 local c = s