Improve throwing and improve formspecs
|
@ -450,8 +450,19 @@ local function item_throw_step(entity, dtime)
|
|||
return
|
||||
end
|
||||
local hit_object = nil
|
||||
local node = minetest.get_node({x=pos.x, y=pos.y - 1, z=pos.z})
|
||||
local objs = minetest.get_objects_inside_radius(pos, 1)
|
||||
local dir = vector.normalize(entity.object:get_velocity())
|
||||
local pos2 = vector.add(pos, vector.multiply(dir, 3))
|
||||
local _, node_pos = minetest.line_of_sight(pos, pos2)
|
||||
if node_pos then
|
||||
local def = minetest.get_node(node_pos)
|
||||
if def then
|
||||
pos = vector.subtract(node_pos, vector.multiply(dir, 1.5))
|
||||
entity.object:move_to(pos)
|
||||
else
|
||||
node_pos = nil
|
||||
end
|
||||
end
|
||||
local objs = minetest.get_objects_inside_radius(pos, 1.5)
|
||||
for _, obj in pairs(objs) do
|
||||
if obj:is_player() then
|
||||
local name = obj:get_player_name()
|
||||
|
@ -463,7 +474,7 @@ local function item_throw_step(entity, dtime)
|
|||
hit_object = obj
|
||||
end
|
||||
end
|
||||
if hit_object or (node.name ~= "air" and node.name ~= "ignore") then
|
||||
if hit_object or node_pos then
|
||||
local player = core.get_player_by_name(entity.thrower)
|
||||
entity.on_impact(player, pos, entity.throw_direction, hit_object)
|
||||
entity.object:remove()
|
||||
|
|
|
@ -18,7 +18,7 @@ local time_to_live = tonumber(core.settings:get("item_entity_ttl")) or 900
|
|||
local gravity = tonumber(core.settings:get("movement_gravity")) or 9.81
|
||||
|
||||
core.register_entity(":__builtin:throwing_item", {
|
||||
physical = true,
|
||||
physical = false,
|
||||
visual = "wielditem",
|
||||
collisionbox = {0,0,0, 0,0,0},
|
||||
textures = {""},
|
||||
|
|
|
@ -69,7 +69,7 @@ end
|
|||
|
||||
local filters = {
|
||||
["all"] = function(name, def, groups)
|
||||
return true --[[and not def.groups.stairs]]
|
||||
return true and not def.groups.stairs
|
||||
end,
|
||||
["blocks"] = function(name, def, groups)
|
||||
return minetest.registered_nodes[name] and
|
||||
|
@ -120,28 +120,18 @@ filters["misc"] = function(name, def, groups)
|
|||
return true
|
||||
end
|
||||
|
||||
local function get_item_list(category)
|
||||
local filter = filters[category] or function() return true end
|
||||
local item_list = {}
|
||||
local function init_creative_cache(tab_name, category)
|
||||
inventory_cache[tab_name] = {}
|
||||
local i_cache = inventory_cache[tab_name]
|
||||
local filter = filters[category] or function() return end
|
||||
for name, def in pairs(minetest.registered_items) do
|
||||
local groups = def.groups or {}
|
||||
if def.description and def.description ~= "" and
|
||||
groups.not_in_creative_inventory ~= 1 and
|
||||
filter(name, def, groups) then
|
||||
table.insert(item_list, name)
|
||||
i_cache[name] = def.description
|
||||
end
|
||||
end
|
||||
return item_list
|
||||
end
|
||||
|
||||
local function init_creative_cache(tab_name, category)
|
||||
inventory_cache[tab_name] = {}
|
||||
local i_cache = inventory_cache[tab_name]
|
||||
local item_list = get_item_list(category)
|
||||
for _, name in pairs(item_list) do
|
||||
local def = minetest.registered_items[name]
|
||||
i_cache[name] = def.description
|
||||
end
|
||||
table.sort(i_cache)
|
||||
end
|
||||
|
||||
|
@ -209,7 +199,7 @@ local function get_creative_formspec(player_name, start_i, pagenum, page, pagema
|
|||
page = page or "all"
|
||||
pagenum = math.floor(pagenum) or 1
|
||||
pagemax = (pagemax and pagemax ~= 0) and pagemax or 1
|
||||
local slider_height = 4 / pagemax - 0.04
|
||||
local slider_height = 4.46 / pagemax
|
||||
local slider_pos = 4 / pagemax * (pagenum - 1) + 2.14
|
||||
local main_list = get_button_formspec(player_name, start_i)
|
||||
if page == "inv" then
|
||||
|
@ -223,7 +213,7 @@ local function get_creative_formspec(player_name, start_i, pagenum, page, pagema
|
|||
"list[detached:"..player_name.."_armor;armor;0.99,2.69;1,1;3]"
|
||||
end
|
||||
end
|
||||
local formspec = "image_button_exit[10.4,-0.1;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
local formspec = "image_button_exit[10.4,-0.1;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"background[-0.2,-0.26;11.55,8.49;inventory_creative.png]"..
|
||||
sfinv.gui_bg..
|
||||
sfinv.listcolors..
|
||||
|
@ -240,11 +230,13 @@ local function get_creative_formspec(player_name, start_i, pagenum, page, pagema
|
|||
"image_button[9.2,-0.15;1,1;"..bg["brew"]..";brew;;;false]".. --brewing
|
||||
"image_button[10.25,1;1,1;"..bg["all"]..";default;;;false]".. --all items
|
||||
"image_button[10.25,7.11;1,1;"..bg["inv"]..";inv;;;false]".. --inventory
|
||||
"image_button_exit[10.3,2.5;1,1;creative_home_set.png;sethome_set;;true;true;]"..
|
||||
"image_button_exit[10.3,3.5;1,1;creative_home_go.png;sethome_go;;true;true;]"..
|
||||
"image_button_exit[10.3,2.5;1,1;creative_home_set.png;sethome_set;;true;false]"..
|
||||
"tooltip[sethome_set;Set Home;#000;#FFF]"..
|
||||
"image_button_exit[10.3,3.5;1,1;creative_home_go.png;sethome_go;;true;false]"..
|
||||
"tooltip[sethome_go;Go Home;#000;#FFF]"..
|
||||
"image[0,0.95;5,0.75;fnt_"..page..".png]"..
|
||||
"image_button[9.145,1.65;0.81,0.6;creative_up.png;creative_prev;]"..
|
||||
"image_button[9.145,6.08;0.81,0.6;creative_down.png;creative_next;]"..
|
||||
"image_button[9.145,1.65;0.81,0.6;blank.png;creative_prev;;;false]" ..
|
||||
"image_button[9.145,6.08;0.81,0.6;blank.png;creative_next;;;false]" ..
|
||||
"list[current_player;main;0.02,6.93;9,1;]"..main_list..
|
||||
"list[detached:creative_trash;main;9.03,6.94;1,1;]"..
|
||||
"image["..ofs_tab[page]..";1.45,1.45;creative_active.png"..rot[page].."]"..
|
||||
|
|
Before Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.9 KiB |
|
@ -45,7 +45,7 @@ minetest.register_node("default:chest", {
|
|||
"background[-0.2,-0.35;9.42,12.46;formspec_chest_large.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[nodemeta:"..p.x..","..p.y..","..p.z..";main;0.01,0.4;9,3;]"..
|
||||
"list[current_name;main;0.01,3.39;9,3;]"..
|
||||
"list[current_player;main;0.01,7.4;9,3;9]"..
|
||||
|
@ -58,7 +58,7 @@ minetest.register_node("default:chest", {
|
|||
"background[-0.2,-0.35;9.42,12.46;formspec_chest_large.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0.01,3.39;9,3;]"..
|
||||
"list[current_name;main;0.01,0.4;9,3;]"..
|
||||
"list[current_player;main;0.01,7.4;9,3;9]"..
|
||||
|
@ -72,7 +72,7 @@ minetest.register_node("default:chest", {
|
|||
"background[-0.2,-0.35;9.42,12.46;formspec_chest_large.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[nodemeta:"..p.x..","..p.y..","..p.z..";main;0.01,3.39;9,3;]"..
|
||||
"list[current_name;main;0.01,0.4;9,3;]"..
|
||||
"list[current_player;main;0.01,7.4;9,3;9]"..
|
||||
|
@ -85,7 +85,7 @@ minetest.register_node("default:chest", {
|
|||
"background[-0.2,-0.35;9.42,12.46;formspec_chest_large.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.28;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0.01,0.4;9,3;]"..
|
||||
"list[current_name;main;0.01,3.39;9,3;]"..
|
||||
"list[current_player;main;0.01,7.4;9,3;9]"..
|
||||
|
@ -97,7 +97,7 @@ minetest.register_node("default:chest", {
|
|||
"background[-0.2,-0.26;9.41,9.49;formspec_chest.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.19;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.19;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[current_name;main;0,0.5;9,3;]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]" ..
|
||||
"list[current_player;main;0,7.74;9,1;]")
|
||||
|
@ -163,7 +163,7 @@ minetest.register_node("default:chest_left", {
|
|||
"background[-0.2,-0.26;9.41,9.49;formspec_chest.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.19;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.19;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[current_name;main;0,0.5;9,3;]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]" ..
|
||||
"list[current_player;main;0,7.74;9,1;]")
|
||||
|
@ -221,7 +221,7 @@ minetest.register_node("default:chest_right", {
|
|||
"background[-0.2,-0.26;9.41,9.49;formspec_chest.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.35,-0.19;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.35,-0.19;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[current_name;main;0,0.5;9,3;]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]" ..
|
||||
"list[current_player;main;0,7.74;9,1;]")
|
||||
|
|
|
@ -536,7 +536,15 @@ end
|
|||
|
||||
-- Shoot snowball
|
||||
|
||||
local function snowball_impact(thrower, pos)
|
||||
local function snowball_impact(thrower, pos, dir, hit_object)
|
||||
if hit_object then
|
||||
local punch_damage = {
|
||||
full_punch_interval = 1.0,
|
||||
damage_groups = {fleshy=1},
|
||||
}
|
||||
hit_object:punch(thrower, 1.0, punch_damage, dir)
|
||||
end
|
||||
local node_pos = nil
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "air" then
|
||||
local pos_under = vector.subtract(pos, {x=0, y=1, z=0})
|
||||
|
@ -544,50 +552,45 @@ local function snowball_impact(thrower, pos)
|
|||
if node.name then
|
||||
local def = minetest.registered_items[node.name] or {}
|
||||
if def.buildable_to == true then
|
||||
minetest.add_node(pos_under, {name="default:snow"})
|
||||
node_pos = pos_under
|
||||
elseif def.walkable == true then
|
||||
minetest.add_node(pos, {name="default:snow"})
|
||||
node_pos = pos
|
||||
end
|
||||
elseif node.name then
|
||||
local def = minetest.registered_items[node.name]
|
||||
if def and def.buildable_to == true then
|
||||
minetest.add_node(pos, {name="default:snow"})
|
||||
node_pos = pos
|
||||
end
|
||||
end
|
||||
if node_pos then
|
||||
minetest.add_node(pos, {name="default:snow"})
|
||||
minetest.spawn_falling_node(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function default.snow_shoot_snowball(itemstack, player, pointed_thing)
|
||||
if not (creative and creative.is_enabled_for and
|
||||
creative.is_enabled_for(player)) or
|
||||
not minetest.is_singleplayer() then
|
||||
itemstack:take_item()
|
||||
end
|
||||
minetest.item_throw("default:snowball_entity", player, 19, -3,
|
||||
local obj = minetest.item_throw("default:snow", player, 19, -3,
|
||||
snowball_impact)
|
||||
local playerpos = player:get_pos()
|
||||
if not minetest.is_valid_pos(playerpos) then
|
||||
return
|
||||
if obj then
|
||||
obj:set_properties({
|
||||
visual = "sprite",
|
||||
visual_size = {x=1, y=1},
|
||||
textures = {"default_snowball.png"},
|
||||
})
|
||||
if not (creative and creative.is_enabled_for and
|
||||
creative.is_enabled_for(player)) or
|
||||
not minetest.is_singleplayer() then
|
||||
itemstack:take_item()
|
||||
end
|
||||
local playerpos = player:get_pos()
|
||||
if minetest.is_valid_pos(playerpos) then
|
||||
minetest.sound_play("throwing_sound", {
|
||||
pos = playerpos,
|
||||
gain = 0.7,
|
||||
max_hear_distance = 10,
|
||||
})
|
||||
end
|
||||
end
|
||||
minetest.sound_play("throwing_sound", {
|
||||
pos = playerpos,
|
||||
gain = 1.0,
|
||||
max_hear_distance = 5,
|
||||
})
|
||||
return itemstack
|
||||
end
|
||||
|
||||
minetest.register_entity("default:snowball_entity", {
|
||||
physical = true,
|
||||
textures = {"default_snowball.png",},
|
||||
visual = "sprite",
|
||||
collisionbox = {0,0,0, 0,0,0},
|
||||
on_activate = function(self, staticdata)
|
||||
if staticdata == "expired" then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
get_staticdata = function()
|
||||
return "expired"
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -9,7 +9,7 @@ function default.get_furnace_active_formspec(fuel_percent, item_percent)
|
|||
"background[-0.2,-0.26;9.41,9.49;formspec_furnace.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.4,-0.1;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.4,-0.1;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
"list[current_name;src;3,0.5;1,1;]"..
|
||||
|
@ -26,7 +26,7 @@ function default.get_furnace_inactive_formspec()
|
|||
"background[-0.2,-0.26;9.41,9.49;formspec_furnace.png]"..
|
||||
default.gui_bg..
|
||||
default.listcolors..
|
||||
"image_button_exit[8.4,-0.1;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.4,-0.1;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
"list[current_name;src;3,0.5;1,1;]"..
|
||||
|
|
After Width: | Height: | Size: 245 B |
Before Width: | Height: | Size: 350 B After Width: | Height: | Size: 350 B |
Before Width: | Height: | Size: 339 B After Width: | Height: | Size: 339 B |
|
@ -13,14 +13,18 @@ local function set_inventory(player)
|
|||
default.listcolors..
|
||||
"background[-0.2,-0.26;9.41,9.49;formspec_inventory.png]"..
|
||||
"background[-0.2,-0.26;9.41,9.49;formspec_inventory_inventory.png]"..
|
||||
"image_button_exit[8.4,-0.1;0.75,0.75;close.png;exit;;true;true;]"..
|
||||
"image_button_exit[8.4,-0.1;0.75,0.75;close.png;exit;;true;false;close_pressed.png]"..
|
||||
"list[current_player;main;0.01,4.51;9,3;9]"..
|
||||
"list[current_player;main;0.01,7.74;9,1;]"..
|
||||
"list[current_player;craft;4,1;2,1;1]"..
|
||||
"list[current_player;craft;4,2;2,1;4]"..
|
||||
"list[current_player;craftpreview;7.05,1.53;1,1;]"..
|
||||
"list[detached:split;main;8,3.14;1,1;]"..
|
||||
"image[1.5,0;2,4;default_player2d.png]"
|
||||
"image[1.5,0;2,4;default_player2d.png]"..
|
||||
"image_button_exit[9.21,2.5;1,1;creative_home_set.png;sethome_set;;true;false]"..
|
||||
"tooltip[sethome_set;Set Home;#000;#FFF]"..
|
||||
"image_button_exit[9.21,3.5;1,1;creative_home_go.png;sethome_go;;true;false]"..
|
||||
"tooltip[sethome_go;Go Home;#000;#FFF]"
|
||||
-- Armor
|
||||
if minetest.get_modpath("3d_armor") then
|
||||
local player_name = player:get_player_name()
|
||||
|
|
|
@ -153,10 +153,10 @@ local mobs_shoot_egg = function (item, player, pointed_thing)
|
|||
|
||||
local playerpos = player:get_pos()
|
||||
|
||||
minetest.sound_play("default_place_node_hard", {
|
||||
minetest.sound_play("throwing_sound", {
|
||||
pos = playerpos,
|
||||
gain = 1.0,
|
||||
max_hear_distance = 5,
|
||||
gain = 0.7,
|
||||
max_hear_distance = 10,
|
||||
})
|
||||
|
||||
local obj = minetest.add_entity({
|
||||
|
|
|
@ -3766,9 +3766,20 @@ end
|
|||
|
||||
local function throw_spawn_egg(itemstack, user, pointed_thing)
|
||||
local mob = itemstack:get_name():gsub("_set$", "")
|
||||
local egg_impact = function(thrower, pos)
|
||||
local egg_impact = function(thrower, pos, dir, hit_object)
|
||||
if hit_object then
|
||||
local punch_damage = {
|
||||
full_punch_interval = 1.0,
|
||||
damage_groups = {fleshy=1},
|
||||
}
|
||||
hit_object:punch(thrower, 1.0, punch_damage, dir)
|
||||
end
|
||||
spawn_mob(pos, mob, itemstack:get_metadata(), user)
|
||||
end
|
||||
local playerpos = user:get_pos()
|
||||
if not minetest.is_valid_pos(playerpos) then
|
||||
return
|
||||
end
|
||||
local obj = minetest.item_throw(mob.."_set", user, 19, -3, egg_impact)
|
||||
if obj then
|
||||
local def = minetest.registered_items[mob.."_set"]
|
||||
|
@ -3779,6 +3790,11 @@ local function throw_spawn_egg(itemstack, user, pointed_thing)
|
|||
textures = {def.inventory_image},
|
||||
})
|
||||
end
|
||||
minetest.sound_play("throwing_sound", {
|
||||
pos = playerpos,
|
||||
gain = 0.7,
|
||||
max_hear_distance = 10,
|
||||
})
|
||||
if not mobs.is_creative(user) or
|
||||
not minetest.is_singleplayer() then
|
||||
itemstack:take_item()
|
||||
|
|
|
@ -30,7 +30,11 @@ local throwing_shoot_arrow = function(itemstack, player)
|
|||
if obj then
|
||||
local ent = obj:get_luaentity()
|
||||
if ent then
|
||||
minetest.sound_play("throwing_sound", {pos=playerpos})
|
||||
minetest.sound_play("throwing_sound", {
|
||||
pos = playerpos,
|
||||
gain = 0.7,
|
||||
max_hear_distance = 10,
|
||||
})
|
||||
obj:set_yaw(player:get_look_yaw() + math.pi)
|
||||
return true
|
||||
else
|
||||
|
|