mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-30 22:41:20 +01:00
Implement minecart with command block
This commit is contained in:
parent
4c88eb1439
commit
296c301669
2 changed files with 39 additions and 14 deletions
|
@ -698,7 +698,7 @@ local function register_entity(entity_id, def)
|
||||||
for d=1, #drop do
|
for d=1, #drop do
|
||||||
minetest.add_item(self.object:get_pos(), drop[d])
|
minetest.add_item(self.object:get_pos(), drop[d])
|
||||||
end
|
end
|
||||||
elseif puncher and killer:is_player() then
|
elseif killer and killer:is_player() then
|
||||||
local inv = killer:get_inventory()
|
local inv = killer:get_inventory()
|
||||||
for d=1, #drop do
|
for d=1, #drop do
|
||||||
if not inv:contains_item("main", drop[d]) then
|
if not inv:contains_item("main", drop[d]) then
|
||||||
|
@ -841,17 +841,18 @@ function mcl_minecarts.place_minecart(itemstack, pointed_thing, placer)
|
||||||
local cart_dir = mcl_minecarts:get_rail_direction(railpos, vector.new(1,0,0), nil, nil, railtype)
|
local cart_dir = mcl_minecarts:get_rail_direction(railpos, vector.new(1,0,0), nil, nil, railtype)
|
||||||
cart:set_yaw(minetest.dir_to_yaw(cart_dir))
|
cart:set_yaw(minetest.dir_to_yaw(cart_dir))
|
||||||
|
|
||||||
-- Call placer
|
|
||||||
if cart._mcl_minecarts_on_place then
|
|
||||||
cart._mcl_minecarts_on_place(self, placer)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Update static data
|
-- Update static data
|
||||||
local le = cart:get_luaentity()
|
local le = cart:get_luaentity()
|
||||||
if le then
|
if le then
|
||||||
le._staticdata = make_staticdata( railtype, railpos, cart_dir )
|
le._staticdata = make_staticdata( railtype, railpos, cart_dir )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Call placer
|
||||||
|
if le._mcl_minecarts_on_place then
|
||||||
|
print("Calling on_place")
|
||||||
|
le._mcl_minecarts_on_place(le, placer)
|
||||||
|
end
|
||||||
|
|
||||||
handle_cart_enter(le, railpos)
|
handle_cart_enter(le, railpos)
|
||||||
|
|
||||||
local pname = ""
|
local pname = ""
|
||||||
|
@ -1118,6 +1119,20 @@ register_minecart({
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
function table_metadata(table)
|
||||||
|
return {
|
||||||
|
table = table,
|
||||||
|
set_string = function(self, key, value)
|
||||||
|
print("set_string("..tostring(key)..", "..tostring(value)..")")
|
||||||
|
self.table[key] = tostring(value)
|
||||||
|
end,
|
||||||
|
get_string = function(self, key)
|
||||||
|
if self.table[key] then
|
||||||
|
return tostring(self.table[key])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
-- Minecart with Command Block
|
-- Minecart with Command Block
|
||||||
register_minecart({
|
register_minecart({
|
||||||
|
@ -1139,18 +1154,27 @@ register_minecart({
|
||||||
},
|
},
|
||||||
icon = "mcl_minecarts_minecart_command_block.png",
|
icon = "mcl_minecarts_minecart_command_block.png",
|
||||||
drop = {"mcl_minecarts:minecart"},
|
drop = {"mcl_minecarts:minecart"},
|
||||||
on_rightclick = nil,
|
on_rightclick = function(self, clicker)
|
||||||
|
self._staticdata.meta = self._staticdata.meta or {}
|
||||||
|
local meta = table_metadata(self._staticdata.meta)
|
||||||
|
|
||||||
|
mesecon.commandblock.handle_rightclick(meta, clicker)
|
||||||
|
end,
|
||||||
_mcl_minecarts_on_place = function(self, placer)
|
_mcl_minecarts_on_place = function(self, placer)
|
||||||
if mesecon and mesecon.command_block then
|
-- Create a fake metadata object that stores into the cart's staticdata
|
||||||
mesecons.command_block.configure_entity(self, placer)
|
self._staticdata.meta = self._staticdata.meta or {}
|
||||||
end
|
local meta = table_metadata(self._staticdata.meta)
|
||||||
|
|
||||||
|
mesecon.commandblock.initialize(meta)
|
||||||
|
mesecon.commandblock.place(meta, placer)
|
||||||
end,
|
end,
|
||||||
on_activate_by_rail = function(self, timer)
|
on_activate_by_rail = function(self, timer)
|
||||||
if mesecon and mesecond.command_block then
|
self._staticdata.meta = self._staticdata.meta or {}
|
||||||
mesecons.command_block.resolve_command_entity(self)
|
local meta = table_metadata(self._staticdata.meta)
|
||||||
end
|
|
||||||
|
mesecon.commandblock.action_on(meta, self.object:get_pos())
|
||||||
end,
|
end,
|
||||||
creative = false
|
creative = true
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Minecart with Hopper
|
-- Minecart with Hopper
|
||||||
|
|
|
@ -211,6 +211,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local meta = formspec_metas[fs_id]
|
local meta = formspec_metas[fs_id]
|
||||||
|
formspec_metas[fs_id] = nil
|
||||||
|
|
||||||
-- Verify the command
|
-- Verify the command
|
||||||
local check, error_message = check_commands(fields.commands, player:get_player_name())
|
local check, error_message = check_commands(fields.commands, player:get_player_name())
|
||||||
|
|
Loading…
Reference in a new issue