From 5ed92a2695ebb9d9dd713fa3cedd47de0678cd58 Mon Sep 17 00:00:00 2001 From: PrairieWind Date: Thu, 27 Apr 2023 17:01:32 -0600 Subject: [PATCH] Make pigs mountable without carrot on a stick, but require the carrot on a stick to actually control the pig --- mods/ENTITIES/mobs_mc/pig.lua | 47 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index 7f2ebc88d..9084c5d4d 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -82,7 +82,7 @@ mcl_mobs.register_mob("mobs_mc:pig", { end -- if driver present allow control of horse - if self.driver then + if self.driver and self.driver:get_wielded_item():get_name() == "mcl_mobitems:carrot_on_a_stick" then mcl_mobs.drive(self, "walk", "stand", false, dtime) @@ -149,18 +149,14 @@ mcl_mobs.register_mob("mobs_mc:pig", { return end - -- Mount or detach player - local name = clicker:get_player_name() - if self.driver and clicker == self.driver then - -- Detach if already attached - mcl_mobs.detach(clicker, {x=1, y=0, z=0}) - return - - elseif not self.driver and self.saddle == "yes" and wielditem:get_name() == "mcl_mobitems:carrot_on_a_stick" then - -- Ride pig if it has a saddle and player uses a carrot on a stick - - mcl_mobs.attach(self, clicker) - + -- Should make pig go faster when right clicked with carrot on a stick. + -- FIXME: needs work on the going faster part. + --[[if self.driver and clicker == self.driver and self.driver:get_wielded_item():get_name() == "mcl_mobitems:carrot_on_a_stick" then + if not self.v3 then + self.v3 = 0 + self.max_speed_forward = 100 + self.accel = 10 + end if not minetest.is_creative_enabled(clicker:get_player_name()) then local inv = self.driver:get_inventory() @@ -177,6 +173,19 @@ mcl_mobs.register_mob("mobs_mc:pig", { end inv:set_stack("main",self.driver:get_wield_index(), wielditem) end + end]] + + -- Mount or detach player + local name = clicker:get_player_name() + if self.driver and clicker == self.driver then -- and self.driver:get_wielded_item():get_name() ~= "mcl_mobitems:carrot_on_a_stick" then -- Note: This is for when the ability to make the pig go faster is implemented + -- Detach if already attached + mcl_mobs.detach(clicker, {x=1, y=0, z=0}) + return + + elseif not self.driver and self.saddle == "yes" then + -- Ride pig if it has a saddle + + mcl_mobs.attach(self, clicker) return -- Capture pig @@ -195,6 +204,18 @@ mcl_mobs.register_mob("mobs_mc:pig", { return false end end, + + after_activate = function(self, staticdata, def, dtime) + if self.saddle == "yes" then -- Make saddle load upon rejoin + self.base_texture = { + "mobs_mc_pig.png", -- base + "mobs_mc_pig_saddle.png", -- saddle + } + self.object:set_properties({ + textures = self.base_texture + }) + end + end, }) mcl_mobs:spawn_specific(