From 578709c93e494c928921aab4aa225e2017dff6ac Mon Sep 17 00:00:00 2001 From: Code-Sploit Date: Sat, 27 Feb 2021 15:35:59 +0000 Subject: [PATCH 1/7] Add Depth Strider enchantment --- mods/ITEMS/mcl_enchanting/enchantments.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 7056ba13..893ce58d 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -124,8 +124,8 @@ mcl_enchanting.enchantments.curse_of_vanishing = { inv_tool_tab = true, } --- unimplemented ---[[mcl_enchanting.enchantments.depth_strider = { +-- implemented in mcl_playerplus +mcl_enchanting.enchantments.depth_strider = { name = S("Depth Strider"), max_level = 3, primary = {}, @@ -141,7 +141,7 @@ mcl_enchanting.enchantments.curse_of_vanishing = { power_range_table = {{10, 25}, {20, 35}, {30, 45}}, inv_combat_tab = true, inv_tool_tab = false, -}]]-- +} -- implemented via on_enchant mcl_enchanting.enchantments.efficiency = { From 828c1110b11548719465c49e591dae46dedd4413 Mon Sep 17 00:00:00 2001 From: Code-Sploit Date: Sat, 27 Feb 2021 15:37:25 +0000 Subject: [PATCH 2/7] Implement Depth Strider enchantment --- mods/PLAYER/mcl_playerplus/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index e12f73fc..94dda9cf 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -197,6 +197,18 @@ minetest.register_globalstep(function(dtime) playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface") end + -- Swimming? Check if boots are enchanted with depth strider + if node_feet == "mcl_core:water_source" or node_feet == "mclx_core:river_water_source" then + local boots = player:get_inventory():get_stack("armor", 5) + local depth_strider = mcl_enchanting.get_enchantment(boots, "depth_strider") + + if depth_strider > 0 then + playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", depth_strider / 2) + end + else + playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface") + end + -- Is player suffocating inside node? (Only for solid full opaque cube type nodes -- without group disable_suffocation=1) local ndef = minetest.registered_nodes[node_head] From de9d838642a73c2d221f9f491e25e89bf52f36d6 Mon Sep 17 00:00:00 2001 From: Code-Sploit Date: Sat, 27 Feb 2021 16:10:11 +0000 Subject: [PATCH 3/7] Fix a bug and improve some things Bugs: 1) When player is in liquid and takes off his/her boots, he/her still has increased speed. Improve: 1) Check for liquid group instead of node names --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 94dda9cf..faa7e70d 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -198,7 +198,7 @@ minetest.register_globalstep(function(dtime) end -- Swimming? Check if boots are enchanted with depth strider - if node_feet == "mcl_core:water_source" or node_feet == "mclx_core:river_water_source" then + if minetest.get_item_group(node_feet, "liquid") and mcl_enchanting.get_enchantment(player:get_inventory():get_stack("armor", 5), "depth_strider") then local boots = player:get_inventory():get_stack("armor", 5) local depth_strider = mcl_enchanting.get_enchantment(boots, "depth_strider") From 99b5dff84957626d15774a9927d2cadcba44d078 Mon Sep 17 00:00:00 2001 From: Code-Sploit Date: Sat, 27 Feb 2021 16:13:05 +0000 Subject: [PATCH 4/7] Fix another bug --- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index faa7e70d..b2a61fb1 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -198,7 +198,7 @@ minetest.register_globalstep(function(dtime) end -- Swimming? Check if boots are enchanted with depth strider - if minetest.get_item_group(node_feet, "liquid") and mcl_enchanting.get_enchantment(player:get_inventory():get_stack("armor", 5), "depth_strider") then + if minetest.get_item_group(node_feet, "liquid") ~= 0 and mcl_enchanting.get_enchantment(player:get_inventory():get_stack("armor", 5), "depth_strider") then local boots = player:get_inventory():get_stack("armor", 5) local depth_strider = mcl_enchanting.get_enchantment(boots, "depth_strider") From 6ab0e0fa86845a823ff797b8de342741db038c54 Mon Sep 17 00:00:00 2001 From: Code-Sploit Date: Sun, 28 Feb 2021 14:02:48 +0000 Subject: [PATCH 5/7] Do some calculating --- mods/PLAYER/mcl_playerplus/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index b2a61fb1..73e799a3 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -198,12 +198,12 @@ minetest.register_globalstep(function(dtime) end -- Swimming? Check if boots are enchanted with depth strider - if minetest.get_item_group(node_feet, "liquid") ~= 0 and mcl_enchanting.get_enchantment(player:get_inventory():get_stack("armor", 5), "depth_strider") then + if minetest.get_item_group(node_feet, "liquid") ~= 0 and mcl_enchanting.get_enchantment(player:get_inventory():get_stack("armor", 5), "depth_strider") then local boots = player:get_inventory():get_stack("armor", 5) local depth_strider = mcl_enchanting.get_enchantment(boots, "depth_strider") if depth_strider > 0 then - playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", depth_strider / 2) + playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:surface", (depth_strider / 3) + 0.75) end else playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:surface") From 8af76f835da46c713591893bbda65a4791b68023 Mon Sep 17 00:00:00 2001 From: kay27 Date: Mon, 1 Mar 2021 01:43:00 +0400 Subject: [PATCH 6/7] Slightly tweak minecarts to be more MC-like --- mods/ENTITIES/mcl_minecarts/init.lua | 187 +++++++++++++-------------- 1 file changed, 89 insertions(+), 98 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 6ad3ff28..6c022a9b 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -12,15 +12,14 @@ local function detach_driver(self) if not self._driver then return end - mcl_player.player_attached[self._driver] = nil - local player = minetest.get_player_by_name(self._driver) + if self._driver:is_player() then + mcl_player.player_attached[self._driver:get_player_name()] = nil + self._driver:set_detach() + self._driver:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0}) + mcl_player.player_set_animation(self._driver, "stand" , 30) + end self._driver = nil self._start_pos = nil - if player then - player:set_detach() - player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0}) - mcl_player.player_set_animation(player, "stand" , 30) - end end local function activate_tnt_minecart(self, timer) @@ -62,7 +61,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o on_rightclick = on_rightclick, - _driver = nil, -- player who sits in and controls the minecart (only for minecart!) + _driver = nil, -- player (or mob) who sits in and controls the minecart (only for minecart!) _punched = false, -- used to re-send _velocity and position _velocity = {x=0, y=0, z=0}, -- only used on punch _start_pos = nil, -- Used to calculate distance for “On A Rail” achievement @@ -97,111 +96,101 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o end function cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) + -- Punch: Pick up minecart (unless TNT was ignited) + if self._boomtimer then return end + if self._driver then + detach_driver(self) + end local pos = self.object:get_pos() - if not self._railtype then - local node = minetest.get_node(vector.floor(pos)).name - self._railtype = minetest.get_item_group(node, "connect_to_raillike") + + -- Disable detector rail + local rou_pos = vector.round(pos) + local node = minetest.get_node(rou_pos) + if node.name == "mcl_minecarts:detector_rail_on" then + local newnode = {name="mcl_minecarts:detector_rail", param2 = node.param2} + minetest.swap_node(rou_pos, newnode) + mesecon.receptor_off(rou_pos) end - if not puncher or not puncher:is_player() then - local cart_dir = mcl_minecarts:get_rail_direction(pos, {x=1, y=0, z=0}, nil, nil, self._railtype) - if vector.equals(cart_dir, {x=0, y=0, z=0}) then - return + -- Drop items and remove cart entity + if not minetest.is_creative_enabled(puncher:get_player_name()) then + for d=1, #drop do + minetest.add_item(self.object:get_pos(), drop[d]) end - self._velocity = vector.multiply(cart_dir, 3) - self._old_pos = nil - self._punched = true - return - end - - -- Punch+sneak: Pick up minecart (unless TNT was ignited) - if puncher:get_player_control().sneak and not self._boomtimer then - if self._driver then - if self._old_pos then - self.object:set_pos(self._old_pos) - end - detach_driver(self) - end - - -- Disable detector rail - local rou_pos = vector.round(pos) - local node = minetest.get_node(rou_pos) - if node.name == "mcl_minecarts:detector_rail_on" then - local newnode = {name="mcl_minecarts:detector_rail", param2 = node.param2} - minetest.swap_node(rou_pos, newnode) - mesecon.receptor_off(rou_pos) - end - - -- Drop items and remove cart entity - if not minetest.is_creative_enabled(puncher:get_player_name()) then - for d=1, #drop do - minetest.add_item(self.object:get_pos(), drop[d]) - end - elseif puncher and puncher:is_player() then - local inv = puncher:get_inventory() - for d=1, #drop do - if not inv:contains_item("main", drop[d]) then - inv:add_item("main", drop[d]) - end + elseif puncher and puncher:is_player() then + local inv = puncher:get_inventory() + for d=1, #drop do + if not inv:contains_item("main", drop[d]) then + inv:add_item("main", drop[d]) end end - - self.object:remove() - return end - local vel = self.object:get_velocity() - if puncher:get_player_name() == self._driver then - if math.abs(vel.x + vel.z) > 7 then - return - end - end - - local punch_dir = mcl_minecarts:velocity_to_dir(puncher:get_look_dir()) - punch_dir.y = 0 - local cart_dir = mcl_minecarts:get_rail_direction(pos, punch_dir, nil, nil, self._railtype) - if vector.equals(cart_dir, {x=0, y=0, z=0}) then - return - end - - time_from_last_punch = math.min(time_from_last_punch, tool_capabilities.full_punch_interval) - local f = 3 * (time_from_last_punch / tool_capabilities.full_punch_interval) - - self._velocity = vector.multiply(cart_dir, f) - self._old_pos = nil - self._punched = true + self.object:remove() end cart.on_activate_by_rail = on_activate_by_rail function cart:on_step(dtime) local ctrl, player = nil, nil - if self._driver then - player = minetest.get_player_by_name(self._driver) - if player then - ctrl = player:get_player_control() - -- player detach - if ctrl.sneak then - detach_driver(self) - return + local update = {} + local vel = self.object:get_velocity() + local pos, rou_pos, node + pos = self.object:get_pos() + rou_pos = vector.round(pos) + node = minetest.get_node(rou_pos) + local g = minetest.get_item_group(node.name, "connect_to_raillike") + if self._driver and self._driver:is_player() then + player = self._driver + ctrl = player:get_player_control() + -- player detach + if ctrl.sneak then + detach_driver(self) + return + end + if g == self._railtype then + if ctrl.right then + local c = vector.multiply(minetest.yaw_to_dir(self._driver:get_look_horizontal()-1.57), 0.2) + self.object:set_velocity(vector.add(vel, {x=c.x, y=0, z=c.z})) + end + if ctrl.left then + local c = vector.multiply(minetest.yaw_to_dir(self._driver:get_look_horizontal()+1.57), 0.2) + self.object:set_velocity(vector.add(vel, {x=c.x, y=0, z=c.z})) + end + if ctrl.up then + local c = vector.multiply(self._driver:get_look_dir(), 0.2) + self.object:set_velocity(vector.add(vel, {x=c.x, y=0, z=c.z})) + end + if ctrl.down then + local c = vector.multiply(self._driver:get_look_dir(), 0.2) + self.object:set_velocity(vector.subtract(vel, {x=c.x, y=0, z=c.z})) end end end - local vel = self.object:get_velocity() - local update = {} if self._last_float_check == nil then self._last_float_check = 0 else self._last_float_check = self._last_float_check + dtime end - local pos, rou_pos, node -- Drop minecart if it isn't on a rail anymore if self._last_float_check >= mcl_minecarts.check_float_time then - pos = self.object:get_pos() - rou_pos = vector.round(pos) - node = minetest.get_node(rou_pos) - local g = minetest.get_item_group(node.name, "connect_to_raillike") + + + for _,object in pairs(minetest.get_objects_inside_radius(pos, 1.3)) do + if object ~= self.object then + local mob = object:get_luaentity() + if mob then mob = mob._cmi_is_mob == true end + if mob and (not self._driver) and not object:get_attach() then + self._driver = object + object:set_attach(self.object, "", {x=0, y=-1.75, z=-2}, {x=0, y=0, z=0}) + mobs:set_animation(self.object, "stand") + return + end + end + end + + if g ~= self._railtype and self._railtype ~= nil then -- Detach driver if player then @@ -300,8 +289,12 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o end end - if self._punched then + if update.vel then vel = vector.add(vel, self._velocity) + if vel.x>8 then vel.x = 8 end + if vel.x<-8 then vel.x = -8 end + if vel.z>8 then vel.z = 8 end + if vel.z<-8 then vel.z = -8 end self.object:set_velocity(vel) self._old_dir.y = 0 elseif vector.equals(vel, {x=0, y=0, z=0}) and (not has_fuel) then @@ -626,17 +619,14 @@ register_minecart( "mcl_minecarts_minecart_normal.png", {"mcl_minecarts:minecart"}, function(self, clicker) - local name = clicker:get_player_name() - if not clicker or not clicker:is_player() then - return - end - local player_name = clicker:get_player_name() - if self._driver and player_name == self._driver then + if not clicker or not clicker:is_player() then return end + if clicker == self._driver then detach_driver(self) - elseif not self._driver then - self._driver = player_name + else + local name = clicker:get_player_name() + self._driver = clicker self._start_pos = self.object:get_pos() - mcl_player.player_attached[player_name] = true + mcl_player.player_attached[name] = true clicker:set_attach(self.object, "", {x=0, y=-1.75, z=-2}, {x=0, y=0, z=0}) mcl_player.player_attached[name] = true minetest.after(0.2, function(name) @@ -647,6 +637,7 @@ register_minecart( mcl_tmp_message.message(clicker, S("Sneak to dismount")) end end, name) + clicker:set_look_horizontal(self.object:get_yaw()) end end, activate_normal_minecart ) From 95b0a495bcc5e6865033a45bca12c8f812e1c4fd Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 1 Mar 2021 10:51:57 +0100 Subject: [PATCH 7/7] Fix #1152 --- mods/ENTITIES/mobs_mc/villager.lua | 5 ++++- mods/ITEMS/mcl_enchanting/engine.lua | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 7e6921f9..0021a1ad 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -412,6 +412,7 @@ local init_trades = function(self, inv) offered_stack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"}) else mcl_enchanting.enchant_randomly(offered_stack, math.random(5, 19), false, false, true) + mcl_enchanting.unload_enchantments(offered_stack) end end @@ -457,7 +458,9 @@ local set_trade = function(trader, player, inv, concrete_tradenum) player_tradenum[name] = concrete_tradenum local trade = trades[concrete_tradenum] inv:set_stack("wanted", 1, ItemStack(trade.wanted[1])) - inv:set_stack("offered", 1, ItemStack(trade.offered)) + local offered = ItemStack(trade.offered) + mcl_enchanting.load_enchantments(offered) + inv:set_stack("offered", 1, offered) if trade.wanted[2] then local wanted2 = ItemStack(trade.wanted[2]) inv:set_stack("wanted", 2, wanted2) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 5bb5884c..e6f98fad 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -9,14 +9,21 @@ function mcl_enchanting.get_enchantments(itemstack) return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {} end -function mcl_enchanting.set_enchantments(itemstack, enchantments) - itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments)) +function mcl_enchanting.unload_enchantments(itemstack) local itemdef = itemstack:get_definition() + if itemdef.tool_capabilities then + itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities) + end + local meta = itemstack:get_meta() + if meta:get_string("name") == "" then + meta:set_string("description", "") + end +end + +function mcl_enchanting.load_enchantments(itemstack, enchantments) if not mcl_enchanting.is_book(itemstack:get_name()) then - if itemdef.tool_capabilities then - itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities) - end - for enchantment, level in pairs(enchantments) do + mcl_enchanting.unload_enchantments(itemstack) + for enchantment, level in pairs(enchantments or mcl_enchanting.get_enchantments(itemstack)) do local enchantment_def = mcl_enchanting.enchantments[enchantment] if enchantment_def.on_enchant then enchantment_def.on_enchant(itemstack, level) @@ -26,6 +33,11 @@ function mcl_enchanting.set_enchantments(itemstack, enchantments) tt.reload_itemstack_description(itemstack) end +function mcl_enchanting.set_enchantments(itemstack, enchantments) + itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments)) + mcl_enchanting.load_enchantments(itemstack) +end + function mcl_enchanting.get_enchantment(itemstack, enchantment) return mcl_enchanting.get_enchantments(itemstack)[enchantment] or 0 end