Compare commits
5 Commits
743b1738a2
...
6af9452159
Author | SHA1 | Date |
---|---|---|
AiTechEye | 6af9452159 | |
AiTechEye | b76fab4b09 | |
AiTechEye | aebcb8465d | |
AiTechEye | 2b8a4b7014 | |
AiTechEye | c1802638d6 |
|
@ -42,6 +42,16 @@ bows.register_arrow=function(name,def)
|
|||
end
|
||||
end
|
||||
|
||||
bows.automode=function(itemstack, user, pointed_thing)
|
||||
local item=itemstack:to_table()
|
||||
local meta = minetest.deserialize(item.metadata) or {}
|
||||
meta.automode = meta.automode == false
|
||||
minetest.chat_send_player(user:get_player_name(), "Auto find arrow "..(meta.automode == false and "disabled" or "enabled"))
|
||||
item.metadata = minetest.serialize(meta)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
bows.register_bow=function(name,def)
|
||||
if name==nil or name=="" then return false end
|
||||
|
||||
|
@ -55,13 +65,15 @@ bows.register_bow=function(name,def)
|
|||
description = def.description or name,
|
||||
inventory_image = def.texture or "bows_bow.png",
|
||||
on_use =bows.load,
|
||||
groups = {bow=1,stick=1},
|
||||
on_place = bows.automode,
|
||||
groups = {bow=1,stick=1}
|
||||
})
|
||||
minetest.register_tool(def.replace, {
|
||||
description = def.description or name,
|
||||
inventory_image = def.texture_loaded or "bows_bow_loaded.png",
|
||||
on_use =bows.shoot,
|
||||
groups = {bow=1,stick=1,not_in_creative_inventory=1},
|
||||
on_place = bows.automode,
|
||||
groups = {bow=1,stick=1,not_in_creative_inventory=1}
|
||||
})
|
||||
if def.craft then
|
||||
minetest.register_craft({output = def.name,recipe = def.craft})
|
||||
|
@ -71,13 +83,33 @@ end
|
|||
|
||||
bows.load=function(itemstack, user, pointed_thing)
|
||||
local inv=user:get_inventory()
|
||||
local index=user:get_wield_index()-1
|
||||
local arrow=inv:get_stack("main", index)
|
||||
if minetest.get_item_group(arrow:get_name(), "arrow")==0 then return itemstack end
|
||||
local item=itemstack:to_table()
|
||||
local meta=minetest.deserialize(item.metadata)
|
||||
local shots=bows.registed_bows[item.name .. "_loaded"].shots
|
||||
if bows.creative==false then
|
||||
local meta = minetest.deserialize(item.metadata) or {}
|
||||
local shots = bows.registed_bows[item.name .. "_loaded"].shots
|
||||
local index
|
||||
local arrow
|
||||
|
||||
if meta.automode == true then
|
||||
for i,v in pairs(inv:get_list("main")) do
|
||||
if minetest.get_item_group(v:get_name(), "arrow") > 0 then
|
||||
index = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if not index then
|
||||
return itemstack
|
||||
else
|
||||
arrow = inv:get_stack("main", index)
|
||||
end
|
||||
else
|
||||
index = user:get_wield_index()-1
|
||||
arrow = inv:get_stack("main", index)
|
||||
if minetest.get_item_group(arrow:get_name(), "arrow") == 0 then
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
if bows.creative == false then
|
||||
local c=arrow:get_count()-shots
|
||||
if c<0 then
|
||||
shots=arrow:get_count()
|
||||
|
@ -85,8 +117,11 @@ bows.load=function(itemstack, user, pointed_thing)
|
|||
end
|
||||
inv:set_stack("main",index,ItemStack(arrow:get_name() .. " " .. c))
|
||||
end
|
||||
meta={arrow=arrow:get_name(),shots=shots}
|
||||
item.metadata=minetest.serialize(meta)
|
||||
|
||||
meta.arrow = arrow:get_name()
|
||||
meta.shots = shots
|
||||
|
||||
item.metadata = minetest.serialize(meta)
|
||||
item.name=item.name .. "_loaded"
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
|
||||
bows.arrow_dig=function(self,pos,user,lastpos)
|
||||
minetest.node_dig(pos, minetest.get_node(pos), user)
|
||||
bows.arrow_remove(self)
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
bows.arrow_fire_object=function(self,target,hp,user,lastpos)
|
||||
bows.arrow_fire(self,lastpos,user,target:get_pos())
|
||||
return self
|
||||
end
|
||||
|
||||
bows.arrow_fire=function(self,pos,user,lastpos)
|
||||
lastpos = lastpos or pos
|
||||
local name=user:get_player_name()
|
||||
local node=minetest.get_node(lastpos).name
|
||||
if minetest.is_protected(lastpos, name) then
|
||||
|
|
|
@ -98,14 +98,9 @@ if node.velocity==1 then
|
|||
local dmg=(8/d)*node.radius
|
||||
if ob:get_luaentity() and not ob:get_luaentity().attachplayer and not (ob:get_luaentity().nitroglycerine_dust and ob:get_luaentity().nitroglycerine_dust==2) then
|
||||
ob:set_velocity({x=(pos2.x-pos.x)*dmg, y=(pos2.y-pos.y)*dmg, z=(pos2.z-pos.z)*dmg})
|
||||
|
||||
|
||||
if ob:get_luaentity() and ob:get_luaentity().nitroglycerine_dust then ob:get_luaentity().nitroglycerine_dust=2 end
|
||||
|
||||
elseif ob:is_player() then
|
||||
nitroglycerine.new_player=ob
|
||||
minetest.add_entity({x=pos2.x,y=pos2.y+1,z=pos2.z}, "nitroglycerine:playerp"):set_velocity({x=(pos2.x-pos.x)*dmg, y=(pos2.y-pos.y)*dmg, z=(pos2.z-pos.z)*dmg})
|
||||
nitroglycerine.new_player=nil
|
||||
ob:add_player_velocity({x=(pos2.x-pos.x)*dmg, y=(pos2.y-pos.y)*dmg, z=(pos2.z-pos.z)*dmg})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -311,66 +306,6 @@ minetest.register_entity("nitroglycerine:dust",{
|
|||
nitroglycerine_dust=1,
|
||||
})
|
||||
|
||||
minetest.register_entity("nitroglycerine:playerp",{
|
||||
hp_max = 1000,
|
||||
physical =true,
|
||||
collisionbox = {-0.5,-0.5,-0.5,0.5,1.5,0.5},
|
||||
visual = "sprite",
|
||||
textures ={"nitroglycerine_air.png"},
|
||||
is_visible = true,
|
||||
makes_footstep_sound = false,
|
||||
pointable=false,
|
||||
on_punch=function(self)
|
||||
local v=self.object:get_velocity().y
|
||||
if v<0.2 and v>-0.2 then
|
||||
self.kill(self)
|
||||
end
|
||||
end,
|
||||
kill=function(self,liquid)
|
||||
if self.ob and self.ob:get_attach() then
|
||||
self.ob:set_detach()
|
||||
if not (liquid and liquid>0) then
|
||||
|
||||
local from=math.floor((self.y+0.5)/2)
|
||||
local hit=math.floor((self.object:get_pos().y+0.5)/2)
|
||||
local d=from-hit
|
||||
if d>=0 then
|
||||
nitroglycerine.punchdmg(self.ob,d)
|
||||
end
|
||||
end
|
||||
end
|
||||
self.object:remove()
|
||||
return self
|
||||
end,
|
||||
on_activate=function(self, staticdata)
|
||||
if not nitroglycerine.new_player or minetest.check_player_privs(nitroglycerine.new_player:get_player_name(), {fly=true}) then self.object:remove() return self end
|
||||
self.ob=nitroglycerine.new_player
|
||||
self.ob:set_attach(self.object, "",{x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
self.object:set_acceleration({x=0,y=-10,z=0})
|
||||
self.y=self.object:get_pos().y
|
||||
return self
|
||||
end,
|
||||
on_step=function(self, dtime)
|
||||
self.time=self.time+dtime
|
||||
if self.time<self.timer then return self end
|
||||
self.time=0
|
||||
self.timer2=self.timer2-1
|
||||
local pos=self.object:get_pos()
|
||||
|
||||
if pos.y>self.y then self.y=pos.y end
|
||||
|
||||
local u=minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name]
|
||||
if (u and u.walkable or u.liquid_viscosity>0) or self.timer2<0 or (not self.ob or not self.ob:get_attach()) then
|
||||
self.kill(self,u.liquid_viscosity)
|
||||
end
|
||||
return self
|
||||
end,
|
||||
time=0,
|
||||
timer=0.5,
|
||||
timer2=100,
|
||||
attachplayer=1,
|
||||
})
|
||||
|
||||
minetest.register_node("nitroglycerine:icebox", {
|
||||
description = "Ice box",
|
||||
wield_scale = {x=2, y=2, z=2},
|
||||
|
|
Loading…
Reference in New Issue