1
0
Fork 0

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

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

View File

@ -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")

View File

@ -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

View File

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

View File

@ -16,7 +16,7 @@ minetest.register_craft({
output = "mcl_cake:cake",
recipe = {
{'bucket:bucket_water', 'bucket:bucket_water', 'bucket:bucket_water'},
{'default:sugar', 'default:leaves', 'default:sugar'},
{'default:sugar', 'mcl_throwing:egg', 'default:sugar'},
{'farming:wheat_harvested', 'farming:wheat_harvested', 'farming:wheat_harvested'},
},
replacements = {{"bucket:bucket_water", "bucket:bucket_empty"}},

View File

@ -151,6 +151,14 @@ minetest.register_craftitem("mcl_mobitems:leather", {
stack_max = 64,
})
minetest.register_craftitem("mcl_mobitems:egg", {
description = "Egg",
inventory_image = "mcl_mobitems_rotten_flesh.png",
wield_image = "mcl_mobitems_rotten_flesh.png",
stack_max = 16,
})
minetest.register_craftitem("mcl_mobitems:feather", {
description = "Feather",
wield_image = "mcl_mobitems_feather.png",

View File

@ -1,10 +1,10 @@
minetest.register_craftitem("throwing:arrow", {
minetest.register_craftitem("mcl_throwing:arrow", {
description = "Arrow",
inventory_image = "throwing_arrow_inv.png",
inventory_image = "mcl_throwing_arrow_inv.png",
groups = { ammo=1, ammo_bow=1 },
})
minetest.register_node("throwing:arrow_box", {
minetest.register_node("mcl_throwing:arrow_box", {
drawtype = "nodebox",
is_ground_content = false,
node_box = {
@ -27,7 +27,7 @@ minetest.register_node("throwing:arrow_box", {
{7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
}
},
tiles = {"throwing_arrow.png", "throwing_arrow.png", "throwing_arrow_back.png", "throwing_arrow_front.png", "throwing_arrow_2.png", "throwing_arrow.png"},
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},
})
@ -36,7 +36,7 @@ local THROWING_ARROW_ENTITY={
timer=0,
visual = "wielditem",
visual_size = {x=0.4, y=0.4},
textures = {"throwing:arrow_box"},
textures = {"mcl_throwing:arrow_box"},
lastpos={},
collisionbox = {0,0,0,0,0,0},
}
@ -50,7 +50,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
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 ~= "throwing:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" 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,
@ -71,17 +71,17 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
if self.lastpos.x~=nil then
if node.name ~= "air" then
minetest.add_item(self.lastpos, 'throwing:arrow')
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("throwing:arrow_entity", THROWING_ARROW_ENTITY)
minetest.register_entity("mcl_throwing:arrow_entity", THROWING_ARROW_ENTITY)
minetest.register_craft({
output = 'throwing:arrow 4',
output = 'mcl_throwing:arrow 4',
recipe = {
{'default:flint'},
{'default:stick'},

View File

@ -1,11 +1,14 @@
dofile(minetest.get_modpath("throwing").."/arrow.lua")
dofile(minetest.get_modpath("mcl_throwing").."/arrow.lua")
dofile(minetest.get_modpath("mcl_throwing").."/throwable.lua")
arrows = {
{"throwing:arrow", "throwing:arrow_entity"},
{"mcl_throwing:arrow", "mcl_throwing:arrow_entity"},
}
local throwing_shoot_arrow = function(itemstack, player)
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])
@ -13,9 +16,9 @@ local throwing_shoot_arrow = function(itemstack, player)
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=-10, z=dir.z*-3})
obj:setacceleration({x=dir.x*-3, y=-GRAVITY, z=dir.z*-3})
obj:setyaw(player:get_look_yaw()+math.pi)
minetest.sound_play("throwing_sound", {pos=playerpos})
minetest.sound_play("mcl_throwing_bow_shoot", {pos=playerpos})
if obj:get_luaentity().player == "" then
obj:get_luaentity().player = player
end
@ -26,13 +29,13 @@ local throwing_shoot_arrow = function(itemstack, player)
return false
end
minetest.register_tool("throwing:bow", {
minetest.register_tool("mcl_throwing:bow", {
description = "Bow",
inventory_image = "throwing_bow.png",
inventory_image = "mcl_throwing_bow.png",
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
wear = itemstack:get_wear()
itemstack:replace("throwing:bow_0")
itemstack:replace("mcl_throwing:bow_0")
itemstack:add_wear(wear)
return itemstack
end,
@ -40,7 +43,7 @@ minetest.register_tool("throwing:bow", {
on_use = function(itemstack, user, pointed_thing)
local wear = itemstack:get_wear()
itemstack:add_wear(wear)
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
@ -49,21 +52,21 @@ minetest.register_tool("throwing:bow", {
end,
})
minetest.register_tool("throwing:bow_0", {
minetest.register_tool("mcl_throwing:bow_0", {
description = "Bow",
inventory_image = "throwing_bow_0.png",
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("throwing:bow_1")
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 throwing_shoot_arrow(itemstack, user, pointed_thing) then
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
@ -72,21 +75,21 @@ minetest.register_tool("throwing:bow_0", {
end,
})
minetest.register_tool("throwing:bow_1", {
minetest.register_tool("mcl_throwing:bow_1", {
description = "Bow",
inventory_image = "throwing_bow_1.png",
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("throwing:bow_2")
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 throwing_shoot_arrow(itemstack, user, pointed_thing) then
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
@ -95,16 +98,16 @@ minetest.register_tool("throwing:bow_1", {
end,
})
minetest.register_tool("throwing:bow_2", {
minetest.register_tool("mcl_throwing:bow_2", {
description = "Bow",
inventory_image = "throwing_bow_2.png",
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("throwing:bow")
itemstack:replace("mcl_throwing:bow")
itemstack:add_wear(wear)
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
if mcl_throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535/385)
end
@ -114,7 +117,7 @@ minetest.register_tool("throwing:bow_2", {
})
minetest.register_craft({
output = 'throwing:bow',
output = 'mcl_throwing:bow',
recipe = {
{'', 'default:stick', 'default:string'},
{'default:stick', '', 'default:string'},
@ -122,7 +125,7 @@ minetest.register_craft({
}
})
minetest.register_craft({
output = 'throwing:bow',
output = 'mcl_throwing:bow',
recipe = {
{'default:string', 'default:stick', ''},
{'default:string', '', 'default:stick'},
@ -132,6 +135,6 @@ minetest.register_craft({
minetest.register_craft({
type = "fuel",
recipe = "throwing:bow",
recipe = "mcl_throwing:bow",
burntime = 15,
})

View File

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

View File

Before

Width:  |  Height:  |  Size: 185 B

After

Width:  |  Height:  |  Size: 185 B

View File

Before

Width:  |  Height:  |  Size: 184 B

After

Width:  |  Height:  |  Size: 184 B

View File

Before

Width:  |  Height:  |  Size: 124 B

After

Width:  |  Height:  |  Size: 124 B

View File

Before

Width:  |  Height:  |  Size: 113 B

After

Width:  |  Height:  |  Size: 113 B

View File

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

View File

Before

Width:  |  Height:  |  Size: 244 B

After

Width:  |  Height:  |  Size: 244 B

View File

Before

Width:  |  Height:  |  Size: 318 B

After

Width:  |  Height:  |  Size: 318 B

View File

Before

Width:  |  Height:  |  Size: 323 B

After

Width:  |  Height:  |  Size: 323 B

View File

Before

Width:  |  Height:  |  Size: 311 B

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

View File

@ -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")

View File

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 B