added better painting for mcl

This commit is contained in:
Alexsandro Percy 2024-10-15 18:35:51 -03:00
parent 8a91a85cff
commit 6ac8623c78
2 changed files with 67 additions and 63 deletions

View File

@ -8,7 +8,7 @@ local LATER_DRAG_FACTOR = 2.0
-- entity
--
minetest.register_entity('steampunk_blimp:fire',{
core.register_entity('steampunk_blimp:fire',{
initial_properties = {
physical = false,
collide_with_objects=false,
@ -22,13 +22,13 @@ initial_properties = {
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
self.sdata = core.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
return core.serialize(self.sdata)
end,
})
@ -36,7 +36,7 @@ initial_properties = {
--
-- seat pivot
--
minetest.register_entity('steampunk_blimp:stand_base',{
core.register_entity('steampunk_blimp:stand_base',{
initial_properties = {
physical = false,
collide_with_objects=false,
@ -49,17 +49,17 @@ minetest.register_entity('steampunk_blimp:stand_base',{
dist_moved = 0,
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
self.sdata = core.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
return core.serialize(self.sdata)
end,
})
minetest.register_entity("steampunk_blimp:blimp", {
core.register_entity("steampunk_blimp:blimp", {
initial_properties = {
physical = true,
collide_with_objects = true, --true,
@ -114,7 +114,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
item = "steampunk_blimp:blimp",
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
return core.serialize({
stored_baloon_buoyancy = self._baloon_buoyancy,
stored_energy = self._energy,
stored_water_level = self._water_level,
@ -140,14 +140,14 @@ minetest.register_entity("steampunk_blimp:blimp", {
if self._remove ~= true then
airutils.save_inventory(self)
end
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
if self.sound_handle_pistons then minetest.sound_stop(self.sound_handle_pistons) end
if self.sound_handle then core.sound_stop(self.sound_handle) end
if self.sound_handle_pistons then core.sound_stop(self.sound_handle_pistons) end
end,
on_activate = function(self, staticdata, dtime_s)
--minetest.chat_send_all('passengers: '.. dump(self._passengers))
--core.chat_send_all('passengers: '.. dump(self._passengers))
if staticdata ~= "" and staticdata ~= nil then
local data = minetest.deserialize(staticdata) or {}
local data = core.deserialize(staticdata) or {}
self._baloon_buoyancy = data.stored_baloon_buoyancy or 0
self._energy = data.stored_energy or 0
@ -170,7 +170,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
if self._remove ~= true then
self._inv_id = data.stored_inv_id
end
--minetest.debug("loaded: ", self._energy)
--core.debug("loaded: ", self._energy)
local properties = self.object:get_properties()
properties.infotext = data.stored_owner .. " nice blimp"
self.object:set_properties(properties)
@ -191,7 +191,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
steampunk_blimp.paint2(self, self.color2)
local pos = self.object:get_pos()
local fire=minetest.add_entity(pos,'steampunk_blimp:fire')
local fire=core.add_entity(pos,'steampunk_blimp:fire')
fire:set_attach(self.object,'',{x=0.0,y=0.0,z=0.0},{x=0,y=0,z=0})
self.fire = fire
@ -203,7 +203,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
do
self._passenger_is_sit[i] = 0
self._passengers_base_pos[i] = steampunk_blimp.copy_vector(steampunk_blimp.passenger_pos[i])
self._passengers_base[i]=minetest.add_entity(pos,'steampunk_blimp:stand_base')
self._passengers_base[i]=core.add_entity(pos,'steampunk_blimp:stand_base')
self._passengers_base[i]:set_attach(self.object,'',self._passengers_base_pos[i],{x=0,y=0,z=0})
end
@ -219,7 +219,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
self.object:set_armor_groups({immortal=1})
if self._remove ~= true then
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
local inv = core.get_inventory({type = "detached", name = self._inv_id})
-- if the game was closed the inventories have to be made anew, instead of just reattached
if not inv then
airutils.create_inventory(self, steampunk_blimp.trunk_slots)
@ -267,7 +267,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
local newyaw
local newpitch
local hull_direction = minetest.yaw_to_dir(yaw)
local hull_direction = core.yaw_to_dir(yaw)
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
local velocity = self.object:get_velocity()
local wind_speed = airutils.get_wind(curr_pos, 0.15)
@ -317,7 +317,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
--roll adjust
---------------------------------
local sdir = minetest.yaw_to_dir(newyaw)
local sdir = core.yaw_to_dir(newyaw)
local snormal = {x=sdir.z,y=0,z=-sdir.x} -- rightside, dot is negative
local prsr = steampunk_blimp.dot(snormal,nhdir)
local rollfactor = -15
@ -353,13 +353,13 @@ minetest.register_entity("steampunk_blimp:blimp", {
end
self._last_roll = newroll
end
--minetest.chat_send_all('newroll: '.. newroll)
--core.chat_send_all('newroll: '.. newroll)
---------------------------------
-- end roll
if steampunk_blimp.wind_enabled then
--local wind_yaw = minetest.dir_to_yaw(wind_speed)
--minetest.chat_send_all("x: "..wind_speed.x.. " - z: "..wind_speed.z.." - yaw: "..math.deg(wind_yaw).. " - orig: "..wind_yaw)
--local wind_yaw = core.dir_to_yaw(wind_speed)
--core.chat_send_all("x: "..wind_speed.x.. " - z: "..wind_speed.z.." - yaw: "..math.deg(wind_yaw).. " - orig: "..wind_yaw)
if self.anchored == false and self.isonground == false then
accel = vector.add(accel, wind_speed)
@ -397,7 +397,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
return
end
local is_admin
is_admin = minetest.check_player_privs(puncher, {server=true})
is_admin = core.check_player_privs(puncher, {server=true})
local name = puncher:get_player_name()
if self.owner == nil then
self.owner = name
@ -408,7 +408,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
local itmstck=puncher:get_wielded_item()
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
--minetest.chat_send_all(item_name)
--core.chat_send_all(item_name)
if is_attached == true then
--refuel
@ -427,7 +427,11 @@ minetest.register_entity("steampunk_blimp:blimp", {
-- deal with painting or destroying
if itmstck then
--core.chat_send_all(dump(item_name))
local find_str = 'dye:'
if airutils.is_mcl then
find_str = 'mcl_dyes:'
end
local _,indx = item_name:find(find_str)
if indx then
@ -437,8 +441,8 @@ minetest.register_entity("steampunk_blimp:blimp", {
color = item_name:sub(indx+1)
end
local colstr = steampunk_blimp.colors[color]
--minetest.chat_send_all(color ..' '.. dump(colstr))
if colstr and (name == self.owner or minetest.check_player_privs(puncher, {protection_bypass=true})) then
--core.chat_send_all(color ..' '.. dump(colstr))
if colstr and (name == self.owner or core.check_player_privs(puncher, {protection_bypass=true})) then
local ctrl = puncher:get_player_control()
if ctrl.aux1 then
steampunk_blimp.paint2(self, colstr)
@ -471,7 +475,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
--airutils.make_sound(self,'hit')
if is_empty == true then
self.hp = self.hp - 10
minetest.sound_play("steampunk_blimp_collision", {
core.sound_play("steampunk_blimp_collision", {
object = self.object,
max_hear_distance = 5,
gain = 1.0,
@ -500,7 +504,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
self.owner = name
end
--minetest.chat_send_all('passengers: '.. dump(self._passengers))
--core.chat_send_all('passengers: '.. dump(self._passengers))
--=========================
-- form to pilot
--=========================
@ -536,7 +540,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
local pass_is_attached = steampunk_blimp.check_passenger_is_attached(self, name)
if pass_is_attached then
local can_bypass = minetest.check_player_privs(clicker, {protection_bypass=true})
local can_bypass = core.check_player_privs(clicker, {protection_bypass=true})
if clicker:get_player_control().aux1 == true then --lets see the inventory
local is_shared = false
if name == self.owner or can_bypass then is_shared = true end
@ -583,7 +587,7 @@ minetest.register_entity("steampunk_blimp:blimp", {
for i = steampunk_blimp.max_seats,1,-1
do
if self._passengers[i] ~= nil then
local old_player = minetest.get_player_by_name(self._passengers[i])
local old_player = core.get_player_by_name(self._passengers[i])
if not old_player then self._passengers[i] = nil end
end
end

View File

@ -19,14 +19,14 @@ function steampunk_blimp.testDamage(self, velocity, position)
if impact > 2 then
if self.colinfo then
collision = self.colinfo.collides
--minetest.chat_send_all(impact)
--core.chat_send_all(impact)
end
end
if collision then
--self.object:set_velocity({x=0,y=0,z=0})
local damage = impact -- / 2
minetest.sound_play("steampunk_blimp_collision", {
core.sound_play("steampunk_blimp_collision", {
--to_player = self.driver_name,
object = self.object,
max_hear_distance = 15,
@ -41,14 +41,14 @@ function steampunk_blimp.testDamage(self, velocity, position)
if self.driver_name then
local player_name = self.driver_name
local player = minetest.get_player_by_name(player_name)
local player = core.get_player_by_name(player_name)
if player then
if player:get_hp() > 0 then
player:set_hp(player:get_hp()-(damage/2))
end
end
if self._passenger ~= nil then
local passenger = minetest.get_player_by_name(self._passenger)
local passenger = core.get_player_by_name(self._passenger)
if passenger then
if passenger:get_hp() > 0 then
passenger:set_hp(passenger:get_hp()-(damage/2))
@ -64,7 +64,7 @@ local function do_attach(self, player, slot)
if slot == 0 then return end
if self._passengers[slot] == nil then
local name = player:get_player_name()
--minetest.chat_send_all(self.driver_name)
--core.chat_send_all(self.driver_name)
self._passengers[slot] = name
player:set_attach(self._passengers_base[slot], "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
@ -96,12 +96,12 @@ end
function steampunk_blimp.rescueConnectionFailedPassengers(self)
self._disconnection_check_time = self._disconnection_check_time + self.dtime
if self._disconnection_check_time > 1 then
--minetest.chat_send_all(dump(self._passengers))
--core.chat_send_all(dump(self._passengers))
self._disconnection_check_time = 0
for i = steampunk_blimp.max_seats,1,-1
do
if self._passengers[i] then
local player = minetest.get_player_by_name(self._passengers[i])
local player = core.get_player_by_name(self._passengers[i])
if player then --we have a player!
local is_attached = nil
if airutils.is_mcl then
@ -113,7 +113,7 @@ function steampunk_blimp.rescueConnectionFailedPassengers(self)
end
if is_attached == nil then --but isn't attached?
--minetest.chat_send_all("okay")
--core.chat_send_all("okay")
if player:get_hp() > 0 then
self._passengers[i] = nil --clear the slot first
do_attach(self, player, i) --attach
@ -132,7 +132,7 @@ function steampunk_blimp.attach_pax(self, player, slot)
--verify if is locked to non-owners
if self._passengers_locked == true then
local name = player:get_player_name()
local can_bypass = minetest.check_player_privs(player, {protection_bypass=true})
local can_bypass = core.check_player_privs(player, {protection_bypass=true})
local is_shared = false
if name == self.owner or can_bypass then is_shared = true end
for k, v in pairs(self._shared_owners) do
@ -142,7 +142,7 @@ function steampunk_blimp.attach_pax(self, player, slot)
end
end
if is_shared == false then
minetest.chat_send_player(name,core.colorize('#ff0000', " >>> This blimp is currently locked for non-owners"))
core.chat_send_player(name,core.colorize('#ff0000', " >>> This blimp is currently locked for non-owners"))
return
end
end
@ -152,7 +152,7 @@ function steampunk_blimp.attach_pax(self, player, slot)
do_attach(self, player, slot)
return
end
--minetest.chat_send_all(dump(self._passengers))
--core.chat_send_all(dump(self._passengers))
--now yes, lets attach the player
--randomize the seat
@ -163,13 +163,13 @@ function steampunk_blimp.attach_pax(self, player, slot)
t[a],t[b] = t[b],t[a]
end
--minetest.chat_send_all(dump(t))
--core.chat_send_all(dump(t))
for k,v in ipairs(t) do
local i = t[k] or 0
if self._passengers[i] == nil then
do_attach(self, player, i)
--minetest.chat_send_all(i)
--core.chat_send_all(i)
break
end
end
@ -210,7 +210,7 @@ function steampunk_blimp.dettach_pax(self, player, side)
end
-- move player down
minetest.after(0.1, function(pos)
core.after(0.1, function(pos)
local rotation = self.object:get_rotation()
local direction = rotation.y
@ -302,7 +302,7 @@ end
-- destroy the boat
function steampunk_blimp.destroy(self, overload)
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
core.sound_stop(self.sound_handle)
self.sound_handle = nil
end
@ -322,22 +322,22 @@ function steampunk_blimp.destroy(self, overload)
local lua_ent = self.object:get_luaentity()
local staticdata = lua_ent:get_staticdata(self)
local player = minetest.get_player_by_name(self.owner)
local player = core.get_player_by_name(self.owner)
self.object:remove()
if remove_it == false then
pos.y=pos.y+2
--[[for i=1,7 do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:steel_ingot')
core.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:steel_ingot')
end
for i=1,7 do
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:mese_crystal')
core.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:mese_crystal')
end]]--
--minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'steampunk_blimp:boat')
--minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:diamond')
--core.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'steampunk_blimp:boat')
--core.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:diamond')
local stack = ItemStack(self.item)
local stack_meta = stack:get_meta()
@ -349,11 +349,11 @@ function steampunk_blimp.destroy(self, overload)
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
else
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
core.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
end
end
else
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
core.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5}, stack)
end
end
end
@ -398,7 +398,7 @@ function steampunk_blimp.clamp(value, min, max)
local retVal = value
if value < min then retVal = min end
if value > max then retVal = max end
--minetest.chat_send_all(value .. " - " ..retVal)
--core.chat_send_all(value .. " - " ..retVal)
return retVal
end
@ -407,24 +407,24 @@ function steampunk_blimp.reclamp(value, min, max)
local mid = (max-min)/2
if value > min and value <= (min+mid) then retVal = min end
if value < max and value > (max-mid) then retVal = max end
--minetest.chat_send_all(value .. " - return: " ..retVal .. " - mid: " .. mid)
--core.chat_send_all(value .. " - return: " ..retVal .. " - mid: " .. mid)
return retVal
end
function steampunk_blimp.engineSoundPlay(self)
--sound
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
if self.sound_handle_pistons then minetest.sound_stop(self.sound_handle_pistons) end
if self.sound_handle then core.sound_stop(self.sound_handle) end
if self.sound_handle_pistons then core.sound_stop(self.sound_handle_pistons) end
if self.object then
local furnace_sound = "default_furnace_active"
if steampunk_blimp.furnace_sound then
self.sound_handle = minetest.sound_play({name = steampunk_blimp.furnace_sound.name},
self.sound_handle = core.sound_play({name = steampunk_blimp.furnace_sound.name},
{object = self.object, gain = steampunk_blimp.furnace_sound.gain,
max_hear_distance = 5,
loop = true,})
end
self.sound_handle_pistons = minetest.sound_play({name = steampunk_blimp.piston_sound.name},--"default_item_smoke"},
self.sound_handle_pistons = core.sound_play({name = steampunk_blimp.piston_sound.name},--"default_item_smoke"},
{object = self.object, gain = steampunk_blimp.piston_sound.gain,
pitch = steampunk_blimp.piston_sound.pitch+((math.abs(self._power_lever)/100)/2),
max_hear_distance = 32,
@ -434,7 +434,7 @@ end
function steampunk_blimp.engine_set_sound_and_animation(self)
if self._last_applied_power ~= self._power_lever then
--minetest.chat_send_all('test2')
--core.chat_send_all('test2')
self._last_applied_power = self._power_lever
self.object:set_animation_frame_speed(steampunk_blimp.iddle_rotation + (self._power_lever))
if self._last_sound_update == nil then self._last_sound_update = self._power_lever end
@ -445,7 +445,7 @@ function steampunk_blimp.engine_set_sound_and_animation(self)
end
if self._engine_running == false then
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
core.sound_stop(self.sound_handle)
self.sound_handle = nil
--self.object:set_animation_frame_speed(0)
end
@ -458,19 +458,19 @@ function steampunk_blimp.start_furnace(self)
self._engine_running = false
-- sound and animation
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
core.sound_stop(self.sound_handle)
self.sound_handle = nil
end
elseif self._engine_running == false and self._energy > 0 then
self._engine_running = true
-- sound
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
if self.sound_handle then core.sound_stop(self.sound_handle) end
if self.object then
local furnace_sound = "default_furnace_active"
if airutils.is_mcl then furnace_sound = "fire_fire" end
if steampunk_blimp.furnace_sound then
self.sound_handle = minetest.sound_play({name = steampunk_blimp.furnace_sound.name},
self.sound_handle = core.sound_play({name = steampunk_blimp.furnace_sound.name},
{object = self.object, gain = steampunk_blimp.furnace_sound.gain,
max_hear_distance = 5,
loop = true,})
@ -488,7 +488,7 @@ function steampunk_blimp.copy_vector(original_vector)
end
function steampunk_blimp.play_rope_sound(self)
minetest.sound_play({name = "steampunk_blimp_rope"},
core.sound_play({name = "steampunk_blimp_rope"},
{object = self.object, gain = 1,
max_hear_distance = 5,
ephemeral = true,})