From 93edf00da6b9e87ff2806d8893a4dcececa0143c Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 20 Jun 2017 23:40:18 +0200 Subject: [PATCH] Refactor tamed wolf code --- wolf.lua | 181 +++++++++++++++++++++++-------------------------------- 1 file changed, 74 insertions(+), 107 deletions(-) diff --git a/wolf.lua b/wolf.lua index 799ecb7..314f282 100644 --- a/wolf.lua +++ b/wolf.lua @@ -1,111 +1,8 @@ --License for code WTFPL and otherwise stated in readmes --- Tamed wolf -mobs:register_mob("mobs_mc:dog", { - type = "npc", - passive = true, - hp_min = 20, - hp_max = 20, - collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4}, - rotate = -180, - visual = "mesh", - mesh = "wolf.b3d", - textures = { - {"mobs_mc_wolf_tame.png^(mobs_mc_wolf_collar.png^[colorize:#A00000:192)"}, - }, - visual_size = {x=3, y=3}, - makes_footstep_sound = true, - sounds = { - war_cry = "mobs_wolf_attack", - }, - view_range = 16, - stepheight = 1.1, - owner = "", - order = "follow", - floats = {x=0,y=0,z=0}, - walk_velocity = 4, - run_velocity = 4, - stepheight = 1.1, - damage = 4, - group_attack = true, - attacks_monsters = true, - attack_type = "dogfight", - drops = { - {name = "mobs:meat_raw", - chance = 1, - min = 2, - max = 3,}, - }, - drawtype = "front", - water_damage = 0, - lava_damage = 5, - light_damage = 0, - on_rightclick = function(self, clicker) - local item = clicker:get_wielded_item() - if item:get_name() == "mobs:meat_raw" then - local hp = self.object:get_hp() - if hp + 4 > self.hp_max then return end - if not minetest.setting_getbool("creative_mode") then - item:take_item() - clicker:set_wielded_item(item) - end - self.object:set_hp(hp+4) - else - if self.owner == "" then - self.owner = clicker:get_player_name() - else - local formspec = "size[8,4]" - formspec = formspec .. "textlist[2.85,0;2.1,0.5;dialog;What can I do for you?]" - formspec = formspec .. "button_exit[1,1;2,2;dfollow;follow]" - formspec = formspec .. "button_exit[5,1;2,2;dstand;stand]" - formspec = formspec .. "button_exit[0,2;4,4;dfandp;follow and protect]" - formspec = formspec .. "button_exit[4,2;4,4;dsandp;stand and protect]" - formspec = formspec .. "button_exit[1,2;2,2;dgohome; go home]" - formspec = formspec .. "button_exit[5,2;2,2;dsethome; sethome]" - minetest.show_formspec(clicker:get_player_name(), "order", formspec) - minetest.register_on_player_receive_fields(function(clicker, formname, fields) - if fields.dfollow then - self.order = "follow" - self.attacks_monsters = false - end - if fields.dstand then - self.order = "stand" - self.attacks_monsters = false - end - if fields.dfandp then - self.order = "follow" - self.attacks_monsters = true - end - if fields.dsandp then - self.order = "stand" - self.attacks_monsters = true - end - if fields.dsethome then - self.floats = self.object:getpos() - end - if fields.dgohome then - if self.floats then - self.order = "stand" - self.object:setpos(self.floats) - end - end - end) - end - end - end, - animation = { - speed_normal = 50, speed_run = 100, - stand_start = 40, stand_end = 45, - walk_start = 0, walk_end = 40, - run_start = 0, run_end = 40, - }, - jump = true, - step = 1, -}) - --- Wolf by KrupnoPavel -mobs:register_mob("mobs_mc:wolf", { +-- Wolf +local wolf = { type = "npc", hp_min = 8, hp_max = 8, @@ -160,9 +57,79 @@ mobs:register_mob("mobs_mc:wolf", { jump = true, attacks_monsters = true, step = 0.5, -}) -mobs:register_spawn("mobs_mc:wolf", {"default:dirt_with_snow","default:podzol", "default:snowblock"}, 20, 0, 19000, 1, 31000) +} +mobs:register_mob("mobs_mc:wolf", wolf) + +-- Tamed wolf + +local dog = table.copy(wolf) +dog.step = 1 +dog.passive = true +dog.hp_min = 20 +dog.hp_max = 20 +dog.textures = {{"mobs_mc_wolf_tame.png^(mobs_mc_wolf_collar.png^[colorize:#A00000:192)"}} +dog.owner = "" +dog.order = "follow" +dog.step = 1 +dog.on_rightclick = function(self, clicker) + local item = clicker:get_wielded_item() + if item:get_name() == "mobs:meat_raw" then + local hp = self.object:get_hp() + if hp + 4 > self.hp_max then return end + if not minetest.setting_getbool("creative_mode") then + item:take_item() + clicker:set_wielded_item(item) + end + self.object:set_hp(hp+4) + else + if self.owner == "" then + self.owner = clicker:get_player_name() + else + local formspec = "size[8,4]" + formspec = formspec .. "textlist[2.85,0;2.1,0.5;dialog;What can I do for you?]" + formspec = formspec .. "button_exit[1,1;2,2;dfollow;follow]" + formspec = formspec .. "button_exit[5,1;2,2;dstand;stand]" + formspec = formspec .. "button_exit[0,2;4,4;dfandp;follow and protect]" + formspec = formspec .. "button_exit[4,2;4,4;dsandp;stand and protect]" + formspec = formspec .. "button_exit[1,2;2,2;dgohome; go home]" + formspec = formspec .. "button_exit[5,2;2,2;dsethome; sethome]" + minetest.show_formspec(clicker:get_player_name(), "order", formspec) + minetest.register_on_player_receive_fields(function(clicker, formname, fields) + if fields.dfollow then + self.order = "follow" + self.attacks_monsters = false + end + if fields.dstand then + self.order = "stand" + self.attacks_monsters = false + end + if fields.dfandp then + self.order = "follow" + self.attacks_monsters = true + end + if fields.dsandp then + self.order = "stand" + self.attacks_monsters = true + end + if fields.dsethome then + self.floats = self.object:getpos() + end + if fields.dgohome then + if self.floats then + self.order = "stand" + self.object:setpos(self.floats) + end + end + end) + end + end +end + +mobs:register_mob("mobs_mc:dog", dog) + +-- Spawn +mobs:register_spawn("mobs_mc:wolf", {"default:dirt_with_snow","default:podzol", "default:snowblock"}, 20, 0, 19000, 1, 31000) -- Compatibility mobs:alias_mob("mobs:wolf", "mobs_mc:wolf")