mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2025-01-08 17:47:30 +01:00
Update to set_bone_override
This commit is contained in:
parent
1c36a4e07c
commit
dd165ec0e9
@ -558,12 +558,25 @@ function mcl_util.set_properties(obj, props)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Update bones, but only when changed
|
||||||
function mcl_util.set_bone_position(obj, bone, pos, rot)
|
function mcl_util.set_bone_position(obj, bone, pos, rot)
|
||||||
local current_pos, current_rot = obj:get_bone_position(bone)
|
if core.get_bone_override then -- minetest >= 5.9
|
||||||
local pos_equal = not pos or vector.equals(vector.round(current_pos), vector.round(pos))
|
rot = rot and rot:apply(math.rad)
|
||||||
local rot_equal = not rot or vector.equals(vector.round(current_rot), vector.round(rot))
|
local over = obj:get_bone_override(bone)
|
||||||
if not pos_equal or not rot_equal then
|
local pos_equal = not pos or not over.position.absolute or vector.equals(vector.round(over.position.vec), vector.round(pos))
|
||||||
obj:set_bone_position(bone, pos or current_pos, rot or current_rot)
|
local rot_equal = not rot or not over.rotation.absolute or vector.equals(vector.round(over.rotation.vec), vector.round(rot))
|
||||||
|
if not pos_equal or not rot_equal then
|
||||||
|
if pos then over.position = { vec = pos, absolute = true } end
|
||||||
|
if rot then over.rotation = { vec = rot, absolute = true } end
|
||||||
|
obj:set_bone_override(bone, over)
|
||||||
|
end
|
||||||
|
else -- minetest up to 5.8
|
||||||
|
local current_pos, current_rot = obj:get_bone_position(bone)
|
||||||
|
local pos_equal = not pos or vector.equals(vector.round(current_pos), vector.round(pos))
|
||||||
|
local rot_equal = not rot or vector.equals(vector.round(current_rot), vector.round(rot))
|
||||||
|
if not pos_equal or not rot_equal then
|
||||||
|
obj:set_bone_position(bone, pos or current_pos, rot or current_rot)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ local cod = {
|
|||||||
fear_height = 4,
|
fear_height = 4,
|
||||||
do_custom = function(self)
|
do_custom = function(self)
|
||||||
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
|
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
|
||||||
self.object:set_bone_position("body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
|
mcl_util.set_bone_position(self.object, "body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
|
||||||
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
|
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
|
||||||
if self.object:get_velocity().y < 5 then
|
if self.object:get_velocity().y < 5 then
|
||||||
self.object:add_velocity({ x = 0 , y = math.random()*.014-.007, z = 0 })
|
self.object:add_velocity({ x = 0 , y = math.random()*.014-.007, z = 0 })
|
||||||
|
@ -83,7 +83,7 @@ local dolphin = {
|
|||||||
attack_type = "dogfight",
|
attack_type = "dogfight",
|
||||||
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
|
--[[ this is supposed to make them jump out the water but doesn't appear to work very well
|
||||||
do_custom = function(self,dtime)
|
do_custom = function(self,dtime)
|
||||||
self.object:set_bone_position("body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
|
mcl_util.set_bone_position(self.object, "body", vector.new(0,1,0), vector.new(degrees(dir_to_pitch(self.object:get_velocity())) * -1 + 90,0,0))
|
||||||
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
|
if minetest.get_item_group(self.standing_in, "water") ~= 0 then
|
||||||
if self.object:get_velocity().y < 5 then
|
if self.object:get_velocity().y < 5 then
|
||||||
self.object:add_velocity({ x = 0 , y = math.random()*.014-.007, z = 0 })
|
self.object:add_velocity({ x = 0 , y = math.random()*.014-.007, z = 0 })
|
||||||
|
@ -110,16 +110,16 @@ local piglin = {
|
|||||||
return
|
return
|
||||||
elseif self.trading == true then
|
elseif self.trading == true then
|
||||||
self.state = "trading"
|
self.state = "trading"
|
||||||
self.object:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(20,-20,18))
|
mcl_util.set_bone_position(self.object, "Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(20,-20,18))
|
||||||
self.object:set_bone_position("Head", vector.new(0,6.3,0), vector.new(-40,0,0))
|
mcl_util.set_bone_position(self.object, "Head", vector.new(0,6.3,0), vector.new(-40,0,0))
|
||||||
self.base_texture[2] = "default_gold_ingot.png"
|
self.base_texture[2] = "default_gold_ingot.png"
|
||||||
self.object:set_properties({textures = self.base_texture})
|
self.object:set_properties({textures = self.base_texture})
|
||||||
else
|
else
|
||||||
self.object:set_bone_position("Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20))
|
mcl_util.set_bone_position(self.object, "Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20))
|
||||||
self.base_texture[2] = self.weapon
|
self.base_texture[2] = self.weapon
|
||||||
self.object:set_properties({textures = self.base_texture})
|
self.object:set_properties({textures = self.base_texture})
|
||||||
self.object:set_bone_position("Head", vector.new(0,6.3,0), vector.new(0,0,0))
|
mcl_util.set_bone_position(self.object, "Head", vector.new(0,6.3,0), vector.new(0,0,0))
|
||||||
self.object:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0))
|
mcl_util.set_bone_position(self.object, "Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0))
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.state ~= "attack" then
|
if self.state ~= "attack" then
|
||||||
@ -139,7 +139,7 @@ local piglin = {
|
|||||||
self.object:set_animation({x=0,y=79})
|
self.object:set_animation({x=0,y=79})
|
||||||
self.trading = true
|
self.trading = true
|
||||||
self.gold_items = self.gold_items + 1
|
self.gold_items = self.gold_items + 1
|
||||||
self.object:set_bone_position("Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90))
|
mcl_util.set_bone_position(self.object, "Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90))
|
||||||
minetest.after(5, function()
|
minetest.after(5, function()
|
||||||
self.gold_items = self.gold_items - 1
|
self.gold_items = self.gold_items - 1
|
||||||
if self.gold_items == 0 then
|
if self.gold_items == 0 then
|
||||||
@ -202,7 +202,7 @@ sword_piglin.textures = {"extra_mobs_piglin.png", "default_tool_goldsword.png"}
|
|||||||
sword_piglin.on_spawn = function(self)
|
sword_piglin.on_spawn = function(self)
|
||||||
self.gold_items = 0
|
self.gold_items = 0
|
||||||
self.weapon = self.base_texture[2]
|
self.weapon = self.base_texture[2]
|
||||||
self.object:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
|
mcl_util.set_bone_position(self.object, "Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
|
||||||
end
|
end
|
||||||
sword_piglin.drops = {
|
sword_piglin.drops = {
|
||||||
{name = "mcl_tools:sword_gold",
|
{name = "mcl_tools:sword_gold",
|
||||||
|
@ -138,13 +138,9 @@ local is_swimming
|
|||||||
local set_bone_pos = mcl_util.set_bone_position
|
local set_bone_pos = mcl_util.set_bone_position
|
||||||
local set_properties = mcl_util.set_properties
|
local set_properties = mcl_util.set_properties
|
||||||
|
|
||||||
local function get_overall_velocity(vector)
|
|
||||||
local v = math.sqrt(vector.x^2 + vector.y^2 + vector.z^2)
|
|
||||||
return v
|
|
||||||
end
|
|
||||||
local function anglediff(a1, a2)
|
local function anglediff(a1, a2)
|
||||||
local a = a1 - a2
|
local a = a1 - a2
|
||||||
return math.abs((a + math.pi) % (math.pi*2) - math.pi)
|
return math.abs((a + math.pi) % (math.pi*2) - math.pi)
|
||||||
end
|
end
|
||||||
local function clamp(num, min, max)
|
local function clamp(num, min, max)
|
||||||
return math.min(max, math.max(num, min))
|
return math.min(max, math.max(num, min))
|
||||||
@ -686,12 +682,12 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
}
|
}
|
||||||
mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0}
|
mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0}
|
||||||
|
|
||||||
-- Luanti bug: get_bone_position() returns all zeros vectors.
|
-- Luanti limitation: get_bone_position() returns all zeros vectors, because models are client-side not server-side
|
||||||
-- Workaround: call set_bone_position() one time first.
|
-- Workaround: call set_bone_position() one time first.
|
||||||
player:set_bone_position("Head_Control", vector.new(0, 6.75, 0))
|
set_bone_pos(player, "Head_Control", vector.new(0, 6.75, 0))
|
||||||
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3, 5.785, 0))
|
set_bone_pos(player, "Arm_Right_Pitch_Control", vector.new(-3, 5.785, 0))
|
||||||
player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3, 5.785, 0))
|
set_bone_pos(player, "Arm_Left_Pitch_Control", vector.new(3, 5.785, 0))
|
||||||
player:set_bone_position("Body_Control", vector.new(0, 6.75, 0))
|
set_bone_pos(player, "Body_Control", vector.new(0, 6.75, 0))
|
||||||
-- Respawn dead players on joining
|
-- Respawn dead players on joining
|
||||||
if hp <= 0 then
|
if hp <= 0 then
|
||||||
player:respawn()
|
player:respawn()
|
||||||
|
Loading…
Reference in New Issue
Block a user