From 8f32bb8a52b8f97ac8b696ef650bb8bdf392f470 Mon Sep 17 00:00:00 2001 From: Andrea Plati Date: Sat, 3 Oct 2015 20:45:32 +0200 Subject: [PATCH] Alpha1 --- defaults.lua | 4 + depends.txt | 1 + functions.lua | 14 ++++ init.lua | 17 ++++ textures/spears_spear_diamond.png | Bin 0 -> 272 bytes textures/spears_spear_obsidian.png | Bin 0 -> 276 bytes textures/spears_spear_steel.png | Bin 0 -> 273 bytes textures/spears_spear_stone.png | Bin 0 -> 277 bytes tools.lua | 124 +++++++++++++++++++++++++++++ 9 files changed, 160 insertions(+) create mode 100644 defaults.lua create mode 100644 depends.txt create mode 100644 functions.lua create mode 100644 init.lua create mode 100644 textures/spears_spear_diamond.png create mode 100644 textures/spears_spear_obsidian.png create mode 100644 textures/spears_spear_steel.png create mode 100644 textures/spears_spear_stone.png create mode 100644 tools.lua diff --git a/defaults.lua b/defaults.lua new file mode 100644 index 0000000..fbee808 --- /dev/null +++ b/defaults.lua @@ -0,0 +1,4 @@ +DISABLE_STONE_SPEAR = false +DISABLE_STEEL_SPEAR = false +DISABLE_DIAMOND_SPEAR = false +DISABLE_OBSIDIAN_SPEAR = false diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/functions.lua b/functions.lua new file mode 100644 index 0000000..a2ee8be --- /dev/null +++ b/functions.lua @@ -0,0 +1,14 @@ + + +function spears_shot (itemstack, player) + local spear = itemstack:get_name() .. '_entity' + local playerpos = player:getpos() + local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear) + local dir = player:get_look_dir() + obj:setvelocity({x=dir.x*14, y=dir.y*14, z=dir.z*14}) + obj:setacceleration({x=-dir.x*.5, y=-9.8, z=-dir.z*.5}) + obj:setyaw(player:get_look_yaw()+math.pi) + minetest.sound_play("spears_sound", {pos=playerpos}) + obj:get_luaentity().wear = itemstack:get_wear() + return true +end diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..3a45772 --- /dev/null +++ b/init.lua @@ -0,0 +1,17 @@ +dofile(minetest.get_modpath("spears").."/defaults.lua") + +local input = io.open(minetest.get_modpath("spears").."/spears.conf", "r") +if input then + dofile(minetest.get_modpath("spears").."/spears.conf") + input:close() + input = nil +end + +dofile(minetest.get_modpath("spears").."/functions.lua") + +dofile(minetest.get_modpath("spears").."/tools.lua") + + +if minetest.setting_get("log_mods") then + minetest.log("action", "spears loaded") +end diff --git a/textures/spears_spear_diamond.png b/textures/spears_spear_diamond.png new file mode 100644 index 0000000000000000000000000000000000000000..7a852b907c9de501256aa859081a129395a88107 GIT binary patch literal 272 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(|#go(#fqCD#@KMK}vQ zB8wRqxP?KOkzv*x37{Z*iKnkC`+Y8EAq`HSS(jLWLUTP`978NlC*Sz>|NQ@T|Lgym zi~jhVuE14Hd!Q{AMLE$FD3CSG6aeJf>FJAs$Vu!^|iF5O9+&6JcNJ>aZe0ntJ z-+bG;zJmd+GatTW_iOule7?b?6b7D%)m(qnuL|(EE|F>qWz=kYFh%8>z@BBo$sCUM zLPjksCLBxWxcIU6w18VskgS=rgs1PW7i|WUCNoduRXoiwLy-pv7-aHd^ZVH(p8*}p N;OXk;vd$@?2>`1vTRs2) literal 0 HcmV?d00001 diff --git a/textures/spears_spear_obsidian.png b/textures/spears_spear_obsidian.png new file mode 100644 index 0000000000000000000000000000000000000000..6ec0ab4ddfba5dc5db816eeaa9343c1900624609 GIT binary patch literal 276 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(|#go(#fqCD#@KMK}vQ zB8wRqxP?KOkzv*x37{Z*iKnkC`+Y8EAr0-Bza~Ef3N7?>aSX9IojhUs^#AA2pZ~vq z<$?G1%#sZg8yg?~-?B`jE&qPKVa@M<-3#*$sksI5B%JClPOA9wMV47yUHb6P$4;R*^^znW#TV{Q zZ33c~e()$-?JJZ#A~-0&Yb`3Y!#DBpHlb8XFrK88ZJQ<})7AxBzr1 NgQu&X%Q~loCIFNxUSa?M literal 0 HcmV?d00001 diff --git a/textures/spears_spear_stone.png b/textures/spears_spear_stone.png new file mode 100644 index 0000000000000000000000000000000000000000..fead8b353a2f2c8f9b80330c8df003ba0fd3c3a8 GIT binary patch literal 277 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(|#go(#fqCD#@KMK}vQ zB8wRqxP?KOkzv*x37{Z*iKnkC`+Y8EAx-Yx{Y@D_p+%l9jv*GOlYP9sfB*meJ)h0> z-*%o-VKYOc2^=%*>i?ZdSoLFaWB26Vg)0xdw?E0&v1wmQ#g{L#%;M_Ohks6f?s4_} zffEM~9GD>f{LBA0AB%a~w9fGO+ZPzEvH#aHQH43-Kvd`h`;~188cJ6M)^K?kvMg8G z*!IA5u7oqkuZa^BU0O}-oICpRW7;N6`L8xYX literal 0 HcmV?d00001 diff --git a/tools.lua b/tools.lua new file mode 100644 index 0000000..7628521 --- /dev/null +++ b/tools.lua @@ -0,0 +1,124 @@ +function spears_register_spear(kind, desc, eq, toughness, craft) + + minetest.register_tool("spears:spear_" .. kind, { + description = desc .. " spear", + inventory_image = "spears_spear_" .. kind .. ".png", + wield_scale= {x=2,y=1,z=1}, + on_drop = function(itemstack, user, pointed_thing) + spears_shot(itemstack, user) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + end, + on_place = function(itemstack, user, pointed_thing) + minetest.add_item(pointed_thing.above, itemstack) + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + end, + tool_capabilities = { + full_punch_interval = 1.5, + max_drop_level=1, + groupcaps={ + cracky = {times={[3]=2}, uses=toughness, maxlevel=1}, + }, + damage_groups = {fleshy=eq}, + } + }) + + --minetest.register_node("spears:spear_" .. kind .. "_box", { + --drawtype = "nodebox", + --node_box = { + --type = "fixed", + --fixed = { + ---- Shaft + --{-60/16, -2/16, 2/16, 4, 1/16, -1/16}, + ----Spitze + --{-4, -1/16, 1/16, -62/16, 0, 0}, + --{-62/16, -1.5/16, 1.5/16, -60/16, 0.5/16, -0.5/16}, + --} + --}, + --tiles = {"spears_spear_box.png"}, + --groups = {not_in_creative_inventory=1}, + --}) + + local SPEAR_ENTITY={ + physical = false, + timer=0, + visual = "wielditem", + visual_size = {x=0.15, y=0.1}, + textures = {"spears:spear_" .. kind}, + lastpos={}, + collisionbox = {0,0,0,0,0,0}, + } + + SPEAR_ENTITY.on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + local node = minetest.get_node(pos) + if not self.wear then + self.object:remove() + return + end + + if self.timer>0.2 then + local objs = minetest.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 then + if obj:get_luaentity().name ~= "spears:spear_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then + local speed = vector.length(self.object:getvelocity()) + local damage = ((speed + eq)^1.2)/3 + obj:punch(self.object, 1.0, { + full_punch_interval=1.0, + damage_groups={fleshy=damage}, + }, nil) + self.object:remove() + minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, count=1, wear=self.wear+65535/toughness, metadata=""}) + end + end + end + end + + if self.lastpos.x~=nil then + if node.name ~= "air" and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt')) and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then + self.object:remove() + minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, count=1, wear=self.wear+65535/toughness, metadata=""}) + end + end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} + end + + minetest.register_entity("spears:spear_" .. kind .. "_entity", SPEAR_ENTITY) + + minetest.register_craft({ + output = 'spears:spear_' .. kind .. ' 4', + recipe = { + {'group:wood', 'group:wood', craft}, + } + }) + + minetest.register_craft({ + output = 'spears:spear_' .. kind .. ' 4', + recipe = { + {craft, 'group:wood', 'group:wood'}, + } + }) +end + +if not DISABLE_STONE_SPEAR then + spears_register_spear('stone', 'Stone', 4, 20, 'group:stone') +end + +if not DISABLE_STEEL_SPEAR then + spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_ingot') +end + +if not DISABLE_OBSIDIAN_SPEAR then + spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian') +end + +if not DISABLE_DIAMOND_SPEAR then + spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond') +end