From c3b6cf758c58e49b8c8f2c3d182c8163eae84834 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 16 Mar 2024 07:59:39 +0000 Subject: [PATCH] Start adding hooks for implpementing minecart with command block --- mods/ENTITIES/mcl_minecarts/init.lua | 18 ++++++++++++++++-- .../REDSTONE/mesecons_commandblock/init.lua | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index f20e262f2..22b3f49f0 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -436,7 +436,6 @@ local function hopper_take_item(self, dtime) local objs = minetest.get_objects_inside_radius(above_pos, 1.25) if objs then - mcl_log("there is an itemstring. Number of objs: ".. #objs) for k, v in pairs(objs) do @@ -581,6 +580,7 @@ local function register_entity(entity_id, def) on_rightclick = def.on_rightclick, on_activate_by_rail = def.on_activate_by_rail, _mcl_minecarts_on_enter = def._mcl_minecarts_on_enter, + _mcl_minecarts_on_place = def._mcl_minecarts_on_place, _driver = nil, -- player who sits in and controls the minecart (only for minecart!) _passenger = nil, -- for mobs @@ -932,6 +932,11 @@ 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) 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 local le = cart:get_luaentity() if le then @@ -1176,7 +1181,16 @@ register_minecart({ icon = "mcl_minecarts_minecart_command_block.png", drop = {"mcl_minecarts:minecart"}, on_rightclick = nil, - on_activate_by_rail = nil, + _mcl_minecarts_on_place = function(self, placer) + if mesecon and mesecon.command_block then + mesecons.command_block.configure_entity(self, placer) + end + end, + on_activate_by_rail = function(self, timer) + if mesecon and mesecond.command_block then + mesecons.command_block.resolve_command_entity(self) + end + end, creative = false }) diff --git a/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua b/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua index 3902c3c18..ec41785df 100644 --- a/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua @@ -3,6 +3,8 @@ local F = minetest.formspec_escape local tonumber = tonumber +--mesecon.command_block = {} + local color_red = mcl_colors.RED local command_blocks_activated = minetest.settings:get_bool("mcl_enable_commandblocks", true)