From b6575ab19297db672dcfac13921ec9c0c24e5058 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 16 Jan 2017 23:11:04 +0100 Subject: [PATCH] Rework throwing code, add egg --- mods/default/crafting.lua | 4 +- mods/default/functions.lua | 44 ---------- mods/default/nodes.lua | 4 +- mods/default/textures/default_snowball.png | Bin 320 -> 0 bytes mods/default/tools.lua | 15 +--- mods/mcl_cake/init.lua | 2 +- mods/mcl_mobitems/init.lua | 8 ++ mods/{throwing => mcl_throwing}/README.txt | 0 mods/{throwing => mcl_throwing}/arrow.lua | 18 ++-- mods/{throwing => mcl_throwing}/depends.txt | 0 mods/{throwing => mcl_throwing}/init.lua | 51 ++++++------ mods/mcl_throwing/mod.conf | 1 + .../sounds/mcl_throwing_bow_shoot.ogg} | Bin .../textures/mcl_throwing_arrow.png} | Bin .../textures/mcl_throwing_arrow_2.png} | Bin .../textures/mcl_throwing_arrow_back.png} | Bin .../textures/mcl_throwing_arrow_front.png} | Bin .../textures/mcl_throwing_arrow_inv.png} | Bin .../textures/mcl_throwing_bow.png} | Bin .../textures/mcl_throwing_bow_0.png} | Bin .../textures/mcl_throwing_bow_1.png} | Bin .../textures/mcl_throwing_bow_2.png} | Bin .../textures/mcl_throwing_egg.png | Bin 0 -> 254 bytes .../textures/mcl_throwing_snowball.png | Bin 0 -> 365 bytes mods/mcl_throwing/throwable.lua | 78 ++++++++++++++++++ mods/mobs_mc/chicken.lua | 28 +------ mods/mobs_mc/skeleton.lua | 28 +++---- mods/throwing/textures/throwing_arrow_tnt.png | Bin 240 -> 0 bytes mods/throwing/textures/throwing_empty.png | Bin 68 -> 0 bytes mods/throwing/textures/throwing_string.png | Bin 382 -> 0 bytes 30 files changed, 142 insertions(+), 139 deletions(-) delete mode 100644 mods/default/textures/default_snowball.png rename mods/{throwing => mcl_throwing}/README.txt (100%) rename mods/{throwing => mcl_throwing}/arrow.lua (74%) rename mods/{throwing => mcl_throwing}/depends.txt (100%) rename mods/{throwing => mcl_throwing}/init.lua (68%) create mode 100644 mods/mcl_throwing/mod.conf rename mods/{throwing/sounds/throwing_sound.ogg => mcl_throwing/sounds/mcl_throwing_bow_shoot.ogg} (100%) rename mods/{throwing/textures/throwing_arrow.png => mcl_throwing/textures/mcl_throwing_arrow.png} (100%) rename mods/{throwing/textures/throwing_arrow_2.png => mcl_throwing/textures/mcl_throwing_arrow_2.png} (100%) rename mods/{throwing/textures/throwing_arrow_back.png => mcl_throwing/textures/mcl_throwing_arrow_back.png} (100%) rename mods/{throwing/textures/throwing_arrow_front.png => mcl_throwing/textures/mcl_throwing_arrow_front.png} (100%) rename mods/{throwing/textures/throwing_arrow_inv.png => mcl_throwing/textures/mcl_throwing_arrow_inv.png} (100%) rename mods/{throwing/textures/throwing_bow.png => mcl_throwing/textures/mcl_throwing_bow.png} (100%) rename mods/{throwing/textures/throwing_bow_0.png => mcl_throwing/textures/mcl_throwing_bow_0.png} (100%) rename mods/{throwing/textures/throwing_bow_1.png => mcl_throwing/textures/mcl_throwing_bow_1.png} (100%) rename mods/{throwing/textures/throwing_bow_2.png => mcl_throwing/textures/mcl_throwing_bow_2.png} (100%) create mode 100644 mods/mcl_throwing/textures/mcl_throwing_egg.png create mode 100644 mods/mcl_throwing/textures/mcl_throwing_snowball.png create mode 100644 mods/mcl_throwing/throwable.lua delete mode 100644 mods/throwing/textures/throwing_arrow_tnt.png delete mode 100644 mods/throwing/textures/throwing_empty.png delete mode 100644 mods/throwing/textures/throwing_string.png diff --git a/mods/default/crafting.lua b/mods/default/crafting.lua index 3a82e4dc2..5a4c81c33 100644 --- a/mods/default/crafting.lua +++ b/mods/default/crafting.lua @@ -767,8 +767,8 @@ minetest.register_craft({ minetest.register_craft({ output = 'default:snowblock', recipe = { - {'default:snowball', 'default:snowball'}, - {'default:snowball', 'default:snowball'}, + {'mcl_throwing:snowball', 'mcl_throwing:snowball'}, + {'mcl_throwing:snowball', 'mcl_throwing:snowball'}, } }) diff --git a/mods/default/functions.lua b/mods/default/functions.lua index 373deb7e2..f20df4c4d 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -658,50 +658,6 @@ minetest.register_abm({ }) --- --- Snowballs --- - -snowball_GRAVITY=9 -snowball_VELOCITY=19 - ---Shoot snowball. -snow_shoot_snowball=function (item, player, pointed_thing) - local playerpos=player:getpos() - local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "default:snowball_entity") - local dir=player:get_look_dir() - obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY}) - obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3}) - item:take_item() - return item -end - ---The snowball Entity -snowball_ENTITY={ - physical = false, - timer=0, - textures = {"default_snowball.png"}, - lastpos={}, - collisionbox = {0,0,0,0,0,0}, -} - ---Snowball_entity.on_step()--> called when snowball is moving. -snowball_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - local node = minetest.get_node(pos) - - --Become item when hitting a node. - if self.lastpos.x~=nil then --If there is no lastpos for some reason. - if node.name ~= "air" then - self.object:remove() - end - end - self.lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node -end - -minetest.register_entity("default:snowball_entity", snowball_ENTITY) - -- Global environment step function function on_step(dtime) -- print("on_step") diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 2afeaa980..7a025568b 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -2148,7 +2148,7 @@ minetest.register_node("default:snow", { sounds = default.node_sound_dirt_defaults({ footstep = {name="default_grass_footstep", gain=0.4}, }), - drop = "default:snowball 2", + drop = "mcl_throwing:snowball 2", }) minetest.register_node("default:snowblock", { @@ -2160,7 +2160,7 @@ minetest.register_node("default:snowblock", { sounds = default.node_sound_dirt_defaults({ footstep = {name="default_grass_footstep", gain=0.4}, }), - drop = "default:snowball 4", + drop = "mcl_throwing:snowball 4", }) minetest.register_node("default:cobweb", { diff --git a/mods/default/textures/default_snowball.png b/mods/default/textures/default_snowball.png deleted file mode 100644 index 11b9676241ba8f9a02f4be49d925f5461922078e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 320 zcmV-G0l)r6rOcMnz|jvefFKnPZ_a0eU;Fzz(xus?uz z-tB$Kn`~By)w1XO^^#1vkbPf~>5Dk@sKkLx3%9L@q#`0j`M3t)ZV+4PAsQT@1hj@6Le>bFO821fPJwuI};WJOP)-+J3?#Jm}d>54rP*~`c z^pmInerTr@Wd5Z9pg0oF4#W@%2>!98Q-a7_tgrE-oQ7pTr!uB3$AYgj;+Lums@> zK;D9D9C-`J1fX#VkV6~~V2S4d5~2eB3y_Pe0P*JC04M^97XccCD?p1t<3+&h(S0XD zN?{WqEY%RE;JAxgK)?zNVP~m%x%s{|ug15z&IHkL3iAa=saz0@l0%RN2Dwz%a;a00000 LNkvXXu0mjfyRe%S literal 0 HcmV?d00001 diff --git a/mods/mcl_throwing/throwable.lua b/mods/mcl_throwing/throwable.lua new file mode 100644 index 000000000..cc3682442 --- /dev/null +++ b/mods/mcl_throwing/throwable.lua @@ -0,0 +1,78 @@ +-- +-- Snowballs +-- + +local GRAVITY = 9.81 +local snowball_VELOCITY=19 +local egg_VELOCITY=19 + +--Shoot snowball. +local throw_function = function (entity_name, velocity) + local func = function(item, player, pointed_thing) + local playerpos=player:getpos() + local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, entity_name) + local dir=player:get_look_dir() + obj:setvelocity({x=dir.x*velocity, y=dir.y*velocity, z=dir.z*velocity}) + obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3}) + item:take_item() + return item + end + return func +end + +-- The snowball entity +local snowball_ENTITY={ + physical = false, + timer=0, + textures = {"mcl_throwing_snowball.png"}, + lastpos={}, + collisionbox = {0,0,0,0,0,0}, +} +local egg_ENTITY={ + physical = false, + timer=0, + textures = {"mcl_throwing_egg.png"}, + lastpos={}, + collisionbox = {0,0,0,0,0,0}, +} + +-- Snowball_entity.on_step()--> called when snowball is moving. +local on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + local node = minetest.get_node(pos) + + --Become item when hitting a node. + if self.lastpos.x~=nil then --If there is no lastpos for some reason. + if node.name ~= "air" then + self.object:remove() + end + end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node +end + +minetest.register_entity("mcl_throwing:snowball_entity", snowball_ENTITY) +minetest.register_entity("mcl_throwing:egg_entity", egg_ENTITY) + +-- Snowball +minetest.register_craftitem("mcl_throwing:snowball", { + description = "Snowball", + inventory_image = "mcl_throwing_snowball.png", + stack_max = 16, + on_use = throw_function("mcl_throwing:snowball_entity", snowball_VELOCITY), + groups = { weapon_ranged = 1 }, + on_construct = function(pos) + pos.y = pos.y - 1 + if minetest.get_node(pos).name == "default:dirt_with_grass" then + minetest.set_node(pos, {name="default:dirt_with_snow"}) + end + end, +}) + +minetest.register_craftitem("mcl_throwing:egg", { + description = "Egg", + inventory_image = "mcl_throwing_egg.png", + stack_max = 16, + on_use = throw_function("mcl_throwing:egg_entity", egg_VELOCITY), + groups = { weapon_ranged = 1 }, +}) diff --git a/mods/mobs_mc/chicken.lua b/mods/mobs_mc/chicken.lua index 899fbcd5f..5dbab11c0 100644 --- a/mods/mobs_mc/chicken.lua +++ b/mods/mobs_mc/chicken.lua @@ -107,7 +107,7 @@ mobs:register_mob("mobs_mc:chicken", { local pos = self.object:getpos() - minetest.add_item(pos, "mcl_mobitems:egg") + minetest.add_item(pos, "mcl_throwing:egg") minetest.sound_play("default_place_node_hard", { pos = pos, @@ -121,32 +121,6 @@ mobs:register_mob("mobs_mc:chicken", { --mobs:register_spawn("mobs_mc:chicken", {"default:dirt_with_grass"}, 20, 8, 7000, 1, 31000) --- from mobs_redo --- egg -minetest.register_node(":mobs:egg", { - description = "Chicken Egg", - tiles = {"mobs_chicken_egg.png"}, - inventory_image = "mobs_chicken_egg.png", - visual_scale = 0.7, - drawtype = "plantlike", - wield_image = "mobs_chicken_egg.png", - paramtype = "light", - walkable = false, - is_ground_content = true, - sunlight_propagates = true, - selection_box = { - type = "fixed", - fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} - }, - groups = {snappy = 2, dig_immediate = 3}, - after_place_node = function(pos, placer, itemstack) - if placer:is_player() then - minetest.set_node(pos, {name = "mobs:egg", param2 = 1}) - end - end, - on_use = mobs_shoot_egg -}) - -- compatibility mobs:alias_mob("mobs:chicken", "mobs_mc:chicken") diff --git a/mods/mobs_mc/skeleton.lua b/mods/mobs_mc/skeleton.lua index f577db73c..9acf50aff 100644 --- a/mods/mobs_mc/skeleton.lua +++ b/mods/mobs_mc/skeleton.lua @@ -28,15 +28,11 @@ mobs:register_mob("mobs_mc:skeleton", { damage = 1, armor = 200, drops = { - {name = "throwing:arrow", + {name = "mcl_throwing:arrow", chance = 1, min = 0, max = 2,}, - {name = "throwing:bow", - chance = 11, - min = 1, - max = 1,}, - {name = "bonemeal:bone", + {name = "default:bone", chance = 1, min = 0, max = 2,}, @@ -63,7 +59,7 @@ mobs:register_mob("mobs_mc:skeleton", { light_damage = 1, view_range = 16, attack_type = "dogshoot", - arrow = "throwing:arrow_entity", + arrow = "mcl_throwing:arrow_entity", shoot_interval = 2.5, shoot_offset = 1, --'dogshoot_switch' allows switching between shoot and dogfight modes inside dogshoot using timer (1 = shoot, 2 = dogfight) @@ -96,18 +92,18 @@ mobs:register_mob("mobs_mc:skeleton2", { damage = 3, armor = 200, drops = { - {name = "throwing:arrow", + {name = "default:coal_lump", + chance = 1, + min = 0, + max = 1,}, + {name = "default:bone", chance = 1, min = 0, max = 2,}, - {name = "throwing:bow", - chance = 11, + {name = "heads:wither_skeleton", + chance = 40, min = 1, max = 1,}, - {name = "bonemeal:bone", - chance = 1, - min = 0, - max = 2,}, }, animation = { speed_normal = 30, @@ -131,7 +127,7 @@ mobs:register_mob("mobs_mc:skeleton2", { light_damage = 0, view_range = 16, attack_type = "dogshoot", - arrow = "throwing:arrow_entity", + arrow = "mcl_throwing:arrow_entity", shoot_interval = 0.5, shoot_offset = 1, --'dogshoot_switch' allows switching between shoot and dogfight modes inside dogshoot using timer (1 = shoot, 2 = dogfight) @@ -143,7 +139,7 @@ mobs:register_spawn("mobs_mc:skeleton2", {"group:crumbly", "group:cracky", "grou arrows = { - {"throwing:arrow", "throwing:arrow_entity" }, + {"mcl_throwing:arrow", "mcl_throwing:arrow_entity" }, } -- compatibility diff --git a/mods/throwing/textures/throwing_arrow_tnt.png b/mods/throwing/textures/throwing_arrow_tnt.png deleted file mode 100644 index 651cf299f3058c05021c923824de636cd5400524..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 240 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd7G?$phPQVgfdmu-d_r8mfB*jD$B&;sfByRQ z>-X>9fByXW`}gm^fB*jf|Ifg{@c;k+*e<^d3=9mMB|(0{3@}ifGJ7Ed14F5&i(?3f ztmwgmyiEZDt{21GR5z44zHpFIcyvkPaZYdNxl1SHpIu_y&$`NF&f@bYEpNA^eXyxe z-f_|DgzT<^0sXf-l7>)u;1@HO_XIBP@QRNz4353yx{S8yjkUaI$N|&ib_xj?)SuEvA}kp z&nNLNcrzj$O9I&5a=H8jpVq{iFg@1L&~HMUd2Ju4z2EOWBe`0w25tlHXK*|oGgek( z{3hfFu|5bJh3oZt=yr%zG0pxS5wDR61dSp%olYZ~V6)kb{XND;eFTMisw!B-5aB=g0w#M9e@Zch_{1VXm|<~H*v!;`!1;Wh`g^8R@RgGg!w`>xV@n%c zVCH}0928R=@i^coJ=N6UKgR2FxllZ>Lq3Yk^lfw&0^i`tKss6IjPz8U^hY2i#