Rework throwing code, add egg
This commit is contained in:
parent
e85a830a01
commit
b6575ab192
30 changed files with 142 additions and 139 deletions
|
@ -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'},
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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", {
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 320 B |
|
@ -412,17 +412,4 @@ minetest.register_tool("default:shears", {
|
|||
}
|
||||
})
|
||||
|
||||
-- Snowball
|
||||
minetest.register_craftitem("default:snowball", {
|
||||
description = "Snowball",
|
||||
inventory_image = "default_snowball.png",
|
||||
stack_max = 64,
|
||||
on_use = snow_shoot_snowball,
|
||||
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,
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue