Rework throwing code, add egg

This commit is contained in:
Wuzzy 2017-01-16 23:11:04 +01:00
parent e85a830a01
commit b6575ab192
30 changed files with 142 additions and 139 deletions

View file

@ -0,0 +1,48 @@
=== THROWING-MOD for MINETEST-C55 ===
by PilzAdam
Inroduction:
This mod adds bows and arrows to Minetest.
How to install:
Unzip the archive an place it in minetest-base-directory/mods/minetest/
if you have a windows client or a linux run-in-place client. If you have
a linux system-wide instalation place it in ~/.minetest/mods/minetest/.
If you want to install this mod only in one world create the folder
worldmods/ in your worlddirectory.
For further information or help see:
http://wiki.minetest.com/wiki/Installing_Mods
How to use the mod:
Craft a bow with the strings from the farming mod:
wood string
wood string
wood string
Craft arrows with:
flint
stick
paper
Select the bow and shoot with left mouse click. Every shoot will take 1
arrow from your inventory and wears out the bow (you have around 385
shoots).
License:
This mod was originally published by Jeija.
Sourcecode: WTFPL (see below)
See also:
http://minetest.net/
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

View file

@ -0,0 +1,90 @@
minetest.register_craftitem("mcl_throwing:arrow", {
description = "Arrow",
inventory_image = "mcl_throwing_arrow_inv.png",
groups = { ammo=1, ammo_bow=1 },
})
minetest.register_node("mcl_throwing:arrow_box", {
drawtype = "nodebox",
is_ground_content = false,
node_box = {
type = "fixed",
fixed = {
-- Shaft
{-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
--Spitze
{-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
{-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
--Federn
{6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
{7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
{7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
{6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
{7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
{8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
{8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
{7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
}
},
tiles = {"mcl_throwing_arrow.png", "mcl_throwing_arrow.png", "mcl_throwing_arrow_back.png", "mcl_throwing_arrow_front.png", "mcl_throwing_arrow_2.png", "mcl_throwing_arrow.png"},
groups = {not_in_creative_inventory=1},
})
local THROWING_ARROW_ENTITY={
physical = false,
timer=0,
visual = "wielditem",
visual_size = {x=0.4, y=0.4},
textures = {"mcl_throwing:arrow_box"},
lastpos={},
collisionbox = {0,0,0,0,0,0},
}
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
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 ~= "mcl_throwing:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 3
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
self.object:remove()
end
else
local damage = 3
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
self.object:remove()
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" then
minetest.add_item(self.lastpos, 'mcl_throwing:arrow')
self.object:remove()
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
minetest.register_entity("mcl_throwing:arrow_entity", THROWING_ARROW_ENTITY)
minetest.register_craft({
output = 'mcl_throwing:arrow 4',
recipe = {
{'default:flint'},
{'default:stick'},
{'mcl_mobitems:feather'}
}
})

View file

@ -0,0 +1 @@
default

140
mods/mcl_throwing/init.lua Normal file
View file

@ -0,0 +1,140 @@
dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua")
dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
arrows = {
{"mcl_throwing:arrow", "mcl_throwing:arrow_entity"},
}
local GRAVITY = 9.81
local mcl_throwing_shoot_arrow = function(itemstack, player)
for _,arrow in ipairs(arrows) do
if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then
player:get_inventory():remove_item("main", arrow[1])
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2])
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=-GRAVITY, z=dir.z*-3})
obj:setyaw(player:get_look_yaw()+math.pi)
minetest.sound_play("mcl_throwing_bow_shoot", {pos=playerpos})
if obj:get_luaentity().player == "" then
obj:get_luaentity().player = player
end
obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
return true
end
end
return false
end
minetest.register_tool("mcl_throwing:bow", {
description = "Bow",
inventory_image = "mcl_throwing_bow.png",
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_0")
itemstack:add_wear(wear)
return itemstack
end,
groups = {weapon_ranged=1,},
on_use = function(itemstack, user, pointed_thing)
local wear = itemstack:get_wear()
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
minetest.register_tool("mcl_throwing:bow_0", {
description = "Bow",
inventory_image = "mcl_throwing_bow_0.png",
stack_max = 1,
groups = {not_in_creative_inventory=1},
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_1")
itemstack:add_wear(wear)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
wear = itemstack:get_wear()
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
minetest.register_tool("mcl_throwing:bow_1", {
description = "Bow",
inventory_image = "mcl_throwing_bow_1.png",
stack_max = 1,
groups = {not_in_creative_inventory=1},
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_2")
itemstack:add_wear(wear)
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
wear = itemstack:get_wear()
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
minetest.register_tool("mcl_throwing:bow_2", {
description = "Bow",
inventory_image = "mcl_throwing_bow_2.png",
stack_max = 1,
groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing)
wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow")
itemstack:add_wear(wear)
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
end
return itemstack
end,
})
minetest.register_craft({
output = 'mcl_throwing:bow',
recipe = {
{'', 'default:stick', 'default:string'},
{'default:stick', '', 'default:string'},
{'', 'default:stick', 'default:string'},
}
})
minetest.register_craft({
output = 'mcl_throwing:bow',
recipe = {
{'default:string', 'default:stick', ''},
{'default:string', '', 'default:stick'},
{'default:string', 'default:stick', ''},
}
})
minetest.register_craft({
type = "fuel",
recipe = "mcl_throwing:bow",
burntime = 15,
})

View file

@ -0,0 +1 @@
name = mcl_throwing

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

View file

@ -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 },
})