mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-26 03:07:32 +01:00
Merge branch 'master' of https://git.minetest.land/MineClone2/MineClone2
This commit is contained in:
commit
70db02306f
@ -406,6 +406,14 @@ minetest.register_entity(":__builtin:item", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local stack = ItemStack(itemstring)
|
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 count = stack:get_count()
|
||||||
local max_count = stack:get_stack_max()
|
local max_count = stack:get_stack_max()
|
||||||
if count > max_count then
|
if count > max_count then
|
||||||
@ -593,6 +601,12 @@ minetest.register_entity(":__builtin:item", {
|
|||||||
local node = minetest.get_node_or_nil(p)
|
local node = minetest.get_node_or_nil(p)
|
||||||
local in_unloaded = (node == nil)
|
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 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
|
if self._magnet_active and (self._collector_timer == nil or (self._collector_timer > item_drop_settings.magnet_time)) then
|
||||||
self._magnet_active = false
|
self._magnet_active = false
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local S = minetest.get_translator("mcl_clock")
|
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
|
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
|
-- 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"
|
mcl_clock.stereotype = "mcl_clock:clock"
|
||||||
|
|
||||||
local watch = {}
|
mcl_clock.old_time = -1
|
||||||
watch.old_time = -1
|
|
||||||
|
|
||||||
local clock_frames = 64
|
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)
|
local random_frame = math.random(0, clock_frames-1)
|
||||||
|
|
||||||
-- Image of all possible faces
|
-- Image of all possible faces
|
||||||
watch.images = {}
|
mcl_clock.images = {}
|
||||||
for frame=0, clock_frames-1 do
|
for frame=0, clock_frames-1 do
|
||||||
local sframe = tostring(frame)
|
local sframe = tostring(frame)
|
||||||
if string.len(sframe) == 1 then
|
if string.len(sframe) == 1 then
|
||||||
sframe = "0" .. sframe
|
sframe = "0" .. sframe
|
||||||
end
|
end
|
||||||
table.insert(watch.images, "mcl_clock_clock_"..sframe..".png")
|
table.insert(mcl_clock.images, "mcl_clock_clock_"..sframe..".png")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function round(num)
|
local function round(num)
|
||||||
return math.floor(num + 0.5)
|
return math.floor(num + 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
function watch.get_clock_frame()
|
function mcl_clock.get_clock_frame()
|
||||||
local t = clock_frames * minetest.get_timeofday()
|
local t = clock_frames * minetest.get_timeofday()
|
||||||
t = round(t)
|
t = round(t)
|
||||||
if t == clock_frames then t = 0 end
|
if t == clock_frames then t = 0 end
|
||||||
@ -45,7 +44,7 @@ end
|
|||||||
local doc_mod = minetest.get_modpath("doc") ~= nil
|
local doc_mod = minetest.get_modpath("doc") ~= nil
|
||||||
|
|
||||||
-- Register items
|
-- Register items
|
||||||
function watch.register_item(name, image, creative, frame)
|
function mcl_clock.register_item(name, image, creative, frame)
|
||||||
local g = 1
|
local g = 1
|
||||||
if creative then
|
if creative then
|
||||||
g = 0
|
g = 0
|
||||||
@ -78,7 +77,7 @@ end
|
|||||||
local force_clock_update_timer = 0
|
local force_clock_update_timer = 0
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
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
|
force_clock_update_timer = force_clock_update_timer + dtime
|
||||||
random_timer = random_timer + dtime
|
random_timer = random_timer + dtime
|
||||||
-- This causes the random spinning of the clock
|
-- This causes the random spinning of the clock
|
||||||
@ -87,16 +86,18 @@ minetest.register_globalstep(function(dtime)
|
|||||||
random_timer = 0
|
random_timer = 0
|
||||||
end
|
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
|
return
|
||||||
end
|
end
|
||||||
force_clock_update_timer = 0
|
force_clock_update_timer = 0
|
||||||
|
|
||||||
watch.old_time = now
|
mcl_clock.old_time = now
|
||||||
|
mcl_clock.random_frame = random_frame
|
||||||
|
|
||||||
for p, player in pairs(minetest.get_connected_players()) do
|
for p, player in pairs(minetest.get_connected_players()) do
|
||||||
for s, stack in pairs(player:get_inventory():get_list("main")) do
|
for s, stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
local dim = mcl_worlds.pos_to_dimension(player:get_pos())
|
local dim = mcl_worlds.pos_to_dimension(player:get_pos())
|
||||||
|
|
||||||
local frame
|
local frame
|
||||||
-- Clocks do not work in certain zones
|
-- Clocks do not work in certain zones
|
||||||
if not mcl_worlds.clock_works(player:get_pos()) then
|
if not mcl_worlds.clock_works(player:get_pos()) then
|
||||||
@ -104,6 +105,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
else
|
else
|
||||||
frame = now
|
frame = now
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = stack:get_count()
|
local count = stack:get_count()
|
||||||
if stack:get_name() == mcl_clock.stereotype then
|
if stack:get_name() == mcl_clock.stereotype then
|
||||||
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)
|
player:get_inventory():set_stack("main", s, "mcl_clock:clock_"..frame.." "..count)
|
||||||
@ -117,7 +119,7 @@ end)
|
|||||||
-- Immediately set correct clock time after crafting
|
-- Immediately set correct clock time after crafting
|
||||||
minetest.register_on_craft(function(itemstack)
|
minetest.register_on_craft(function(itemstack)
|
||||||
if itemstack:get_name() == mcl_clock.stereotype then
|
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
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -132,7 +134,7 @@ minetest.register_craft({
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- Clock tool
|
-- 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
|
-- Faces
|
||||||
for a=0,clock_frames-1,1 do
|
for a=0,clock_frames-1,1 do
|
||||||
@ -142,6 +144,6 @@ for a=0,clock_frames-1,1 do
|
|||||||
else
|
else
|
||||||
b = b + 32
|
b = b + 32
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
@ -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)
|
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)
|
minetest.register_globalstep(function(dtime)
|
||||||
random_timer = random_timer + dtime
|
random_timer = random_timer + dtime
|
||||||
|
|
||||||
@ -30,27 +51,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
if has_compass(player) then
|
if has_compass(player) then
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal())
|
||||||
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
|
|
||||||
|
|
||||||
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
|
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
|
||||||
|
@ -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 },
|
groups = { dig_immediate=3,deco_block=1,dig_by_piston=1,container=7,attached_node_facedir=1 },
|
||||||
sounds = mcl_sounds.node_sound_defaults(),
|
sounds = mcl_sounds.node_sound_defaults(),
|
||||||
node_placement_prediction = "",
|
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)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
if pointed_thing.type ~= "node" then
|
if pointed_thing.type ~= "node" then
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -188,6 +203,13 @@ minetest.register_node("mcl_itemframes:item_frame",{
|
|||||||
end
|
end
|
||||||
local put_itemstack = ItemStack(itemstack)
|
local put_itemstack = ItemStack(itemstack)
|
||||||
put_itemstack:set_count(1)
|
put_itemstack:set_count(1)
|
||||||
|
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)
|
inv:set_stack("main", 1, put_itemstack)
|
||||||
update_item_entity(pos, node)
|
update_item_entity(pos, node)
|
||||||
-- Add node infotext when item has been named
|
-- Add node infotext when item has been named
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name = mcl_itemframes
|
name = mcl_itemframes
|
||||||
depends = mcl_core, mcl_sounds
|
depends = mcl_core, mcl_sounds, mcl_compass
|
||||||
optional_depends = screwdriver
|
optional_depends = screwdriver
|
||||||
|
Loading…
Reference in New Issue
Block a user