Finished DM pedestal (but not all the abilities)
This commit is contained in:
parent
bd934c691b
commit
8e808c8343
|
@ -1,14 +1,129 @@
|
|||
local particle_positions = {
|
||||
{x = -0.2, y=-0.2, z=-0.2},
|
||||
{x = 0, y=-0.2, z=-0.2},
|
||||
{x = 0.2, y=-0.2, z=-0.2},
|
||||
{x = 0.2, y=-0.2, z=0},
|
||||
{x = 0.2, y=-0.2, z=0.2},
|
||||
{x = 0, y=-0.2, z=0.2},
|
||||
{x = -0.2, y=-0.2, z=0.2},
|
||||
{x = -0.2, y=-0.2, z=0},
|
||||
}
|
||||
|
||||
local function add_particles(pos)
|
||||
for _, offset in pairs(particle_positions) do
|
||||
minetest.add_particle({
|
||||
pos = vector.add(pos, offset),
|
||||
expirationtime = 1.1,
|
||||
size = 1,
|
||||
texture = "exchangeclone_flame_particle.png",
|
||||
glow = 14,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("exchangeclone:item", {
|
||||
initial_properties = {
|
||||
hp_max = 1,
|
||||
pointable = false,
|
||||
visual = "wielditem",
|
||||
visual_size = {x=0.25,y=0.25,z=0.25},
|
||||
wield_item = "air",
|
||||
automatic_rotate = 1,
|
||||
static_save = false,
|
||||
},
|
||||
on_activate = function(self, staticdata)
|
||||
if staticdata and staticdata ~= "" then
|
||||
local split_data = staticdata:split(";")
|
||||
self._itemstring = split_data[1]
|
||||
if self._itemstring and minetest.registered_items[self._itemstring] then
|
||||
self.object:set_properties({wield_item = split_data[1], is_visible = true})
|
||||
else
|
||||
self.object:set_properties({is_visible = false})
|
||||
end
|
||||
self._pedestal_pos = minetest.string_to_pos(split_data[2])
|
||||
end
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if self._itemstring and self._pedestal_pos then
|
||||
return self._itemstring..";"..minetest.pos_to_string(self._pedestal_pos)
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
exchangeclone.pedestal_offset = {x=0,y=0.4,z=0}
|
||||
|
||||
-- Copied from Mineclonia enchanting table book
|
||||
local function spawn_pedestal_entity(pos, itemstring, respawn)
|
||||
if respawn then
|
||||
-- Check if we already have an entity
|
||||
local objs = minetest.get_objects_inside_radius(pos, 1)
|
||||
for o=1, #objs do
|
||||
local obj = objs[o]
|
||||
local lua = obj:get_luaentity()
|
||||
if lua and lua.name == "exchangeclone:item" then
|
||||
if lua._pedestal_pos and vector.equals(pos, lua._pedestal_pos) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.add_entity(vector.add(pos, exchangeclone.pedestal_offset), "exchangeclone:item", (itemstring or "")..";"..minetest.pos_to_string(pos))
|
||||
end
|
||||
|
||||
local function update_pedestal_entity(pos)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 1)
|
||||
local stack = minetest.get_meta(pos):get_inventory():get_stack("main", 1)
|
||||
local itemstring
|
||||
if stack:is_known() then
|
||||
itemstring = stack:get_name()
|
||||
end
|
||||
if itemstring == "" then
|
||||
itemstring = nil
|
||||
end
|
||||
local found
|
||||
for o=1, #objs do
|
||||
local obj = objs[o]
|
||||
local lua = obj:get_luaentity()
|
||||
if lua and lua.name == "exchangeclone:item" then
|
||||
if lua._pedestal_pos and vector.equals(pos, lua._pedestal_pos) then
|
||||
found = true
|
||||
if itemstring then
|
||||
lua._itemstring = itemstring
|
||||
obj:set_properties({wield_item = itemstring, is_visible = true})
|
||||
else
|
||||
obj:set_properties({is_visible = false})
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not found then
|
||||
spawn_pedestal_entity(pos, itemstring)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "(Re-)spawn item entity above DM pedestal",
|
||||
name = "exchangeclone:spawn_pedestal_entity",
|
||||
nodenames = {"exchangeclone:dark_matter_pedestal"},
|
||||
run_at_every_load = true,
|
||||
action = update_pedestal_entity
|
||||
})
|
||||
|
||||
local function pedestal_action(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack("main", 1)
|
||||
local def = stack:get_definition()
|
||||
local func = def._exchangeclone_pedestal
|
||||
add_particles(pos)
|
||||
if func then
|
||||
minetest.log("Running function")
|
||||
inv:set_stack("main", 1, func(pos, stack) or stack)
|
||||
update_pedestal_entity(pos)
|
||||
local new_stack = inv:get_stack("main", 1)
|
||||
if new_stack:get_definition() and new_stack:get_definition()._exchangeclone_pedestal then
|
||||
if new_stack:is_known() and new_stack:get_definition()._exchangeclone_pedestal then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -31,11 +146,13 @@ minetest.register_node("exchangeclone:dark_matter_pedestal", {
|
|||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("main") and wielded_item:is_empty() then
|
||||
minetest.log("Should be an item")
|
||||
minetest.add_item(vector.offset(pos,0,0.5,0), inv:get_stack("main", 1))
|
||||
minetest.add_item(vector.add(pos, exchangeclone.pedestal_offset), inv:get_stack("main", 1))
|
||||
inv:set_stack("main", 1, ItemStack(""))
|
||||
else
|
||||
minetest.log("Nothing happened (punch)")
|
||||
update_pedestal_entity(pos)
|
||||
if minetest.get_node_timer(pos):is_started() then
|
||||
minetest.sound_play("exchangeclone_charge_down", {pos = pos, max_hear_distance = 20})
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_rightclick = function(pos, node, player, pointed_thing)
|
||||
|
@ -47,26 +164,19 @@ minetest.register_node("exchangeclone:dark_matter_pedestal", {
|
|||
local pedestal_data = stack:get_definition()._exchangeclone_pedestal
|
||||
if pedestal_data then
|
||||
if minetest.get_node_timer(pos):is_started() then
|
||||
minetest.log("Off")
|
||||
minetest.sound_play("exchangeclone_charge_down", {pos = pos, max_hear_distance = 20})
|
||||
minetest.get_node_timer(pos):stop()
|
||||
else
|
||||
minetest.log("On")
|
||||
minetest.sound_play("exchangeclone_enable", {pos = pos, max_hear_distance = 20})
|
||||
minetest.get_node_timer(pos):start(1,0)
|
||||
add_particles(pos)
|
||||
end
|
||||
else
|
||||
minetest.log("No pedestal data")
|
||||
end
|
||||
elseif inv:is_empty("main") and not wielded_item:is_empty() and wielded_item:get_stack_max() == 1 then
|
||||
minetest.log(wielded_item:get_name())
|
||||
inv:set_stack("main", 1, wielded_item:take_item())
|
||||
--wielded_item:set_count(wielded_item:get_count() - 1)
|
||||
update_pedestal_entity(pos)
|
||||
if wielded_item:get_count() <= 0 then wielded_item = ItemStack("") end
|
||||
minetest.log(tostring(wielded_item))
|
||||
return wielded_item
|
||||
else
|
||||
minetest.log("Nothing happened (rightclick)")
|
||||
end
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
|
@ -80,4 +190,27 @@ minetest.register_node("exchangeclone:dark_matter_pedestal", {
|
|||
groups = {pickaxey=5, material_stone=1, cracky = 3, building_block = 1, level = exchangeclone.mtg and 4 or 0},
|
||||
_mcl_blast_resistance = 1500,
|
||||
_mcl_hardness = 12,
|
||||
after_dig_node = exchangeclone.drop_after_dig({"main"}),
|
||||
on_blast = exchangeclone.on_blast({"main"}),
|
||||
after_destruct = function(pos)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 1)
|
||||
for o=1, #objs do
|
||||
local obj = objs[o]
|
||||
local lua = obj:get_luaentity()
|
||||
if lua and lua.name == "exchangeclone:item" then
|
||||
if lua._pedestal_pos and vector.equals(pos, lua._pedestal_pos) then
|
||||
obj:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "exchangeclone:dark_matter_pedestal",
|
||||
recipe = {
|
||||
{"exchangeclone:red_matter", "exchangeclone:dark_matter_block", "exchangeclone:red_matter"},
|
||||
{"exchangeclone:red_matter", "exchangeclone:dark_matter_block", "exchangeclone:red_matter"},
|
||||
{"exchangeclone:dark_matter_block", "exchangeclone:dark_matter_block", "exchangeclone:dark_matter_block"},
|
||||
}
|
||||
})
|
|
@ -81,11 +81,9 @@ local function link_action(pos)
|
|||
local timer = minetest.get_node_timer(pos)
|
||||
if inv:get_stack("src", 1):is_empty() and inv:get_stack("target", 1):is_empty() then
|
||||
timer:stop()
|
||||
else
|
||||
if not timer:is_started() then
|
||||
elseif not timer:is_started() then
|
||||
timer:start(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 145 B |
|
@ -236,18 +236,6 @@ function exchangeclone.format_number(number)
|
|||
return minus .. int:reverse():gsub("^,", "") .. fraction
|
||||
end
|
||||
|
||||
-- Splits a string into a table using a delimiter (copied from somewhere, I don't remember)
|
||||
function exchangeclone.split (input, sep)
|
||||
if sep == nil then
|
||||
sep = "%s"
|
||||
end
|
||||
local result={}
|
||||
for str in string.gmatch(input, "([^"..sep.."]+)") do
|
||||
table.insert(result, str)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Returns a table of all items in the specified group(s).
|
||||
function exchangeclone.get_group_items(groups, allow_duplicates, include_no_group)
|
||||
if type(groups) ~= "table" then
|
||||
|
@ -276,10 +264,10 @@ function exchangeclone.get_group_items(groups, allow_duplicates, include_no_grou
|
|||
in_group = false
|
||||
for i = 1, num_groups do
|
||||
local grp = groups[i]
|
||||
local subgroups = exchangeclone.split(grp, ",")
|
||||
local subgroups = grp:split(",")
|
||||
local success = true
|
||||
for _, subgroup in pairs(subgroups) do
|
||||
local group_info = exchangeclone.split(subgroup, "=")
|
||||
local group_info = subgroup:split("=")
|
||||
if #group_info == 1 then
|
||||
if minetest.get_item_group(name, subgroup) <= 0 then
|
||||
success = false
|
||||
|
@ -631,7 +619,7 @@ minetest.register_chatcommand("add_player_emc", {
|
|||
description = "Add to a player's personal EMC (player is self if not included, value can be negative to subtract)",
|
||||
privs = {privs = true},
|
||||
func = function(name, param)
|
||||
local split_param = exchangeclone.split(param, " ")
|
||||
local split_param = param:split(" ")
|
||||
local target_player
|
||||
local target_name
|
||||
local value
|
||||
|
@ -685,7 +673,7 @@ minetest.register_chatcommand("set_player_emc", {
|
|||
description = "Set a player's personal EMC (player is self if not included; use 'limit' as value to set it to maximum)",
|
||||
privs = {privs = true},
|
||||
func = function(name, param)
|
||||
local split_param = exchangeclone.split(param, " ")
|
||||
local split_param = param:split(" ")
|
||||
local target_player
|
||||
local target_name
|
||||
local value
|
||||
|
|
Loading…
Reference in New Issue