tweaked
This commit is contained in:
parent
307cac1395
commit
730f222cc7
50
init.lua
50
init.lua
@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
function core.spawn_item(pos, item)
|
function core.spawn_item(pos, item)
|
||||||
|
|
||||||
local stack = ItemStack(item)
|
|
||||||
local obj = core.add_entity(pos, "__builtin:item")
|
local obj = core.add_entity(pos, "__builtin:item")
|
||||||
|
|
||||||
if obj then
|
if obj then
|
||||||
obj:get_luaentity():set_item(stack:to_string())
|
obj:get_luaentity():set_item(ItemStack(item):to_string())
|
||||||
end
|
end
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
@ -100,7 +99,7 @@ end
|
|||||||
|
|
||||||
local function quick_flow(pos, node)
|
local function quick_flow(pos, node)
|
||||||
|
|
||||||
local x, z = 0.0, 0.0
|
local x, z = 0, 0
|
||||||
|
|
||||||
x = x + quick_flow_logic(node, {x = pos.x - 1, y = pos.y, z = pos.z},-1)
|
x = x + quick_flow_logic(node, {x = pos.x - 1, y = pos.y, z = pos.z},-1)
|
||||||
x = x + quick_flow_logic(node, {x = pos.x + 1, y = pos.y, z = pos.z}, 1)
|
x = x + quick_flow_logic(node, {x = pos.x + 1, y = pos.y, z = pos.z}, 1)
|
||||||
@ -335,11 +334,9 @@ core.register_entity(":__builtin:item", {
|
|||||||
step_node_inside_checks = function(self)
|
step_node_inside_checks = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local node = self.node_inside
|
|
||||||
local def = self.def_inside
|
|
||||||
|
|
||||||
-- Delete in 'ignore' nodes
|
-- Delete in 'ignore' nodes
|
||||||
if node and node.name == "ignore" then
|
if self.node_inside and self.node_inside.name == "ignore" then
|
||||||
|
|
||||||
self.itemstring = ""
|
self.itemstring = ""
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
@ -347,6 +344,8 @@ core.register_entity(":__builtin:item", {
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local def = self.def_inside
|
||||||
|
|
||||||
-- item inside block, move to vacant space
|
-- item inside block, move to vacant space
|
||||||
if def and (def.walkable == nil or def.walkable == true)
|
if def and (def.walkable == nil or def.walkable == true)
|
||||||
and (def.collision_box == nil or def.collision_box.type == "regular")
|
and (def.collision_box == nil or def.collision_box.type == "regular")
|
||||||
@ -385,19 +384,16 @@ core.register_entity(":__builtin:item", {
|
|||||||
|
|
||||||
-- don't check for slippery ground if we're not on
|
-- don't check for slippery ground if we're not on
|
||||||
-- any ground to begin with
|
-- any ground to begin with
|
||||||
local node = self.node_under
|
if self.falling_state or not self.node_under then
|
||||||
local def = self.def_under
|
|
||||||
|
|
||||||
if self.falling_state or not node then
|
|
||||||
|
|
||||||
self.slippery_state = false
|
self.slippery_state = false
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if node and def and def.walkable then
|
if self.node_under and self.def_under and self.def_under.walkable then
|
||||||
|
|
||||||
local slippery = core.get_item_group(node.name, "slippery")
|
local slippery = core.get_item_group(self.node_under.name, "slippery")
|
||||||
|
|
||||||
self.slippery_state = slippery ~= 0
|
self.slippery_state = slippery ~= 0
|
||||||
end
|
end
|
||||||
@ -405,17 +401,16 @@ core.register_entity(":__builtin:item", {
|
|||||||
|
|
||||||
step_water_physics = function(self)
|
step_water_physics = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
self.waterflow_state = self.def_inside and
|
||||||
local vel = self.object:get_velocity()
|
self.def_inside.liquidtype == "flowing"
|
||||||
local node = self.node_inside
|
|
||||||
local def = self.def_inside
|
|
||||||
|
|
||||||
self.waterflow_state = def and def.liquidtype == "flowing"
|
|
||||||
|
|
||||||
if self.waterflow_state then
|
if self.waterflow_state then
|
||||||
|
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
local vel = self.object:get_velocity()
|
||||||
|
|
||||||
-- get flow velocity
|
-- get flow velocity
|
||||||
local flow_vel = quick_flow(pos, node)
|
local flow_vel = quick_flow(pos, self.node_inside)
|
||||||
|
|
||||||
-- calculate flow force and drag
|
-- calculate flow force and drag
|
||||||
local flow_force_x = flow_vel.x * water_force
|
local flow_force_x = flow_vel.x * water_force
|
||||||
@ -470,17 +465,15 @@ core.register_entity(":__builtin:item", {
|
|||||||
|
|
||||||
step_check_timeout = function(self, dtime)
|
step_check_timeout = function(self, dtime)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
|
||||||
|
|
||||||
self.age = self.age + dtime
|
self.age = self.age + dtime
|
||||||
|
|
||||||
if time_to_live > 0 and self.age > time_to_live then
|
if time_to_live > 0 and self.age > time_to_live then
|
||||||
|
|
||||||
|
add_effects(self.object:get_pos())
|
||||||
|
|
||||||
self.itemstring = ""
|
self.itemstring = ""
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
add_effects(pos)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -489,14 +482,13 @@ core.register_entity(":__builtin:item", {
|
|||||||
|
|
||||||
step_check_custom_step = function(self, dtime, moveresult)
|
step_check_custom_step = function(self, dtime, moveresult)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
|
||||||
|
|
||||||
-- do custom step function
|
-- do custom step function
|
||||||
local name = ItemStack(self.itemstring):get_name() or ""
|
local name = ItemStack(self.itemstring):get_name() or ""
|
||||||
local custom = core.registered_items[name]
|
local custom = core.registered_items[name]
|
||||||
and core.registered_items[name].dropped_step
|
and core.registered_items[name].dropped_step
|
||||||
|
|
||||||
if custom and custom(self, pos, dtime, moveresult) == false then
|
if custom
|
||||||
|
and custom(self, self.object:get_pos(), dtime, moveresult) == false then
|
||||||
return true -- skip further checks if false
|
return true -- skip further checks if false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -505,8 +497,6 @@ core.register_entity(":__builtin:item", {
|
|||||||
|
|
||||||
step_try_collect = function(self)
|
step_try_collect = function(self)
|
||||||
|
|
||||||
local self_pos = self.object:get_pos()
|
|
||||||
|
|
||||||
-- Don't collect items if falling
|
-- Don't collect items if falling
|
||||||
if self.falling_state then
|
if self.falling_state then
|
||||||
return
|
return
|
||||||
@ -524,6 +514,7 @@ core.register_entity(":__builtin:item", {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local self_pos = self.object:get_pos()
|
||||||
local objects = core.get_objects_inside_radius(self_pos, 1.0)
|
local objects = core.get_objects_inside_radius(self_pos, 1.0)
|
||||||
|
|
||||||
for _, obj in pairs(objects) do
|
for _, obj in pairs(objects) do
|
||||||
@ -552,7 +543,8 @@ core.register_entity(":__builtin:item", {
|
|||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
|
|
||||||
-- apply air drag
|
-- apply air drag
|
||||||
if self.falling_state or (self.slippery_state and not self.waterflow_state) then
|
if self.falling_state
|
||||||
|
or (self.slippery_state and not self.waterflow_state) then
|
||||||
self.accel.x = self.accel.x - vel.x * air_drag
|
self.accel.x = self.accel.x - vel.x * air_drag
|
||||||
self.accel.z = self.accel.z - vel.z * air_drag
|
self.accel.z = self.accel.z - vel.z * air_drag
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user