+boat & attach functions

master
AiTechEye 2018-11-03 21:37:19 +01:00 committed by GitHub
parent 34890d7303
commit b45945db36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 168 additions and 12 deletions

View File

@ -108,7 +108,8 @@ minetest.register_entity("mt2d:cam",{
end
end
--input & anim
if self.ob:get_luaentity().dead then
if self.ob:get_luaentity().dead or mt2d.attach[self.username] then
self.object:set_velocity({x=((pos2.x-pos.x)*10)+self.user_pos.x,y=(-0.5+(pos2.y-pos.y))*10,z=(5-(pos.z-pos2.z))*10})
return self
elseif self.laying then
v={x=0,y=0,z=0}
@ -271,4 +272,133 @@ minetest.register_entity("mt2d:player",{
type="npc",
team="Sam",
timer=0,
})
})
minetest.register_entity("mt2d:boat",{
hp_max = 10,
physical = true,
visual = "upright_sprite",
collisionbox = {-0.9,-0.1,0,0.9,1.25,0},
visual_size={x=1.8,y=0.2},
textures = {"default_wood.png"},
is_visible = true,
makes_footstep_sound = false,
on_rightclick=function(self, clicker,name)
local name=clicker:get_player_name()
if not self.user and mt2d.user[name] and mt2d.user[name].object then
self.user=clicker
self.username=name
self.id=mt2d.user[name].id
self.ob=mt2d.user[name].object
mt2d.player_anim(self,"sit")
mt2d.set_attach(name,self.object,self.ob,{y=0.8})
elseif self.user and self.username==name then
self.user=nil
self.username=nil
self.id=nil
self.ob=nil
mt2d.set_dettach(name)
self.anim=nil
end
end,
on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
tool_capabilities.damage_groups.fleshy=tool_capabilities.damage_groups.fleshy or 1
if not self.user then
if puncher:get_inventory() then
puncher:get_inventory():add_item("main","boats:boat")
else
minetest.add_item(self.object:get_pos(),"boats:boat")
end
self.object:remove()
elseif self.object:get_hp()-tool_capabilities.damage_groups.fleshy<=0 then
self.anim=nil
mt2d.set_dettach(self.username)
mt2d.player_anim(self,"stand")
end
end,
on_step=function(self, dtime)
if self.timer>0 then
self.timer=self.timer+dtime
if self.timer>1 then
self.timer=0.001
else
return self
end
end
local v=self.object:get_velocity()
local pos=self.object:get_pos()
local l=minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y,z=0}).name]
local lu=minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=0}).name]
if l and l.liquid_viscosity>0 then
v.y=1
self.object:set_acceleration({x=0,y=0,z=0})
self.delaytimer=0
elseif lu and lu.liquid_viscosity==0 then
self.object:set_acceleration({x=0,y=-20,z=0})
self.delaytimer=0
else
self.delaytimer=self.delaytimer+dtime
self.object:set_acceleration({x=0,y=0,z=0})
v.y=0
if self.delaytimer>10 then
self.timer=0.001
else
self.timer=0
end
end
self.object:set_velocity(v)
if not self.user then
if math.abs(v.x)>0.2 then
v.x=v.x*0.99
self.object:set_velocity(v)
end
return self
elseif self.id~=mt2d.user[self.username].id then --or not (self.ob and self.ob:get_attach())
mt2d.set_dettach(self.username)
self.user=nil
self.username=nil
self.id=nil
self.ob=nil
return self
end
local key=self.user:get_player_control()
if key.left and v.x<4 then
v.x=v.x+0.1
self.delaytimer=0
self.ob:set_yaw(4.71)
elseif key.right and v.x>-4 then
v.x=v.x-0.1
self.delaytimer=0
self.ob:set_yaw(1.57)
elseif not (key.right or key.left) and math.abs(v.x)>0.2 then
v.x=v.x*0.99
self.delaytimer=0
end
self.object:set_velocity(v)
end,
timer=0,
delaytimer=0,
type="npc",
team="Sam",
})
minetest.after(0.1, function()
minetest.override_item("boats:boat", {
on_place=function(itemstack, user, pointed_thing)
local pos=pointed_thing.under
if not pos then return end
local l=minetest.registered_nodes[minetest.get_node(pos).name]
if not (l and l.liquid_viscosity>0) then return end
itemstack:take_item()
minetest.add_entity({x=pos.x,y=pos.y,z=0.05}, "mt2d:boat")
return itemstack
end,
})
end)

View File

@ -1,7 +1,8 @@
mt2d={
timer=0,
user3d={},
user={},
user3d={}, --3d users
user={}, --users data
attach={}, --attached objects (pushing them)
playeranim={
stand={x=1,y=39,speed=30},
walk={x=41,y=61,speed=30},
@ -21,7 +22,6 @@ minetest.register_privilege("leave2d", {
})
minetest.after(0.1, function()
minetest.unregister_item("boats:boat")
minetest.unregister_item("carts:cart")
minetest.registered_entities["__builtin:item"].on_activate2=minetest.registered_entities["__builtin:item"].on_activate
@ -122,6 +122,19 @@ mt2d.to_3dplayer=function(player)
end
minetest.register_globalstep(function(dtime)
for name, a in pairs(mt2d.attach) do
if not (mt2d.user[name] or mt2d.user[name].id==a.id) or not (a.ob1:get_pos() and a.ob2:get_pos()) then
minetest.after(0, function(name)
mt2d.attach[name]=nil
end,name)
break
end
local pos1=a.ob1:get_pos()
local pos2=a.ob2:get_pos()
a.ob2:set_velocity({x=((pos1.x-pos2.x)+a.pos.x)*10,y=((pos1.y-pos2.y)+a.pos.y)*10,z=((pos1.z-pos2.z)+a.pos.z)*10})
end
mt2d.timer=mt2d.timer+dtime
if mt2d.timer<2 then return end
mt2d.timer=0
@ -352,4 +365,24 @@ mt2d.get_nodes_radius=function(pos,rad)
end
end
return nodes
end
mt2d.set_attach=function(name,object,object_to_attach,pos)
pos=pos or {}
pos={x=pos.x or 0,y=pos.y or 0,z=pos.z or 0}
mt2d.attach[name]={
name=name,
id=mt2d.user[name].id,
ob1=object,
ob2=object_to_attach,
pos=pos or {x=0,y=0,z=0}
}
end
mt2d.get_attach=function(name)
return mt2d.attach[name]
end
mt2d.set_dettach=function(name)
mt2d.attach[name]=nil
end

View File

@ -2,14 +2,8 @@ minetest.register_node("mt2d:blocking", {
description = "blocking",
drawtype="airlike",
pointable=false,
--liquids_pointable=false,
mt2d=true,
groups={blockingsky=1},
--drawtype = "liquid",
--liquidtype = "source",
--liquid_range = 0,
--liquid_alternative_flowing = "mt2d:blocking",
--liquid_alternative_source = "mt2d:blocking",
after_destruct = function(pos, oldnode)
local m=minetest.get_meta(pos)
if m:get_int("reset")==0 then
@ -71,7 +65,6 @@ minetest.register_node("mt2d:blocking_stone", {
minetest.register_node("mt2d:blocking_sky", {
description = "blocking sky",
--paramtype="light",
mt2d=true,
groups={blockingsky=1},
tiles={"default_cloud.png^[colorize:#9ee7ffff"},