From 85c2284da5e26f7967530ef9b959711341678c1f Mon Sep 17 00:00:00 2001 From: MrIbby Date: Fri, 6 Nov 2015 19:24:55 -0800 Subject: [PATCH] Add throwable cake --- README.txt | 1 + init.lua | 54 +++++++++++++++++++++++++++++++++++++++ textures/cake_entity.png | Bin 0 -> 359 bytes 3 files changed, 55 insertions(+) create mode 100644 textures/cake_entity.png diff --git a/README.txt b/README.txt index 165de15..f6fa7db 100644 --- a/README.txt +++ b/README.txt @@ -35,6 +35,7 @@ Authors of textures: -------------------- rubenwardy (CC-BY-SA): cake_bottom.png, derivative + cake_entity.png cake_inner.png, derivative cake_side.png, derivative cake_sugar.png diff --git a/init.lua b/init.lua index 2c8edd4..7405380 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,7 @@ +local throwable_cake = false + +-- CAKE -- + local sizes = {-0.4375, -0.3125, -0.1875, -0.0625, 0.0625, 0.1875, 0.3125} for i, size in ipairs(sizes) do @@ -70,3 +74,53 @@ minetest.register_craft({ output = "cake:cake", recipe = {"farming:flour", "group:water_bucket", "group:food_sugar", "group:food_sugar"} }) + +-- THROWABLE CAKE -- + +minetest.register_entity("cake:cake_entity", { + physical = false, + timer = 0, + textures = {"cake_entity.png"}, + lastpos = {}, + collisionbox = {0,0,0,0,0,0}, + on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + local node = minetest.env:get_node(pos) + + if self.timer>0.2 then + local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) + for k, obj in pairs(objs) do + if obj:get_luaentity() == nil or obj:get_luaentity().name ~= "cake:cake_entity" and obj:get_luaentity().name ~= "__builtin:item" then + obj:set_hp(obj:get_hp() + 7) + self.object:remove() + end + end + end + + if self.lastpos.x~=nil then + if node.name ~= "air" then + minetest.env:add_item(self.lastpos, 'cake:cake') + self.object:remove() + end + end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} + end, +}) + +if throwable_cake then + minetest.override_item("cake:cake", { + on_use = function(itemstack, player, pointed_thing) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + local playerpos = player:getpos() + local obj = minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "cake:cake_entity") + local dir = player:get_look_dir() + obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19}) + obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3}) + obj:setyaw(player:get_look_yaw()+math.pi) + return itemstack + end, + }) +end diff --git a/textures/cake_entity.png b/textures/cake_entity.png new file mode 100644 index 0000000000000000000000000000000000000000..6739b333ffb47419456c3f32908536da42341d52 GIT binary patch literal 359 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPq3m2ab*V^TF4}n6mnIRD+&iT2ysd*(pE(3#eQEFmI zYKlU6W=V#EyQgnJie4%^Q2ex~i(`nz>Eu8E|JyUGHgq;RIc#Lqxxr$c)U@%}>ZFrV zZY73pPYfC|O$-B%X5F4?yxou|$>~~7(juj|aplni2M#cp zbI2ZeveE7F?dR(yTU1>OwOrWp=kGr@k1s*Up!q}Qk=YYAXdan8MSI$s)IEP2Dtx!g u?`cz4Tca5m>L{|@?aP!C9lF+&Cy6r@_2fQM+bfa@@~@|>pUXO@geCywk%Kb; literal 0 HcmV?d00001