Update 3d_armor, replace mcl_inventory with craftingpack
|
@ -1,15 +1,24 @@
|
|||
[mod] Visible Player Armor [3d_armor]
|
||||
=====================================
|
||||
|
||||
depends: default, inventory_plus, unified_skins
|
||||
Depends: default
|
||||
|
||||
Adds craftable armor that is visible to other players. Each armor item worn contibutes to
|
||||
Recommends: inventory_plus or unified_inventory (use only one)
|
||||
|
||||
Adds craftable armor that is visible to other players. Each armor item worn contributes to
|
||||
a player's armor group level making them less vulnerable to weapons.
|
||||
|
||||
Armor takes damage when a player is hurt but also offers a percentage chance of healing.
|
||||
Overall level is boosted by 10% when wearing a full matching set.
|
||||
|
||||
default settings: [minetest.conf]
|
||||
Fire protection added by TenPlus1 when using crystal armor if Ethereal mod active, level 1
|
||||
protects against torches, level 2 for crystal spike, level 3 for fire, level 5 for lava.
|
||||
|
||||
# Set number of seconds between armor updates.
|
||||
3d_armor_update_time = 1
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
Armor can be configured by adding a file called armor.conf in 3d_armor mod and/or world directory.
|
||||
see armor.conf.example for all available options.
|
||||
|
||||
Note: worldpath config settings override any settings made in the mod's directory.
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
-- Armor Configuration
|
||||
ARMOR_MATERIALS = {
|
||||
leather = "group:wood",
|
||||
iron = "default:steel_ingot",
|
||||
chain = nil,
|
||||
gold = "default:gold_ingot",
|
||||
diamond = "default:diamond",
|
||||
}
|
||||
|
||||
ARMOR_FIRE_PROTECT = false
|
||||
|
||||
ARMOR_FIRE_NODES = {
|
||||
{"default:lava_source", 5, 4},
|
||||
{"default:lava_flowing", 5, 4},
|
||||
{"fire:basic_flame", 3, 4},
|
||||
{"fire:permanent_flame", 3, 4},
|
||||
}
|
||||
|
||||
ARMOR_DROP = true
|
||||
ARMOR_DESTROY = false
|
||||
ARMOR_HEAL_MULTIPLIER = 0
|
||||
ARMOR_RADIATION_MULTIPLIER = 0
|
|
@ -0,0 +1,61 @@
|
|||
-- Armor Configuration (defaults)
|
||||
|
||||
-- You can remove any unwanted armor materials from this table.
|
||||
-- Note that existing armor that is removed will show up as an unknown item.
|
||||
ARMOR_MATERIALS = {
|
||||
wood = "group:wood",
|
||||
cactus = "default:cactus",
|
||||
steel = "default:steel_ingot",
|
||||
bronze = "default:bronze_ingot",
|
||||
diamond = "default:diamond",
|
||||
gold = "default:gold_ingot",
|
||||
mithril = "moreores:mithril_ingot",
|
||||
crystal = "ethereal:crystal_ingot",
|
||||
}
|
||||
|
||||
-- Enable fire protection (defaults true if using ethereal mod)
|
||||
ARMOR_FIRE_PROTECT = false
|
||||
|
||||
-- Fire protection nodes, (name, protection level, damage)
|
||||
ARMOR_FIRE_NODES = {
|
||||
{"default:lava_source", 5, 4},
|
||||
{"default:lava_flowing", 5, 4},
|
||||
{"fire:basic_flame", 3, 4},
|
||||
{"fire:permanent_flame", 3, 4},
|
||||
{"ethereal:crystal_spike", 2, 1},
|
||||
{"ethereal:fire_flower", 2, 1},
|
||||
{"default:torch", 1, 1},
|
||||
}
|
||||
|
||||
-- Increase this if you get initialization glitches when a player first joins.
|
||||
ARMOR_INIT_DELAY = 1
|
||||
|
||||
-- Number of initialization attempts.
|
||||
-- Use in conjunction with ARMOR_INIT_DELAY if initialization problems persist.
|
||||
ARMOR_INIT_TIMES = 1
|
||||
|
||||
-- Increase this if armor is not getting into bones due to server lag.
|
||||
ARMOR_BONES_DELAY = 1
|
||||
|
||||
-- How often player armor/wield items are updated.
|
||||
ARMOR_UPDATE_TIME = 1
|
||||
|
||||
-- Drop armor when a player dies.
|
||||
-- Uses bones mod if present, otherwise items are dropped around the player.
|
||||
ARMOR_DROP = true
|
||||
|
||||
-- Pulverise armor when a player dies, overrides ARMOR_DROP.
|
||||
ARMOR_DESTROY = false
|
||||
|
||||
-- You can use this to increase or decrease overall armor effectiveness,
|
||||
-- eg: ARMOR_LEVEL_MULTIPLIER = 0.5 will reduce armor level by half.
|
||||
ARMOR_LEVEL_MULTIPLIER = 1
|
||||
|
||||
-- You can use this to increase or decrease overall armor healing,
|
||||
-- eg: ARMOR_HEAL_MULTIPLIER = 0 will disable healing altogether.
|
||||
ARMOR_HEAL_MULTIPLIER = 1
|
||||
|
||||
-- You can use this to increase or decrease overall armor radiation protection,
|
||||
-- eg: ARMOR_RADIATION_MULTIPLIER = 0 will completely disable radiation protection.
|
||||
-- Note: patched technic mod is required
|
||||
ARMOR_RADIATION_MULTIPLIER = 1
|
|
@ -1,90 +1,552 @@
|
|||
local time = 0
|
||||
local update_time = tonumber(minetest.setting_get("3d_armor_update_time"))
|
||||
if not update_time then
|
||||
update_time = 1
|
||||
minetest.setting_set("3d_armor_update_time", tostring(update_time))
|
||||
ARMOR_INIT_DELAY = 1
|
||||
ARMOR_INIT_TIMES = 1
|
||||
ARMOR_BONES_DELAY = 1
|
||||
ARMOR_UPDATE_TIME = 1
|
||||
ARMOR_DROP = minetest.get_modpath("bones") ~= nil
|
||||
ARMOR_DESTROY = false
|
||||
ARMOR_LEVEL_MULTIPLIER = 1
|
||||
ARMOR_HEAL_MULTIPLIER = 1
|
||||
ARMOR_RADIATION_MULTIPLIER = 1
|
||||
ARMOR_MATERIALS = {
|
||||
wood = "group:wood",
|
||||
cactus = "default:cactus",
|
||||
steel = "default:steel_ingot",
|
||||
bronze = "default:bronze_ingot",
|
||||
diamond = "default:diamond",
|
||||
gold = "default:gold_ingot",
|
||||
mithril = "moreores:mithril_ingot",
|
||||
crystal = "ethereal:crystal_ingot",
|
||||
}
|
||||
ARMOR_FIRE_PROTECT = minetest.get_modpath("ethereal") ~= nil
|
||||
ARMOR_FIRE_NODES = {
|
||||
{"default:lava_source", 5, 8},
|
||||
{"default:lava_flowing", 5, 8},
|
||||
{"fire:basic_flame", 3, 4},
|
||||
{"fire:permanent_flame", 3, 4},
|
||||
{"ethereal:crystal_spike", 2, 1},
|
||||
{"ethereal:fire_flower", 2, 1},
|
||||
{"default:torch", 1, 1},
|
||||
}
|
||||
|
||||
local skin_mod = nil
|
||||
local inv_mod = nil
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
local worldpath = minetest.get_worldpath()
|
||||
local input = io.open(modpath.."/armor.conf", "r")
|
||||
if input then
|
||||
dofile(modpath.."/armor.conf")
|
||||
input:close()
|
||||
input = nil
|
||||
end
|
||||
input = io.open(worldpath.."/armor.conf", "r")
|
||||
if input then
|
||||
dofile(worldpath.."/armor.conf")
|
||||
input:close()
|
||||
input = nil
|
||||
end
|
||||
if not minetest.get_modpath("moreores") then
|
||||
ARMOR_MATERIALS.mithril = nil
|
||||
end
|
||||
if not minetest.get_modpath("ethereal") then
|
||||
ARMOR_MATERIALS.crystal = nil
|
||||
end
|
||||
|
||||
armor = {
|
||||
player_hp = {},
|
||||
timer = 0,
|
||||
elements = {"head", "torso", "legs", "feet"},
|
||||
--[[formspec = "size[8,8.5]button[0,0;2,0.5;main;Back]"
|
||||
physics = {"jump","speed","gravity"},
|
||||
formspec = "size[8,8.5]image[2,0.75;2,4;armor_preview]"
|
||||
.."list[current_player;main;0,4.5;8,4;]"
|
||||
.."list[detached:player_name_armor;armor_head;3,0;1,1;]"
|
||||
.."list[detached:player_name_armor;armor_torso;3,1;1,1;]"
|
||||
.."list[detached:player_name_armor;armor_legs;3,2;1,1;]"
|
||||
.."list[detached:player_name_armor;armor_feet;3,3;1,1;]",]]
|
||||
.."list[current_player;craft;4,1;3,3;]"
|
||||
.."list[current_player;craftpreview;7,2;1,1;]"
|
||||
.."listring[current_player;main]"
|
||||
.."listring[current_player;craft]",
|
||||
textures = {},
|
||||
default_skin = "character",
|
||||
version = "0.4.6",
|
||||
}
|
||||
|
||||
if minetest.get_modpath("inventory_plus") then
|
||||
inv_mod = "inventory_plus"
|
||||
armor.formspec = "size[8,8.5]button[0,0;2,0.5;main;Back]"
|
||||
.."image[2.5,0.75;2,4;armor_preview]"
|
||||
.."label[5,1;Level: armor_level]"
|
||||
.."label[5,1.5;Heal: armor_heal]"
|
||||
.."label[5,2;Fire: armor_fire]"
|
||||
.."label[5,2.5;Radiation: armor_radiation]"
|
||||
.."list[current_player;main;0,4.5;8,4;]"
|
||||
if minetest.get_modpath("crafting") then
|
||||
inventory_plus.get_formspec = function(player, page)
|
||||
end
|
||||
end
|
||||
elseif minetest.get_modpath("unified_inventory") then
|
||||
inv_mod = "unified_inventory"
|
||||
unified_inventory.register_button("armor", {
|
||||
type = "image",
|
||||
image = "inventory_plus_armor.png",
|
||||
})
|
||||
unified_inventory.register_page("armor", {
|
||||
get_formspec = function(player, perplayer_formspec)
|
||||
local fy = perplayer_formspec.formspec_y
|
||||
local name = player:get_player_name()
|
||||
local formspec = "background[0.06,"..fy..";7.92,7.52;3d_armor_ui_form.png]"
|
||||
.."label[0,0;Armor]"
|
||||
.."list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]"
|
||||
.."image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]"
|
||||
.."label[5.0,"..(fy + 0.0)..";Level: "..armor.def[name].level.."]"
|
||||
.."label[5.0,"..(fy + 0.5)..";Heal: "..armor.def[name].heal.."]"
|
||||
.."label[5.0,"..(fy + 1.0)..";Fire: "..armor.def[name].fire.."]"
|
||||
.."label[5.0,"..(fy + 1.5)..";Radiation: "..armor.def[name].radiation.."]"
|
||||
.."listring[current_player;main]"
|
||||
.."listring[detached:"..name.."_armor;armor]"
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
elseif minetest.get_modpath("inventory_enhanced") then
|
||||
inv_mod = "inventory_enhanced"
|
||||
end
|
||||
|
||||
if minetest.get_modpath("skins") then
|
||||
skin_mod = "skins"
|
||||
elseif minetest.get_modpath("simple_skins") then
|
||||
skin_mod = "simple_skins"
|
||||
elseif minetest.get_modpath("u_skins") then
|
||||
skin_mod = "u_skins"
|
||||
elseif minetest.get_modpath("wardrobe") then
|
||||
skin_mod = "wardrobe"
|
||||
end
|
||||
|
||||
armor.def = {
|
||||
state = 0,
|
||||
count = 0
|
||||
count = 0,
|
||||
}
|
||||
|
||||
armor.set_player_armor = function(self, player)
|
||||
armor.update_player_visuals = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_texture = uniskins.default_texture
|
||||
if self.textures[name] then
|
||||
default.player_set_textures(player, {
|
||||
self.textures[name].skin,
|
||||
self.textures[name].armor,
|
||||
self.textures[name].wielditem,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
armor.set_player_armor = function(self, player)
|
||||
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
|
||||
if not name then
|
||||
return
|
||||
end
|
||||
local armor_texture = "3d_armor_trans.png"
|
||||
local armor_level = 0
|
||||
local armor_heal = 0
|
||||
local armor_fire = 0
|
||||
local armor_water = 0
|
||||
local armor_radiation = 0
|
||||
local state = 0
|
||||
local items = 0
|
||||
local elements = {}
|
||||
local textures = {}
|
||||
local physics_o = {speed=1,gravity=1,jump=1}
|
||||
local material = {type=nil, count=1}
|
||||
local preview = armor:get_preview(name) or "character_preview.png"
|
||||
for _,v in ipairs(self.elements) do
|
||||
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||
local level = stack:get_definition().groups["armor_"..v]
|
||||
if level then
|
||||
elements[v] = false
|
||||
end
|
||||
for i=1, 6 do
|
||||
local stack = player_inv:get_stack("armor", i)
|
||||
local item = stack:get_name()
|
||||
table.insert(textures, item:gsub("%:", "_")..".png")
|
||||
if stack:get_count() == 1 then
|
||||
local def = stack:get_definition()
|
||||
for k, v in pairs(elements) do
|
||||
if v == false then
|
||||
local level = def.groups["armor_"..k]
|
||||
if level then
|
||||
local texture = def.texture or item:gsub("%:", "_")
|
||||
table.insert(textures, texture..".png")
|
||||
preview = preview.."^"..texture.."_preview.png"
|
||||
armor_level = armor_level + level
|
||||
state = state + stack:get_wear()
|
||||
items = items + 1
|
||||
armor_heal = armor_heal + (def.groups["armor_heal"] or 0)
|
||||
armor_fire = armor_fire + (def.groups["armor_fire"] or 0)
|
||||
armor_water = armor_water + (def.groups["armor_water"] or 0)
|
||||
armor_radiation = armor_radiation + (def.groups["armor_radiation"] or 0)
|
||||
for kk,vv in ipairs(self.physics) do
|
||||
local o_value = def.groups["physics_"..vv]
|
||||
if o_value then
|
||||
physics_o[vv] = physics_o[vv] + o_value
|
||||
end
|
||||
end
|
||||
if table.getn(textures) > 0 then
|
||||
local mat = string.match(item, "%:.+_(.+)$")
|
||||
if material.type then
|
||||
if material.type == mat then
|
||||
material.count = material.count + 1
|
||||
end
|
||||
else
|
||||
material.type = mat
|
||||
end
|
||||
elements[k] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if minetest.get_modpath("shields") then
|
||||
armor_level = armor_level * 0.9
|
||||
end
|
||||
if material.type and material.count == #self.elements then
|
||||
armor_level = armor_level * 1.1
|
||||
end
|
||||
armor_level = armor_level * ARMOR_LEVEL_MULTIPLIER
|
||||
armor_heal = armor_heal * ARMOR_HEAL_MULTIPLIER
|
||||
armor_radiation = armor_radiation * ARMOR_RADIATION_MULTIPLIER
|
||||
if #textures > 0 then
|
||||
armor_texture = table.concat(textures, "^")
|
||||
end
|
||||
local armor_groups = {fleshy=100}
|
||||
if armor_level > 0 then
|
||||
armor_groups.level = math.floor(armor_level / 20)
|
||||
armor_groups.fleshy = 100 - armor_level
|
||||
armor_groups.radiation = 100 - armor_radiation
|
||||
end
|
||||
player:set_armor_groups(armor_groups)
|
||||
uniskins.armor[name] = armor_texture
|
||||
uniskins:update_player_visuals(player)
|
||||
armor.def[name].state = state
|
||||
armor.def[name].count = items
|
||||
player:set_physics_override(physics_o)
|
||||
self.textures[name].armor = armor_texture
|
||||
self.textures[name].preview = preview
|
||||
self.def[name].state = state
|
||||
self.def[name].count = items
|
||||
self.def[name].level = armor_level
|
||||
self.def[name].heal = armor_heal
|
||||
self.def[name].jump = physics_o.jump
|
||||
self.def[name].speed = physics_o.speed
|
||||
self.def[name].gravity = physics_o.gravity
|
||||
self.def[name].fire = armor_fire
|
||||
self.def[name].water = armor_water
|
||||
self.def[name].radiation = armor_radiation
|
||||
self:update_player_visuals(player)
|
||||
end
|
||||
|
||||
armor.update_armor = function(self, player)
|
||||
-- Legacy support: Called when armor levels are changed
|
||||
-- Other mods can hook on to this function, see hud mod for example
|
||||
end
|
||||
|
||||
armor.get_player_skin = function(self, name)
|
||||
local skin = nil
|
||||
if skin_mod == "skins" or skin_mod == "simple_skins" then
|
||||
skin = skins.skins[name]
|
||||
elseif skin_mod == "u_skins" then
|
||||
skin = u_skins.u_skins[name]
|
||||
elseif skin_mod == "wardrobe" then
|
||||
skin = string.gsub(wardrobe.playerSkins[name], "%.png$","")
|
||||
end
|
||||
return skin or armor.default_skin
|
||||
end
|
||||
|
||||
armor.get_preview = function(self, name)
|
||||
if skin_mod == "skins" then
|
||||
return armor:get_player_skin(name).."_preview.png"
|
||||
end
|
||||
end
|
||||
|
||||
armor.get_armor_formspec = function(self, name)
|
||||
if not armor.textures[name] then
|
||||
minetest.log("error", "3d_armor: Player texture["..name.."] is nil [get_armor_formspec]")
|
||||
return ""
|
||||
end
|
||||
if not armor.def[name] then
|
||||
minetest.log("error", "3d_armor: Armor def["..name.."] is nil [get_armor_formspec]")
|
||||
return ""
|
||||
end
|
||||
local formspec = armor.formspec.."list[detached:"..name.."_armor;armor;0,1;2,3;]"
|
||||
formspec = formspec:gsub("armor_preview", armor.textures[name].preview)
|
||||
formspec = formspec:gsub("armor_level", armor.def[name].level)
|
||||
formspec = formspec:gsub("armor_heal", armor.def[name].heal)
|
||||
formspec = formspec:gsub("armor_fire", armor.def[name].fire)
|
||||
formspec = formspec:gsub("armor_radiation", armor.def[name].radiation)
|
||||
return formspec
|
||||
end
|
||||
|
||||
armor.update_inventory = function(self, player)
|
||||
local name = armor:get_valid_player(player, "[set_player_armor]")
|
||||
if not name or inv_mod == "inventory_enhanced" then
|
||||
return
|
||||
end
|
||||
if inv_mod == "unified_inventory" then
|
||||
if unified_inventory.current_page[name] == "armor" then
|
||||
unified_inventory.set_inventory_formspec(player, "armor")
|
||||
end
|
||||
else
|
||||
local formspec = armor:get_armor_formspec(name)
|
||||
if inv_mod == "inventory_plus" then
|
||||
formspec = formspec.."listring[current_player;main]"
|
||||
.."listring[detached:"..name.."_armor;armor]"
|
||||
local page = player:get_inventory_formspec()
|
||||
if page:find("detached:"..name.."_armor") then
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
end
|
||||
elseif not core.setting_getbool("creative_mode") then
|
||||
player:set_inventory_formspec(formspec)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
armor.get_valid_player = function(self, player, msg)
|
||||
msg = msg or ""
|
||||
if not player then
|
||||
minetest.log("error", "3d_armor: Player reference is nil "..msg)
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local hp = player:get_hp() or 0
|
||||
if hp == 0 or hp == self.player_hp[name] then
|
||||
if not name then
|
||||
minetest.log("error", "3d_armor: Player name is nil "..msg)
|
||||
return
|
||||
end
|
||||
if self.player_hp[name] > hp then
|
||||
local pos = player:getpos()
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
||||
if not armor_inv then
|
||||
if not pos then
|
||||
minetest.log("error", "3d_armor: Player position is nil "..msg)
|
||||
return
|
||||
elseif not player_inv then
|
||||
minetest.log("error", "3d_armor: Player inventory is nil "..msg)
|
||||
return
|
||||
elseif not armor_inv then
|
||||
minetest.log("error", "3d_armor: Detached armor inventory is nil "..msg)
|
||||
return
|
||||
end
|
||||
return name, player_inv, armor_inv, pos
|
||||
end
|
||||
|
||||
-- Register Player Model
|
||||
|
||||
default.player_register_model("3d_armor_character.b3d", {
|
||||
animation_speed = 30,
|
||||
textures = {
|
||||
armor.default_skin..".png",
|
||||
"3d_armor_trans.png",
|
||||
"3d_armor_trans.png",
|
||||
},
|
||||
animations = {
|
||||
stand = {x=0, y=79},
|
||||
lay = {x=162, y=166},
|
||||
walk = {x=168, y=187},
|
||||
mine = {x=189, y=198},
|
||||
walk_mine = {x=200, y=219},
|
||||
sit = {x=81, y=160},
|
||||
},
|
||||
})
|
||||
|
||||
-- Register Callbacks
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
|
||||
if not name or inv_mod == "inventory_enhanced" then
|
||||
return
|
||||
end
|
||||
if inv_mod == "inventory_plus" and fields.armor then
|
||||
local formspec = armor:get_armor_formspec(name)
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
return
|
||||
end
|
||||
for field, _ in pairs(fields) do
|
||||
if string.find(field, "skins_set") then
|
||||
minetest.after(0, function(player)
|
||||
local skin = armor:get_player_skin(name)
|
||||
armor.textures[name].skin = skin..".png"
|
||||
armor:set_player_armor(player)
|
||||
end, player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
default.player_set_model(player, "3d_armor_character.b3d")
|
||||
local name = player:get_player_name()
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_inv = minetest.create_detached_inventory(name.."_armor", {
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, stack)
|
||||
armor:set_player_armor(player)
|
||||
armor:update_inventory(player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, nil)
|
||||
armor:set_player_armor(player)
|
||||
armor:update_inventory(player)
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
local plaver_inv = player:get_inventory()
|
||||
local stack = inv:get_stack(to_list, to_index)
|
||||
player_inv:set_stack(to_list, to_index, stack)
|
||||
player_inv:set_stack(from_list, from_index, nil)
|
||||
armor:set_player_armor(player)
|
||||
armor:update_inventory(player)
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return 1
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return count
|
||||
end,
|
||||
}, name)
|
||||
if inv_mod == "inventory_plus" then
|
||||
inventory_plus.register_button(player,"armor", "Armor")
|
||||
end
|
||||
armor_inv:set_size("armor", 6)
|
||||
player_inv:set_size("armor", 6)
|
||||
for i=1, 6 do
|
||||
local stack = player_inv:get_stack("armor", i)
|
||||
armor_inv:set_stack("armor", i, stack)
|
||||
end
|
||||
armor.def[name] = {
|
||||
state = 0,
|
||||
count = 0,
|
||||
level = 0,
|
||||
heal = 0,
|
||||
jump = 1,
|
||||
speed = 1,
|
||||
gravity = 1,
|
||||
fire = 0,
|
||||
water = 0,
|
||||
radiation = 0,
|
||||
}
|
||||
armor.textures[name] = {
|
||||
skin = armor.default_skin..".png",
|
||||
armor = "3d_armor_trans.png",
|
||||
wielditem = "3d_armor_trans.png",
|
||||
preview = armor.default_skin.."_preview.png",
|
||||
}
|
||||
if skin_mod == "skins" then
|
||||
local skin = skins.skins[name]
|
||||
if skin and skins.get_type(skin) == skins.type.MODEL then
|
||||
armor.textures[name].skin = skin..".png"
|
||||
end
|
||||
elseif skin_mod == "simple_skins" then
|
||||
local skin = skins.skins[name]
|
||||
if skin then
|
||||
armor.textures[name].skin = skin..".png"
|
||||
end
|
||||
elseif skin_mod == "u_skins" then
|
||||
local skin = u_skins.u_skins[name]
|
||||
if skin and u_skins.get_type(skin) == u_skins.type.MODEL then
|
||||
armor.textures[name].skin = skin..".png"
|
||||
end
|
||||
elseif skin_mod == "wardrobe" then
|
||||
local skin = wardrobe.playerSkins[name]
|
||||
if skin then
|
||||
armor.textures[name].skin = skin
|
||||
end
|
||||
end
|
||||
if minetest.get_modpath("player_textures") then
|
||||
local filename = minetest.get_modpath("player_textures").."/textures/player_"..name
|
||||
local f = io.open(filename..".png")
|
||||
if f then
|
||||
f:close()
|
||||
armor.textures[name].skin = "player_"..name..".png"
|
||||
end
|
||||
end
|
||||
for i=1, ARMOR_INIT_TIMES do
|
||||
minetest.after(ARMOR_INIT_DELAY * i, function(player)
|
||||
armor:set_player_armor(player)
|
||||
if not inv_mod then
|
||||
armor:update_inventory(player)
|
||||
end
|
||||
end, player)
|
||||
end
|
||||
end)
|
||||
|
||||
if ARMOR_DROP == true or ARMOR_DESTROY == true then
|
||||
armor.drop_armor = function(pos, stack)
|
||||
local obj = minetest.add_item(pos, stack)
|
||||
if obj then
|
||||
obj:setvelocity({x=math.random(-1, 1), y=5, z=math.random(-1, 1)})
|
||||
end
|
||||
end
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
|
||||
if not name then
|
||||
return
|
||||
end
|
||||
local drop = {}
|
||||
for i=1, player_inv:get_size("armor") do
|
||||
local stack = armor_inv:get_stack("armor", i)
|
||||
if stack:get_count() > 0 then
|
||||
table.insert(drop, stack)
|
||||
armor_inv:set_stack("armor", i, nil)
|
||||
player_inv:set_stack("armor", i, nil)
|
||||
end
|
||||
end
|
||||
armor:set_player_armor(player)
|
||||
if inv_mod == "unified_inventory" then
|
||||
unified_inventory.set_inventory_formspec(player, "craft")
|
||||
elseif inv_mod == "inventory_plus" then
|
||||
local formspec = inventory_plus.get_formspec(player,"main")
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
else
|
||||
armor:update_inventory(player)
|
||||
end
|
||||
if ARMOR_DESTROY == false then
|
||||
minetest.after(ARMOR_BONES_DELAY, function()
|
||||
local node = minetest.get_node(vector.round(pos))
|
||||
if node then
|
||||
if node.name ~= "bones:bones" then
|
||||
pos.y = pos.y+1
|
||||
node = minetest.get_node(vector.round(pos))
|
||||
if node.name ~= "bones:bones" then
|
||||
minetest.log("warning", "Failed to add armor to bones node.")
|
||||
return
|
||||
end
|
||||
end
|
||||
local meta = minetest.get_meta(vector.round(pos))
|
||||
local owner = meta:get_string("owner")
|
||||
local inv = meta:get_inventory()
|
||||
for _,stack in ipairs(drop) do
|
||||
if name == owner and inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
else
|
||||
armor.drop_armor(pos, stack)
|
||||
end
|
||||
end
|
||||
else
|
||||
for _,stack in ipairs(drop) do
|
||||
armor.drop_armor(pos, stack)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.register_on_player_hpchange(function(player, hp_change)
|
||||
local name, player_inv, armor_inv = armor:get_valid_player(player, "[on_hpchange]")
|
||||
if name and hp_change < 0 then
|
||||
|
||||
-- used for insta kill tools/commands like /kill (doesnt damage armor)
|
||||
if hp_change < -100 then
|
||||
return hp_change
|
||||
end
|
||||
|
||||
local heal_max = 0
|
||||
local state = 0
|
||||
local items = 0
|
||||
for _,v in ipairs(self.elements) do
|
||||
local stack = armor_inv:get_stack("armor_"..v, 1)
|
||||
for i=1, 6 do
|
||||
local stack = player_inv:get_stack("armor", i)
|
||||
if stack:get_count() > 0 then
|
||||
local use = stack:get_definition().groups["armor_use"] or 0
|
||||
local heal = stack:get_definition().groups["armor_heal"] or 0
|
||||
local item = stack:get_name()
|
||||
stack:add_wear(use)
|
||||
armor_inv:set_stack("armor_"..v, 1, stack)
|
||||
player_inv:set_stack("armor_"..v, 1, stack)
|
||||
armor_inv:set_stack("armor", i, stack)
|
||||
player_inv:set_stack("armor", i, stack)
|
||||
state = state + stack:get_wear()
|
||||
items = items + 1
|
||||
if stack:get_count() == 0 then
|
||||
|
@ -92,89 +554,93 @@ armor.update_armor = function(self, player)
|
|||
if desc then
|
||||
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
||||
end
|
||||
self:set_player_armor(player)
|
||||
armor:set_player_armor(player)
|
||||
armor:update_inventory(player)
|
||||
end
|
||||
heal_max = heal_max + heal
|
||||
end
|
||||
end
|
||||
armor.def[name].state = state
|
||||
armor.def[name].count = items
|
||||
heal_max = heal_max * ARMOR_HEAL_MULTIPLIER
|
||||
if heal_max > math.random(100) then
|
||||
player:set_hp(self.player_hp[name])
|
||||
return
|
||||
hp_change = 0
|
||||
end
|
||||
end
|
||||
self.player_hp[name] = hp
|
||||
end
|
||||
|
||||
-- Register Callbacks
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
if fields.armor then
|
||||
local formspec = armor.formspec:gsub("player_name", name)
|
||||
inventory_plus.set_inventory_formspec(player, formspec)
|
||||
return
|
||||
end
|
||||
for field, _ in pairs(fields) do
|
||||
if string.sub(field,0,string.len("skins_set_")) == "skins_set_" then
|
||||
minetest.after(0, function(player)
|
||||
uniskins.skin[name] = skins.skins[name]..".png"
|
||||
uniskins:update_player_visuals(player)
|
||||
end, player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
--inventory_plus.register_button(player,"armor", "Armor")
|
||||
local player_inv = player:get_inventory()
|
||||
local name = player:get_player_name()
|
||||
local armor_inv = minetest.create_detached_inventory(name.."_armor",{
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, stack)
|
||||
armor:set_player_armor(player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
player:get_inventory():set_stack(listname, index, nil)
|
||||
armor:set_player_armor(player)
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if inv:is_empty(listname) then
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
for _,v in ipairs(armor.elements) do
|
||||
local list = "armor_"..v
|
||||
player_inv:set_size(list, 1)
|
||||
armor_inv:set_size(list, 1)
|
||||
armor_inv:set_stack(list, 1, player_inv:get_stack(list, 1))
|
||||
end
|
||||
armor.player_hp[name] = 0
|
||||
armor.def[name] = {
|
||||
state = 0,
|
||||
count = 0
|
||||
}
|
||||
minetest.after(0, function(player)
|
||||
armor:set_player_armor(player)
|
||||
end, player)
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
time = time + dtime
|
||||
if time > update_time then
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
armor:update_armor(player)
|
||||
end
|
||||
time = 0
|
||||
return hp_change
|
||||
end, true)
|
||||
|
||||
-- Fire Protection and water breating, added by TenPlus1
|
||||
|
||||
if ARMOR_FIRE_PROTECT == true then
|
||||
-- override hot nodes so they do not hurt player anywhere but mod
|
||||
for _, row in pairs(ARMOR_FIRE_NODES) do
|
||||
if minetest.registered_nodes[row[1]] then
|
||||
minetest.override_item(row[1], {damage_per_second = 0})
|
||||
end
|
||||
end
|
||||
else
|
||||
print ("[3d_armor] Fire Nodes disabled")
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
armor.timer = armor.timer + dtime
|
||||
if armor.timer < ARMOR_UPDATE_TIME then
|
||||
return
|
||||
end
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local pos = player:getpos()
|
||||
local hp = player:get_hp()
|
||||
-- water breathing
|
||||
if name and armor.def[name].water > 0 then
|
||||
if player:get_breath() < 10 then
|
||||
player:set_breath(10)
|
||||
end
|
||||
end
|
||||
-- fire protection
|
||||
if ARMOR_FIRE_PROTECT == true
|
||||
and name and pos and hp then
|
||||
pos.y = pos.y + 1.4 -- head level
|
||||
local node_head = minetest.get_node(pos).name
|
||||
pos.y = pos.y - 1.2 -- feet level
|
||||
local node_feet = minetest.get_node(pos).name
|
||||
-- is player inside a hot node?
|
||||
for _, row in pairs(ARMOR_FIRE_NODES) do
|
||||
-- check fire protection, if not enough then get hurt
|
||||
if row[1] == node_head or row[1] == node_feet then
|
||||
if hp > 0 and armor.def[name].fire < row[2] then
|
||||
hp = hp - row[3] * ARMOR_UPDATE_TIME
|
||||
player:set_hp(hp)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
armor.timer = 0
|
||||
end)
|
||||
|
||||
-- kill player when command issued
|
||||
minetest.register_chatcommand("kill", {
|
||||
params = "<name>",
|
||||
description = "Kills player instantly",
|
||||
privs = {ban=true},
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(param)
|
||||
if player then
|
||||
player:set_hp(0)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("killme", {
|
||||
description = "Kill yourself instantly",
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player:set_hp(-1001)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
|
||||
armor_api = {
|
||||
player_hp = {},
|
||||
}
|
||||
|
||||
armor_api.get_armor_textures = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local textures = {}
|
||||
local player_inv = player:get_inventory()
|
||||
for _,v in ipairs({"head", "torso", "legs", "feet"}) do
|
||||
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||
if stack:get_definition().groups["armor_"..v] then
|
||||
local item = stack:get_name()
|
||||
textures[v] = item:gsub("%:", "_")..".png"
|
||||
end
|
||||
end
|
||||
return textures
|
||||
end
|
||||
|
||||
armor_api.set_player_armor = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_level = 0
|
||||
for _,v in ipairs({"head", "torso", "legs", "feet"}) do
|
||||
local stack = player_inv:get_stack("armor_"..v, 1)
|
||||
local armor = stack:get_definition().groups["armor_"..v] or 0
|
||||
armor_level = armor_level + armor
|
||||
end
|
||||
local armor_groups = {fleshy=100}
|
||||
if armor_level > 0 then
|
||||
armor_groups.level = math.floor(armor_level / 20)
|
||||
armor_groups.fleshy = 100 - armor_level
|
||||
end
|
||||
player:set_armor_groups(armor_groups)
|
||||
uniskins:update_player_visuals(player)
|
||||
end
|
||||
|
||||
armor_api.update_armor = function(self, player)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local hp = player:get_hp()
|
||||
if hp == nil or hp == 0 or hp == self.player_hp[name] then
|
||||
return
|
||||
end
|
||||
if self.player_hp[name] > hp then
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_inv = minetest.get_inventory({type="detached", name=name.."_outfit"})
|
||||
if armor_inv == nil then
|
||||
return
|
||||
end
|
||||
local heal_max = 0
|
||||
for _,v in ipairs({"head", "torso", "legs", "feet"}) do
|
||||
local stack = armor_inv:get_stack("armor_"..v, 1)
|
||||
if stack:get_count() > 0 then
|
||||
local use = stack:get_definition().groups["armor_use"] or 0
|
||||
local heal = stack:get_definition().groups["armor_heal"] or 0
|
||||
local item = stack:get_name()
|
||||
stack:add_wear(use)
|
||||
armor_inv:set_stack("armor_"..v, 1, stack)
|
||||
player_inv:set_stack("armor_"..v, 1, stack)
|
||||
if stack:get_count() == 0 then
|
||||
local desc = minetest.registered_items[item].description
|
||||
if desc then
|
||||
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
||||
end
|
||||
self:set_player_armor(player)
|
||||
end
|
||||
heal_max = heal_max + heal
|
||||
end
|
||||
end
|
||||
if heal_max > math.random(100) then
|
||||
player:set_hp(self.player_hp[name])
|
||||
return
|
||||
end
|
||||
end
|
||||
self.player_hp[name] = hp
|
||||
end
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
3d_armor -- Crafting Guide
|
||||
--------------------------
|
||||
|
||||
Helmets:
|
||||
|
||||
+---+---+---+
|
||||
| X | X | X |
|
||||
+---+---+---+
|
||||
| X | | X |
|
||||
+---+---+---+
|
||||
| | | |
|
||||
+---+---+---+
|
||||
|
||||
[3d_armor:helmet_wood] X = [default:wood]
|
||||
[3d_armor:helmet_cactus] X = [default:cactus]
|
||||
[3d_armor:helmet_steel] X = [default:steel_ingot]
|
||||
[3d_armor:helmet_bronze] X = [default:bronze_ingot]
|
||||
[3d_armor:helmet_diamond] X = [default:diamond]
|
||||
[3d_armor:helmet_gold] X = [default:gold_ingot]
|
||||
[3d_armor:helmet_mithril] X = [moreores:mithril_ingot] *
|
||||
[3d_armor:helmet_crystal] X = [ethereal:crystal_ingot] **
|
||||
|
||||
Chestplates:
|
||||
|
||||
+---+---+---+
|
||||
| X | | X |
|
||||
+---+---+---+
|
||||
| X | X | X |
|
||||
+---+---+---+
|
||||
| X | X | X |
|
||||
+---+---+---+
|
||||
|
||||
[3d_armor:chestplate_wood] X = [default:wood]
|
||||
[3d_armor:chestplate_cactus] X = [default:cactus]
|
||||
[3d_armor:chestplate_steel] X = [default:steel_ingot]
|
||||
[3d_armor:chestplate_bronze] X = [default:bronze_ingot]
|
||||
[3d_armor:chestplate_diamond] X = [default:diamond]
|
||||
[3d_armor:chestplate_gold] X = [default:gold_ingot]
|
||||
[3d_armor:chestplate_mithril] X = [moreores:mithril_ingot] *
|
||||
[3d_armor:chestplate_crystal] X = [ethereal:crystal_ingot] **
|
||||
|
||||
Leggings:
|
||||
|
||||
+---+---+---+
|
||||
| X | X | X |
|
||||
+---+---+---+
|
||||
| X | | X |
|
||||
+---+---+---+
|
||||
| X | | X |
|
||||
+---+---+---+
|
||||
|
||||
[3d_armor:leggings_wood] X = [default:wood]
|
||||
[3d_armor:leggings_cactus] X = [default:cactus]
|
||||
[3d_armor:leggings_steel] X = [default:steel_ingot]
|
||||
[3d_armor:leggings_bronze] X = [default:bronze_ingot]
|
||||
[3d_armor:leggings_diamond] X = [default:diamond]
|
||||
[3d_armor:leggings_gold] X = [default:gold_ingot]
|
||||
[3d_armor:leggings_mithril] X = [moreores:mithril_ingot] *
|
||||
[3d_armor:leggings_crystal] X = [ethereal:crystal_ingot] **
|
||||
|
||||
Boots:
|
||||
|
||||
+---+---+---+
|
||||
| X | | X |
|
||||
+---+---+---+
|
||||
| X | | X |
|
||||
+---+---+---+
|
||||
|
||||
[3d_armor:boots_wood] X = [default:wood]
|
||||
[3d_armor:boots_cactus] X = [default:cactus]
|
||||
[3d_armor:boots_steel] X = [default:steel_ingot]
|
||||
[3d_armor:boots_bronze] X = [default:bronze_ingot
|
||||
[3d_armor:boots_diamond] X = [default:diamond]
|
||||
[3d_armor:boots_gold] X = [default:gold_ingot]
|
||||
[3d_armor:boots_mithril] X = [moreores:mithril_ingot] *
|
||||
[3d_armor:boots_crystal] X = [ethereal:crystal_ingot] **
|
||||
|
||||
* Requires moreores mod by Calinou - https://forum.minetest.net/viewtopic.php?id=549
|
||||
** Requires ethereal mod by Chinchow & TenPlus1 - https://github.com/tenplus1/ethereal
|
|
@ -1,2 +1,6 @@
|
|||
default
|
||||
unified_skins
|
||||
inventory_plus?
|
||||
unified_inventory?
|
||||
fire?
|
||||
ethereal?
|
||||
bakedclay?
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Adds craftable armor that is visible to other players.
|
|
@ -0,0 +1,31 @@
|
|||
Minetest mod "Crafting"
|
||||
=======================
|
||||
version: 2.0.1
|
||||
|
||||
License of source code and Textures: WTFPL
|
||||
------------------------------------
|
||||
Copyright (c) 2013-2014 BlockMen
|
||||
|
||||
This program is free software. It comes without any warranty, to
|
||||
the extent permitted by applicable law. You can redistribute it
|
||||
and/or modify it under the terms of the Do What The Fuck You Want
|
||||
To Public License, Version 2, as published by Sam Hocevar. See
|
||||
http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
|
||||
--USING the mod--
|
||||
=================
|
||||
This mod changes the players inventory (survival and creative) with more slots (9*4 instead of 8*4)
|
||||
Like known from Minecraft you have a 2x2 crafting grid at inventory now. Furthermore a categorized creative
|
||||
inventory and a support for stu's 3d armor mod (To use the armor and a preview of player).
|
||||
|
||||
Left items in the crafting slots are dropped infront of you.
|
||||
|
||||
Workbench
|
||||
=========
|
||||
With following recipe you craft a workbench (aka crafting table):
|
||||
|
||||
wood wood
|
||||
wood wood
|
||||
|
||||
The workbench has a 3x3 crafting grid, that allows to use all recipes.
|
|
@ -0,0 +1,34 @@
|
|||
Minetest mod "Crafting"
|
||||
=======================
|
||||
Version: 2.0.1
|
||||
|
||||
License of source code and Textures: WTFPL
|
||||
------------------------------------
|
||||
copyright (c) 2013-2014 by BlockMen
|
||||
|
||||
This program is free software. It comes without any warranty, to
|
||||
the extent permitted by applicable law. You can redistribute it
|
||||
and/or modify it under the terms of the Do What The Fuck You Want
|
||||
To Public License, Version 2, as published by Sam Hocevar. See
|
||||
http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
|
||||
--USING the mod--
|
||||
=================
|
||||
|
||||
This mod changes the players inventory (survival and creative) with more slots (9*4 instead of 8*4)
|
||||
Like known from Minecraft you have a 2x2 crafting grid at inventory now. Furthermore a categorized creative
|
||||
inventory and a support for stu's 3d armor mod (To use the armor and a preview of player).
|
||||
|
||||
Left items in the crafting slots are dropped infront of you.
|
||||
|
||||
|
||||
Workbench
|
||||
_________
|
||||
|
||||
With following recipe you craft a workbench (aka crafting table):
|
||||
|
||||
wood wood
|
||||
wood wood
|
||||
|
||||
The workbench has a 3x3 crafting grid, that allows to use all recipes.
|
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 1.3 KiB |
|
@ -0,0 +1,343 @@
|
|||
crafting = {}
|
||||
crafting.creative_inventory_size = 0
|
||||
|
||||
function init()
|
||||
local inv = minetest.create_detached_inventory("creative", {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
|
||||
if stack then
|
||||
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
|
||||
end
|
||||
end,
|
||||
})
|
||||
set_inv("all")
|
||||
end
|
||||
|
||||
function set_inv(filter, player)
|
||||
local inv = minetest.get_inventory({type="detached", name="creative"})
|
||||
inv:set_size("main", 0)
|
||||
local creative_list = {}
|
||||
for name,def in pairs(minetest.registered_items) do
|
||||
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and def.description ~= "" then
|
||||
if filter ~= "" then
|
||||
if filter == "#blocks" then
|
||||
if def.walkable == true then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#deco" then
|
||||
if def.walkable == false or def.drawtype == "plantlike" or def.drawtype == "allfaces_optional" then--def.groups. == true then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#mese" then
|
||||
if string.find(string.lower(def.name), "mese") or string.find(string.lower(def.description), "mese") then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#rail" then
|
||||
if string.find(string.lower(def.name), "rail") or string.find(string.lower(def.description), "rail") or string.find(string.lower(def.name), "cart") or string.find(string.lower(def.description), "cart") or string.find(string.lower(def.description), "boat") then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#misc" then
|
||||
if def.drawtype == nil and def.tool_capabilities == nil and not string.find(string.lower(def.description), "ingot") and not string.find(string.lower(def.description), "lump") and not string.find(string.lower(def.description), "dye") and not string.find(string.lower(def.name), "diamond") and not string.find(string.lower(def.name), "mese") and not string.find(string.lower(def.name), "obsidian") and not string.find(string.lower(def.description), "clay") then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#food" then
|
||||
if def.groups.food ~= nil or string.find(string.lower(def.description), "apple") or string.find(string.lower(def.description), "bread") then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#tools" then
|
||||
if def.tool_capabilities ~= nil and not string.find(string.lower(def.description), "sword") then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#combat" then
|
||||
if def.tool_capabilities ~= nil and (string.find(string.lower(def.description), "sword") or string.find(string.lower(def.name), "armor") or string.find(string.lower(def.description), "bow") or string.find(string.lower(def.description), "arrow")) or string.find(string.lower(def.name), "armor") then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "#matr" then
|
||||
if def.drawtype == nil and def.tool_capabilities == nil and (string.find(string.lower(def.description), "ingot") or string.find(string.lower(def.description), "lump") or string.find(string.lower(def.description), "dye") or string.find(string.lower(def.name), "diamond") or string.find(string.lower(def.name), "mese") or string.find(string.lower(def.name), "obsidian") or string.find(string.lower(def.description), "clay") or string.find(string.lower(def.description), "stick") or string.find(string.lower(def.description), "flint") or string.find(string.lower(def.description), "seed")) then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
elseif filter == "all" then
|
||||
table.insert(creative_list, name)
|
||||
else --for all other
|
||||
if string.find(string.lower(def.name), filter) or string.find(string.lower(def.description), filter) then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(creative_list)
|
||||
inv:set_size("main", #creative_list)
|
||||
for _,itemstring in ipairs(creative_list) do
|
||||
inv:add_item("main", ItemStack(itemstring))
|
||||
end
|
||||
crafting.creative_inventory_size = #creative_list
|
||||
--print("creative inventory size: "..dump(crafting.creative_inventory_size))
|
||||
end
|
||||
|
||||
-- Create the trash field
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, "")
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
|
||||
-- Create detached creative inventory after loading all mods
|
||||
minetest.after(0, init)
|
||||
|
||||
local offset = {}
|
||||
local hoch = {}
|
||||
local bg = {}
|
||||
offset["blocks"] = "-0.29,-0.25"
|
||||
offset["deco"] = "0.98,-0.25"
|
||||
offset["mese"] = "2.23,-0.25"
|
||||
offset["rail"] = "3.495,-0.25"
|
||||
offset["misc"] = "4.75,-0.25"
|
||||
offset["nix"] = "8.99,-0.25"
|
||||
offset["food"] = "-0.29,8.12"
|
||||
offset["tools"] = "0.98,8.12"
|
||||
offset["combat"] = "2.23,8.12"
|
||||
offset["brew"] = "3.495,8.12"
|
||||
offset["matr"] = offset["brew"]--"4.74,8.12"
|
||||
offset["inv"] = "8.99,8.12"
|
||||
|
||||
hoch["blocks"] = ""
|
||||
hoch["deco"] = ""
|
||||
hoch["mese"] = ""
|
||||
hoch["rail"] = ""
|
||||
hoch["misc"] = ""
|
||||
hoch["nix"] = ""
|
||||
hoch["food"] = "^[transformfy"
|
||||
hoch["tools"] = "^[transformfy"
|
||||
hoch["combat"] = "^[transformfy"
|
||||
hoch["brew"] = "^[transformfy"
|
||||
hoch["matr"] = "^[transformfy"
|
||||
hoch["inv"] = "^[transformfy"
|
||||
|
||||
local dark_bg = "crafting_creative_bg_dark.png"
|
||||
|
||||
local function reset_menu_item_bg()
|
||||
bg["blocks"] = dark_bg
|
||||
bg["deco"] = dark_bg
|
||||
bg["mese"] = dark_bg
|
||||
bg["rail"] = dark_bg
|
||||
bg["misc"] = dark_bg
|
||||
bg["nix"] = dark_bg
|
||||
bg["food"] = dark_bg
|
||||
bg["tools"] = dark_bg
|
||||
bg["combat"] = dark_bg
|
||||
bg["brew"] = dark_bg
|
||||
bg["matr"] = dark_bg
|
||||
bg["inv"] = dark_bg
|
||||
end
|
||||
|
||||
|
||||
crafting.set_creative_formspec = function(player, start_i, pagenum, show, page)
|
||||
reset_menu_item_bg()
|
||||
pagenum = math.floor(pagenum) or 1
|
||||
local pagemax = math.floor((crafting.creative_inventory_size-1) / (9*5) + 1)
|
||||
local slider_height = 4/pagemax
|
||||
local slider_pos = slider_height*(pagenum-1)+2.25
|
||||
local name = "nix"
|
||||
local formspec = ""
|
||||
local main_list = "list[detached:creative;main;0,1.75;9,5;"..tostring(start_i).."]"
|
||||
if page ~= nil then name = page end
|
||||
bg[name] = "crafting_creative_bg.png"
|
||||
if name == "inv" then
|
||||
main_list = "image[-0.2,1.7;11.35,2.33;crafting_creative_bg.png]"..
|
||||
"list[current_player;main;0,3.75;9,3;9]"
|
||||
end
|
||||
formspec = "size[10,9.3]"..
|
||||
"background[-0.19,-0.25;10.5,9.87;crafting_inventory_creative.png]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
"label[-5,-5;"..name.."]"..
|
||||
"image[" .. offset[name] .. ";1.5,1.44;crafting_creative_active.png"..hoch[name].."]"..
|
||||
"image_button[-0.1,0;1,1;"..bg["blocks"].."^crafting_creative_build.png;build;]".. --build blocks
|
||||
"image_button[1.15,0;1,1;"..bg["deco"].."^crafting_creative_deko.png;deco;]".. --decoration blocks
|
||||
"image_button[2.415,0;1,1;"..bg["mese"].."^crafting_creative_mese.png;mese;]".. --redstone
|
||||
"image_button[3.693,0;1,1;"..bg["rail"].."^crafting_creative_rail.png;rail;]".. --transportation
|
||||
"image_button[4.93,0;1,1;"..bg["misc"].."^crafting_creative_misc.png;misc;]".. --miscellaneous
|
||||
"image_button[9.19,0;1,1;"..bg["nix"].."^crafting_creative_all.png;default;]".. --search
|
||||
"image[0,1;5,0.75;fnt_"..name..".png]"..
|
||||
"list[current_player;main;0,7;9,1;]"..
|
||||
main_list..
|
||||
"image_button[9.03,1.74;0.85,0.6;crafting_creative_up.png;creative_prev;]"..
|
||||
"image[9.04," .. tostring(slider_pos) .. ";0.75,"..tostring(slider_height) .. ";crafting_slider.png]"..
|
||||
"image_button[9.03,6.15;0.85,0.6;crafting_creative_down.png;creative_next;]"..
|
||||
"image_button[-0.1,8.28;1,1;"..bg["food"].."^crafting_food.png;food;]".. --foodstuff
|
||||
"image_button[1.15,8.28;1,1;"..bg["tools"].."^crafting_creative_tool.png;tools;]".. --tools
|
||||
"image_button[2.415,8.28;1,1;"..bg["combat"].."^crafting_creative_sword.png;combat;]".. --combat
|
||||
"image_button[3.693,8.28;1,1;"..bg["matr"].."^crafting_creative_matr.png;matr;]".. --brewing
|
||||
--"image_button[4.93,8.28;1,1;"..bg["brew"].."^crafting_creative_matr.png;matr;]".. --materials^
|
||||
"image_button[9.19,8.28;1,1;"..bg["inv"].."^crafting_creative_inv.png;inv;]".. --inventory
|
||||
"list[detached:creative_trash;main;9,7;1,1;]"..
|
||||
"image[9,7;1,1;crafting_creative_trash.png]"
|
||||
|
||||
if name == "nix" then formspec = formspec .. "field[5.3,1.3;4,0.75;suche;;]" end
|
||||
if pagenum ~= nil then formspec = formspec .. "p"..tostring(pagenum) end
|
||||
|
||||
player:set_inventory_formspec(formspec)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local page = nil
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
return
|
||||
end
|
||||
|
||||
if fields.bgcolor then
|
||||
minetest.chat_send_all("jupp")
|
||||
end
|
||||
if fields.suche ~= nil and fields.suche ~= "" then
|
||||
set_inv(string.lower(fields.suche))
|
||||
minetest.after(0.5, function()
|
||||
minetest.show_formspec(player:get_player_name(), "detached:creative", player:get_inventory_formspec())
|
||||
end)
|
||||
end
|
||||
|
||||
if fields.build then
|
||||
set_inv("#blocks",player)
|
||||
page = "blocks"
|
||||
end
|
||||
if fields.deco then
|
||||
set_inv("#deco",player)
|
||||
page = "deco"
|
||||
end
|
||||
if fields.mese then
|
||||
set_inv("#mese",player)
|
||||
page = "mese"
|
||||
end
|
||||
if fields.rail then
|
||||
set_inv("#rail",player)
|
||||
page = "rail"
|
||||
end
|
||||
if fields.misc then
|
||||
set_inv("#misc",player)
|
||||
page = "misc"
|
||||
end
|
||||
if fields.default then
|
||||
set_inv("all")
|
||||
page = nil
|
||||
end
|
||||
if fields.food then
|
||||
set_inv("#food")
|
||||
page = "food"
|
||||
end
|
||||
if fields.tools then
|
||||
set_inv("#tools")
|
||||
page = "tools"
|
||||
end
|
||||
if fields.combat then
|
||||
set_inv("#combat")
|
||||
page = "combat"
|
||||
end
|
||||
if fields.matr then
|
||||
set_inv("#matr")
|
||||
page = "matr"
|
||||
end
|
||||
if fields.inv then
|
||||
page = "inv"
|
||||
end
|
||||
-- Figure out current page from formspec
|
||||
local current_page = 0
|
||||
local formspec = player:get_inventory_formspec()
|
||||
|
||||
local size = string.len(formspec)
|
||||
local marker = string.sub(formspec,size-2)
|
||||
marker = string.sub(marker,1)
|
||||
if marker ~= nil and marker == "p" then
|
||||
local page = string.sub(formspec,size-1)
|
||||
--minetest.chat_send_all(page)
|
||||
start_i = page
|
||||
end
|
||||
start_i = tonumber(start_i) or 0
|
||||
if fields.creative_prev then
|
||||
start_i = start_i - 9*5
|
||||
page = tmp_page
|
||||
end
|
||||
if fields.creative_next then
|
||||
start_i = start_i + 9*5
|
||||
page = tmp_page
|
||||
end
|
||||
if start_i < 0 then
|
||||
start_i = start_i + 9*5
|
||||
end
|
||||
if start_i >= crafting.creative_inventory_size then
|
||||
start_i = start_i - 9*5
|
||||
end
|
||||
if start_i < 0 or start_i >= crafting.creative_inventory_size then
|
||||
start_i = 0
|
||||
end
|
||||
crafting.set_creative_formspec(player, start_i, start_i / (9*5) + 1, false, page)
|
||||
end)
|
||||
|
||||
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
minetest.register_item(":", {
|
||||
type = "none",
|
||||
wield_image = "wieldhand.png",
|
||||
wield_scale = {x=1,y=1,z=2.5},
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.5,
|
||||
max_drop_level = 3,
|
||||
groupcaps = {
|
||||
crumbly = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
cracky = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
snappy = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
choppy = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
oddly_breakable_by_hand = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
return true
|
||||
end)
|
||||
|
||||
function minetest.handle_node_drops(pos, drops, digger)
|
||||
if not digger or not digger:is_player() then
|
||||
return
|
||||
end
|
||||
local inv = digger:get_inventory()
|
||||
if inv then
|
||||
for _,item in ipairs(drops) do
|
||||
item = ItemStack(item):get_name()
|
||||
if not inv:contains_item("main", item) then
|
||||
inv:add_item("main", item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,79 @@
|
|||
default.furnace_inactive_formspec =
|
||||
"size[9,8.75]"..
|
||||
"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory_furnace.png]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
"list[current_name;src;2.75,0.5;1,1;]"..
|
||||
"list[current_name;fuel;2.75,2.5;1,1;]"..
|
||||
"list[current_name;dst;5.75,1.5;1,1;]"..
|
||||
"image[2.75,1.5;1,1;crafting_furnace_fire_bg.png"
|
||||
|
||||
function default.get_furnace_active_formspec(pos, percent)
|
||||
local formspec =
|
||||
"size[9,8.75]"..
|
||||
"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory_furnace.png]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
"list[current_name;src;2.75,0.5;1,1;]"..
|
||||
"list[current_name;fuel;2.75,2.5;1,1;]"..
|
||||
"list[current_name;dst;5.75,1.5;1,1;]"..
|
||||
"image[2.75,1.5;1,1;crafting_furnace_fire_bg.png^[lowpart:"..
|
||||
(100-percent)..":default_furnace_fire_fg.png]"
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("dst",1)
|
||||
|
||||
return formspec
|
||||
end
|
||||
|
||||
default.chest_formspec =
|
||||
"size[9,9.75]"..
|
||||
"background[-0.19,-0.25;9.41,10.48;crafting_inventory_chest.png]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
"list[current_name;main;0,0.5;9,4;]"..
|
||||
"list[current_player;main;0,5.5;9,3;9]"..
|
||||
"list[current_player;main;0,8.74;9,1;]"
|
||||
|
||||
local chest_inv_size = 4*9
|
||||
local chest_inv_vers = 2
|
||||
|
||||
function default.get_locked_chest_formspec(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv_v = meta:get_int("chest_inv_ver")
|
||||
if inv_v and inv_v < chest_inv_vers then
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main",chest_inv_size)
|
||||
meta:set_int("chest_inv_ver",chest_inv_vers)
|
||||
end
|
||||
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
||||
local formspec =
|
||||
"size[9,9.75]"..
|
||||
"background[-0.19,-0.25;9.41,10.48;crafting_inventory_chest.png]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
"list[nodemeta:".. spos .. ";main;0,0.5;9,4;]"..
|
||||
"list[current_player;main;0,5.5;9,3;9]"..
|
||||
"list[current_player;main;0,8.74;9,1;]"
|
||||
return formspec
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:chest"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv_v = meta:get_int("chest_inv_ver")
|
||||
if inv_v and inv_v < chest_inv_vers then
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main",chest_inv_size)
|
||||
meta:set_int("chest_inv_ver",chest_inv_vers)
|
||||
end
|
||||
end
|
||||
})
|
|
@ -0,0 +1,196 @@
|
|||
dofile(minetest.get_modpath("crafting").."/formspecs.lua")
|
||||
|
||||
local show_armor = false
|
||||
if minetest.get_modpath("3d_armor") ~= nil then show_armor = true end
|
||||
|
||||
local function item_drop(itemstack, dropper, pos)
|
||||
if dropper:is_player() then
|
||||
local v = dropper:get_look_dir()
|
||||
local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
|
||||
p.x = p.x+(math.random(1,3)*0.2)
|
||||
p.z = p.z+(math.random(1,3)*0.2)
|
||||
local obj = minetest.env:add_item(p, itemstack)
|
||||
if obj then
|
||||
v.x = v.x*4
|
||||
v.y = v.y*4 + 2
|
||||
v.z = v.z*4
|
||||
obj:setvelocity(v)
|
||||
end
|
||||
else
|
||||
minetest.add_item(pos, itemstack)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function drop_fields(player, name)
|
||||
local inv = player:get_inventory()
|
||||
for i,stack in ipairs(inv:get_list(name)) do
|
||||
item_drop(stack, player, player:getpos())
|
||||
stack:clear()
|
||||
inv:set_stack(name, i, stack)
|
||||
end
|
||||
end
|
||||
|
||||
local player_armor = {}
|
||||
|
||||
local function update_armor(player)
|
||||
local out = ""
|
||||
if not player then return end
|
||||
local name = player:get_player_name()
|
||||
if not armor or not armor.textures then return end
|
||||
local armor_str = armor.textures[name].armor
|
||||
if string.find(armor_str, "leggings") then
|
||||
out = out .. "^crafting_armor_legs.png"
|
||||
end
|
||||
if string.find(armor_str, "boots") then
|
||||
out = out .. "^crafting_armor_boots.png"
|
||||
end
|
||||
if string.find(armor_str, "helmet") then
|
||||
out = out .. "^crafting_armor_helmet.png"
|
||||
end
|
||||
if string.find(armor_str, "chestplate") then
|
||||
out = out .. "^crafting_armor_chest.png"
|
||||
end
|
||||
player_armor[name] = out
|
||||
end
|
||||
|
||||
local function set_inventory(player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
minetest.after(0.5,function()
|
||||
crafting.set_creative_formspec(player, 0, 1)
|
||||
return
|
||||
end)
|
||||
end
|
||||
player:get_inventory():set_width("craft", 3)
|
||||
player:get_inventory():set_size("craft", 9)
|
||||
player:get_inventory():set_size("main", 9*4)
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
local img = "crafting_inventory_player.png"
|
||||
local armor_img = ""
|
||||
if show_armor then
|
||||
armor_img = "^crafting_inventory_armor.png"
|
||||
if player_armor[player_name] ~= nil then
|
||||
img = img .. player_armor[player_name]
|
||||
end
|
||||
end
|
||||
local img_element = "image[1,0;3,4;"..img.."]"
|
||||
if show_armor and armor.textures[player_name] and armor.textures[player_name].preview then
|
||||
img = armor.textures[player_name].preview
|
||||
local s1 = img:find("character_preview")
|
||||
if s1 ~= nil then
|
||||
s1 = img:sub(s1+21)
|
||||
img = "crafting_player2d.png"..s1
|
||||
end
|
||||
img_element = "image[1.5,0;2,4;"..img.."]"
|
||||
end
|
||||
|
||||
local form = "size[9,8.75]"..
|
||||
"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory.png"..armor_img.."]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
img_element
|
||||
--armor
|
||||
if show_armor then
|
||||
if armor.def[player_name] and armor.def[player_name].level then
|
||||
form = form ..
|
||||
"list[detached:"..player_name.."_armor;armor;0,0;1,1;1]"..
|
||||
"list[detached:"..player_name.."_armor;armor;0,1;1,1;2]"..
|
||||
"list[detached:"..player_name.."_armor;armor;0,2;1,1;3]"..
|
||||
"list[detached:"..player_name.."_armor;armor;0,3;1,1;4]"
|
||||
else
|
||||
form = form ..
|
||||
"list[detached:"..player_name.."_armor;armor_head;0,0;1,1;]"..
|
||||
"list[detached:"..player_name.."_armor;armor_torso;0,1;1,1;]"..
|
||||
"list[detached:"..player_name.."_armor;armor_legs;0,2;1,1;]"..
|
||||
"list[detached:"..player_name.."_armor;armor_feet;0,3;1,1;]"
|
||||
end
|
||||
end
|
||||
form = form ..
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
"list[current_player;main;0,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,1.5;1,1;]"..
|
||||
"inv"
|
||||
|
||||
player:set_inventory_formspec(form)
|
||||
end
|
||||
|
||||
local function set_workbench(player)
|
||||
player:get_inventory():set_width("craft", 3)
|
||||
player:get_inventory():set_size("craft", 9)
|
||||
player:get_inventory():set_size("main", 9*4)
|
||||
|
||||
local form = "size[9,8.75]"..
|
||||
"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory_workbench.png]"..
|
||||
"bgcolor[#080808BB;true]"..
|
||||
"listcolors[#9990;#FFF7;#FFF0;#160816;#D4D2FF]"..
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
"list[current_player;craft;1.75,0.5;3,3;]"..
|
||||
"list[current_player;craftpreview;5.75,1.5;1,1;]"..
|
||||
"wob"
|
||||
|
||||
--player:set_inventory_formspec(form)
|
||||
minetest.show_formspec(player:get_player_name(), "main", form)
|
||||
end
|
||||
|
||||
--drop craf items and reset inventory on closing
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if fields.quit then
|
||||
local formspec = player:get_inventory_formspec()
|
||||
local size = string.len(formspec)
|
||||
local marker = string.sub(formspec,size-2)
|
||||
if marker == "inv" or marker == "wob" then
|
||||
set_inventory(player)
|
||||
drop_fields(player,"craft")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
dofile(minetest.get_modpath("crafting").."/creative.lua")
|
||||
end
|
||||
--init inventory
|
||||
set_inventory(player)
|
||||
--set hotbar size
|
||||
if player.hud_set_hotbar_itemcount then
|
||||
minetest.after(0.5, player.hud_set_hotbar_itemcount, player, 9)
|
||||
end
|
||||
--add hotbar images
|
||||
minetest.after(0.5,function()
|
||||
player:hud_set_hotbar_image("crafting_hotbar.png")
|
||||
player:hud_set_hotbar_selected_image("crafting_hotbar_selected.png")
|
||||
|
||||
if show_armor then
|
||||
local armor_orginal = armor.set_player_armor
|
||||
armor.set_player_armor = function(self, player)
|
||||
armor_orginal(self, player)
|
||||
update_armor(player)
|
||||
set_inventory(player)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
minetest.register_node("crafting:workbench", {
|
||||
description = "Workbench",
|
||||
tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png",
|
||||
"crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"},
|
||||
paramtype2 = "facedir",
|
||||
paramtype = "light",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2,flammable=2},
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
set_workbench(clicker)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "crafting:workbench",
|
||||
recipe = {
|
||||
{"group:wood", "group:wood"},
|
||||
{"group:wood", "group:wood"}
|
||||
}
|
||||
})
|
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 397 B |
After Width: | Height: | Size: 806 B |
After Width: | Height: | Size: 340 B |
After Width: | Height: | Size: 228 B |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 870 B |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 370 B |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 406 B |
After Width: | Height: | Size: 382 B |
After Width: | Height: | Size: 400 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 408 B |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 233 B |
After Width: | Height: | Size: 372 B |
After Width: | Height: | Size: 483 B |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 134 B |
After Width: | Height: | Size: 801 B |
After Width: | Height: | Size: 768 B |
After Width: | Height: | Size: 1012 B |
After Width: | Height: | Size: 844 B |
After Width: | Height: | Size: 524 B |
After Width: | Height: | Size: 947 B |
After Width: | Height: | Size: 658 B |
After Width: | Height: | Size: 895 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 459 B |
After Width: | Height: | Size: 744 B |
After Width: | Height: | Size: 751 B |
After Width: | Height: | Size: 859 B |
After Width: | Height: | Size: 487 B |
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,9 @@
|
|||
creative = {}
|
||||
|
||||
creative.set_creative_formspec = function()
|
||||
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
end)
|
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
crafting
|
|
@ -0,0 +1,7 @@
|
|||
inventory_plus = {}
|
||||
|
||||
function inventory_plus.set_inventory_formspec(player, formspec)
|
||||
end
|
||||
|
||||
function inventory_plus.register_button(player,str1, str2)
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
Minetest 0.4 mod: creative
|
||||
==========================
|
||||
|
||||
Implements creative mode.
|
||||
|
||||
Switch on by using the "creative_mode" setting.
|
||||
|
||||
Registered items that
|
||||
- have a description, and
|
||||
- do not have the group not_in_creative_inventory
|
||||
are added to the creative inventory.
|
||||
|
||||
License of source code:
|
||||
---------------------------------------
|
||||
Copyright (C) 2012 Perttu Ahola (celeron55) <celeron55@gmail.com>
|
||||
|
||||
This program is free software. It comes without any warranty, to
|
||||
the extent permitted by applicable law. You can redistribute it
|
||||
and/or modify it under the terms of the Do What The Fuck You Want
|
||||
To Public License, Version 2, as published by Sam Hocevar. See
|
||||
http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
|
@ -1 +0,0 @@
|
|||
default
|
|
@ -1,178 +0,0 @@
|
|||
-- minetest/creative/init.lua
|
||||
--[[
|
||||
creative_inventory = {}
|
||||
creative_inventory.creative_inventory_size = 0
|
||||
|
||||
-- Create detached creative inventory after loading all mods
|
||||
minetest.after(0, function()
|
||||
local inv = minetest.create_detached_inventory("creative", {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
|
||||
if stack then
|
||||
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
|
||||
end
|
||||
end,
|
||||
})
|
||||
local creative_list = {}
|
||||
for name,def in pairs(minetest.registered_items) do
|
||||
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
|
||||
and def.description and def.description ~= "" then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
end
|
||||
table.sort(creative_list)
|
||||
inv:set_size("main", #creative_list)
|
||||
for _,itemstring in ipairs(creative_list) do
|
||||
inv:add_item("main", ItemStack(itemstring))
|
||||
end
|
||||
creative_inventory.creative_inventory_size = #creative_list
|
||||
print("creative inventory size: "..dump(creative_inventory.creative_inventory_size))
|
||||
end)
|
||||
|
||||
-- Create the trash field
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
-- Allow the stack to be placed and remove it in on_put()
|
||||
-- This allows the creative inventory to restore the stack
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, "")
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
|
||||
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
||||
pagenum = math.floor(pagenum)
|
||||
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
|
||||
player:set_inventory_formspec("size[14,7.5]"..
|
||||
--"image[6,0.6;1,2;player.png]"..
|
||||
"list[current_player;main;5,3.5;9,4;]"..
|
||||
"list[current_player;craft;8,0;3,3;]"..
|
||||
"list[current_player;craftpreview;12,1;1,1;]"..
|
||||
"list[detached:creative;main;0.3,0.5;4,6;"..tostring(start_i).."]"..
|
||||
"label[2.0,6.55;"..tostring(pagenum).."/"..tostring(pagemax).."]"..
|
||||
"button[0.3,6.5;1.6,1;creative_prev;<<]"..
|
||||
"button[2.7,6.5;1.6,1;creative_next;>>]"..
|
||||
"label[5,1.5;Trash:]"..
|
||||
"list[detached:creative_trash;main;5,2;1,1;]")
|
||||
player:get_inventory():set_width("craft", 3)
|
||||
player:get_inventory():set_size("craft", 9)
|
||||
player:get_inventory():set_size("main", 9*4)
|
||||
if player.hud_set_hotbar_itemcount then
|
||||
minetest.after(0, player.hud_set_hotbar_itemcount, player, 9)
|
||||
end
|
||||
end
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
-- If in creative mode, modify player's inventory forms
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
return
|
||||
end
|
||||
creative_inventory.set_creative_formspec(player, 0, 1)
|
||||
end)
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
return
|
||||
end
|
||||
-- Figure out current page from formspec
|
||||
local current_page = 0
|
||||
local formspec = player:get_inventory_formspec()
|
||||
local start_i = string.match(formspec, "list%[detached:creative;main;[%d.]+,[%d.]+;[%d.]+,[%d.]+;(%d+)%]")
|
||||
start_i = tonumber(start_i) or 0
|
||||
|
||||
if fields.creative_prev then
|
||||
start_i = start_i - 4*6
|
||||
end
|
||||
if fields.creative_next then
|
||||
start_i = start_i + 4*6
|
||||
end
|
||||
|
||||
if start_i < 0 then
|
||||
start_i = start_i + 4*6
|
||||
end
|
||||
if start_i >= creative_inventory.creative_inventory_size then
|
||||
start_i = start_i - 4*6
|
||||
end
|
||||
|
||||
if start_i < 0 or start_i >= creative_inventory.creative_inventory_size then
|
||||
start_i = 0
|
||||
end
|
||||
|
||||
creative_inventory.set_creative_formspec(player, start_i, start_i / (6*4) + 1)
|
||||
end)
|
||||
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
|
||||
local function get_list(num)
|
||||
local table = {times={}, uses=0}
|
||||
for i=1,num do
|
||||
table.times[i] = 0
|
||||
end
|
||||
return table
|
||||
end
|
||||
|
||||
minetest.register_item(":", {
|
||||
type = "none",
|
||||
wield_image = "wieldhand.png",
|
||||
wield_scale = {x=1,y=1,z=2.5},
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.5,
|
||||
max_drop_level = 3,
|
||||
groupcaps = {
|
||||
crumbly = get_list(8),
|
||||
cracky = get_list(20),
|
||||
snappy = get_list(2),
|
||||
choppy = get_list(9),
|
||||
dig = get_list(7),
|
||||
},
|
||||
damage_groups = {fleshy = 10},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
return true
|
||||
end)
|
||||
|
||||
function minetest.handle_node_drops(pos, drops, digger)
|
||||
if not digger or not digger:is_player() then
|
||||
return
|
||||
end
|
||||
local inv = digger:get_inventory()
|
||||
if inv then
|
||||
for _,item in ipairs(drops) do
|
||||
item = ItemStack(item):get_name()
|
||||
if not inv:contains_item("main", item) then
|
||||
inv:add_item("main", item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
]]
|
|
@ -1,83 +0,0 @@
|
|||
inven = {}
|
||||
CREATIVE_FORMSPEC = "";
|
||||
SURVIVAL_FORMSPEC = "";
|
||||
|
||||
function inventory.creative_inv(player)
|
||||
local name = player:get_player_name()
|
||||
CREATIVE_FORMSPEC =
|
||||
"size[11,9.75]"..
|
||||
default.inventory_header..
|
||||
--"background[-0.25,1;10.5,8;mcl_inventory_creative_inventory_bg.png]"..
|
||||
"button[9.5,0;1.5,1.5;creative_search;Search]"..
|
||||
"list[detached:"..name.."_armor;armor_head;0.25,1.25;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_torso;0.25,2.5;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_legs;2.75,1.25;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_feet;2.75,2.5;1,1;]"..
|
||||
"image[1.3,1;1.5,3;player.png]"..
|
||||
"list[current_player;main;0,4;9,4;9]"..
|
||||
"list[current_player;main;0,7.75;9,1;]"..
|
||||
"list[detached:creative_trash;main;9.1,7.75;1,1;]"..
|
||||
"button[9.15,6;1,1;clear_inventory;Clear]"..
|
||||
"button[9.5,8.75;1.5,1.5;creative_survival;Survival]"
|
||||
|
||||
player:get_inventory():set_width("main", 9)
|
||||
player:get_inventory():set_size("main", 36)
|
||||
player:set_inventory_formspec(CREATIVE_FORMSPEC)
|
||||
end
|
||||
|
||||
function inventory.survival_inv(player)
|
||||
local name = player:get_player_name()
|
||||
SURVIVAL_FORMSPEC =
|
||||
"size[9,9.5]"..
|
||||
default.inventory_header..
|
||||
--"background[-0.4,-0.45;9.8,9.825;mcl_inventory_survival_inventory_bg.png]"..
|
||||
"list[detached:"..name.."_armor;armor_head;0,0;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_torso;0,1;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_legs;0,2;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_feet;0,3;1,1;]"..
|
||||
"image[1.6,0.25;2,4;player.png]"..
|
||||
"list[current_player;main;0,4.5;9,4;9]"..
|
||||
"list[current_player;main;0,8.25;9,1;]"..
|
||||
"list[current_player;craft;4,1;2,2;]"..
|
||||
"list[current_player;craftpreview;7,1.5;1,1;]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[current_player;craft]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[detached:"..name.."_armor;armor_head]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[detached:"..name.."_armor;armor_torso]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[detached:"..name.."_armor;armor_legs]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[detached:"..name.."_armor;armor_feet]"
|
||||
|
||||
player:get_inventory():set_width("craft", 2)
|
||||
player:get_inventory():set_size("craft", 4)
|
||||
player:get_inventory():set_width("main", 9)
|
||||
player:get_inventory():set_size("main", 36)
|
||||
player:set_inventory_formspec(SURVIVAL_FORMSPEC)
|
||||
end
|
||||
|
||||
CRAFTING_FORMSPEC =
|
||||
"size[9,8.5]"..
|
||||
default.inventory_header..
|
||||
"background[-0.4,-0.5;9.78,9.5;mcl_inventory_crafting_inventory_bg.png]"..
|
||||
"list[current_player;main;0,4.32;9,4;9]"..
|
||||
"list[current_player;main;0,7.6;9,1;]"..
|
||||
"list[current_player;craft;1.218,0.46;3,3;]"..
|
||||
"list[current_player;craftpreview;6.44,1.5;1.5,1.5;]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[current_player;craft]"
|
||||
|
||||
--
|
||||
-- Hotbar
|
||||
--
|
||||
|
||||
function inventory.hotbar(player)
|
||||
local name = player:get_player_name()
|
||||
if player.hud_set_hotbar_itemcount then
|
||||
minetest.after(0, player.hud_set_hotbar_itemcount, player, 9)
|
||||
end
|
||||
player:hud_set_hotbar_image("mcl_inventory_hotbar.png")
|
||||
player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png")
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
--Configuration file for Inventory
|
||||
|
||||
-- Set "Creative" for all Player have creatif , set "Survival" for all player in normal mode
|
||||
Default_Mode = "Survival"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
default
|
||||
3d_armor
|
|
@ -1,283 +0,0 @@
|
|||
local init = os.clock()
|
||||
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
local filepath = minetest.get_worldpath()
|
||||
|
||||
CREATIVE_SEARCH_ITEMS = ""
|
||||
|
||||
local creative_type = "search"
|
||||
|
||||
filepath = minetest.get_worldpath()
|
||||
se = {}
|
||||
|
||||
function save_player_data()
|
||||
local file = io.open(filepath .. "/playerdata.txt", "w")
|
||||
file:write(minetest.serialize(playerdata))
|
||||
file:close()
|
||||
end
|
||||
|
||||
function load_player_data()
|
||||
local file = io.open(filepath .. "/playerdata.txt", "r")
|
||||
if file then
|
||||
local table = minetest.deserialize(file:read("*all"))
|
||||
if type(table) == "table" then
|
||||
return table
|
||||
|
||||
end
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
|
||||
|
||||
inventory = {}
|
||||
inventory.inventory_size = 0
|
||||
pagenum = 0
|
||||
playerdata = load_player_data()
|
||||
|
||||
dofile(path.."/config.txt")
|
||||
dofile(path.."/api.lua")
|
||||
dofile(path.."/workbench.lua")
|
||||
|
||||
local function save_newplayer(pname)
|
||||
if not playerdata[pname] then
|
||||
playerdata[pname] = {}
|
||||
playerdata[pname]['isPlayer'] = true
|
||||
playerdata[pname]['gamemode'] = Default_Mode
|
||||
save_player_data()
|
||||
minetest.after(1, function() load_player_data() end)
|
||||
playerdata = load_player_data()
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
local playerdata = load_player_data()
|
||||
if not playerdata[pname] then
|
||||
playerdata[pname] = {}
|
||||
playerdata[pname]['isPlayer'] = true
|
||||
playerdata[pname]['gamemode'] = Default_Mode
|
||||
save_player_data()
|
||||
|
||||
end
|
||||
if not playerdata[pname]['gamemode'] then
|
||||
playerdata[pname]['gamemode'] = Default_Mode
|
||||
save_player_data()
|
||||
playerdata = load_player_data()
|
||||
minetest.after(1, function() updategamemode(pname, "0") end)
|
||||
else
|
||||
minetest.after(1, function() updategamemode(pname, "0") end)
|
||||
end
|
||||
end)
|
||||
|
||||
--Ensure that all mods are loaded before editing inventory.
|
||||
minetest.after(0.3, function()
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
-- Allow the stack to be placed and remove it in on_put()
|
||||
-- This allows the creative inventory to restore the stack
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, "")
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
|
||||
local creative_list = {}
|
||||
for name,def in pairs(minetest.registered_items) do
|
||||
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
|
||||
and def.description and def.description ~= "" then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
local inv = minetest.create_detached_inventory("creative", {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return count
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
return -1
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
|
||||
if stack then
|
||||
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
table.sort(creative_list)
|
||||
|
||||
inv:set_size("main", #creative_list)
|
||||
|
||||
for _,itemstring in ipairs(creative_list) do
|
||||
local stack = ItemStack(itemstring)
|
||||
local stack2 = nil
|
||||
if stack:get_stack_max() == 1 then
|
||||
stack2 = ItemStack(stack:get_name())
|
||||
else
|
||||
stack2 = ItemStack(stack:get_name().." "..(stack:get_stack_max()))--- for know how many item
|
||||
end
|
||||
inv:add_item("main", stack2)
|
||||
end
|
||||
inventory.inventory_size = #creative_list
|
||||
|
||||
end)
|
||||
|
||||
-- Create detached creative inventory after loading all mods
|
||||
function updategamemode(pname, status)
|
||||
playerdata = load_player_data()
|
||||
if not status then
|
||||
print(pname.." has switched to "..playerdata[pname]['gamemode'].." Mode.")
|
||||
minetest.chat_send_all(pname.." has switched to "..playerdata[pname]['gamemode'].." Mode.")
|
||||
end
|
||||
print(playerdata[pname])
|
||||
if playerdata[pname] == nil then
|
||||
save_newplayer(pname)
|
||||
end
|
||||
if playerdata[pname]['gamemode'] == "Creative" then
|
||||
local player = minetest.env:get_player_by_name(pname)
|
||||
inventory.set_player_formspec(player, 1, 1)
|
||||
else
|
||||
|
||||
local player = minetest.env:get_player_by_name(pname)
|
||||
inventory.set_player_formspec(player, 1, 1)
|
||||
|
||||
end
|
||||
end
|
||||
inventory.set_player_formspec = function(player, start_i, pagenum)
|
||||
playerdata = load_player_data()
|
||||
if playerdata[player:get_player_name()]['gamemode'] == "Creative" then
|
||||
inventory.creative_inv(player)
|
||||
inventory.hotbar(player)
|
||||
end
|
||||
|
||||
if creative_type == "search" and playerdata[player:get_player_name()]['gamemode'] == "Creative" then
|
||||
local pagenum = math.floor(pagenum)
|
||||
local pagemax = math.floor((inventory.inventory_size-1) / (9*3) + 1)
|
||||
CREATIVE_SEARCH_ITEMS = "size[10,7]"..
|
||||
"background[-0.22,-0.25;10.8,7.7;mcl_creative_inventory_bg.png]"..
|
||||
"button[8,0;1.5,1;creative_search;Search]"..
|
||||
"list[current_player;main;0.21,6.05;9,1;]"..
|
||||
"list[detached:creative;main;0.21,2.78;9,3;"..tostring(start_i).."]"..
|
||||
"label[7.25,1.7;"..tostring(pagenum).."/"..tostring(pagemax).."]"..
|
||||
"button[5.5,1.5;1.5,1;creative_prev;<<]"..
|
||||
"button[8,1.5;1.5,1;creative_next;>>]"..
|
||||
"button[5.5,0;1.5,1;creative_survival;Survival]"..
|
||||
"list[detached:creative_trash;main;9.28,6.05;1,1;]"
|
||||
player:set_inventory_formspec(CREATIVE_SEARCH_ITEMS)
|
||||
inventory.hotbar(player)
|
||||
end
|
||||
if playerdata[player:get_player_name()]['gamemode'] == "Survival" then
|
||||
inventory.survival_inv(player)
|
||||
inventory.hotbar(player)
|
||||
end
|
||||
end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if playerdata[player:get_player_name()]['gamemode'] == "Survival" then
|
||||
return
|
||||
end
|
||||
-- Figure out current page from formspec
|
||||
local current_page = 0
|
||||
local formspec = player:get_inventory_formspec()
|
||||
local start_i = string.match(formspec, "list%[detached:creative;main;[%d.]+,[%d.]+;[%d.]+,[%d.]+;(%d+)%]")
|
||||
start_i = tonumber(start_i) or 0
|
||||
|
||||
if fields.clear_inventory then
|
||||
local inventory = {}
|
||||
player:get_inventory():set_list("main", inventory)
|
||||
end
|
||||
|
||||
if fields.creative_search then
|
||||
creative_type = "search"
|
||||
end
|
||||
|
||||
if fields.creative_survival then
|
||||
creative_type = "default"
|
||||
inventory.creative_inv(player)
|
||||
end
|
||||
|
||||
if fields.creative_prev then
|
||||
start_i = start_i - 9*3
|
||||
end
|
||||
if fields.creative_next then
|
||||
start_i = start_i + 9*3
|
||||
end
|
||||
|
||||
if start_i < 0 then
|
||||
start_i = start_i + 9*3
|
||||
end
|
||||
if start_i >= inventory.inventory_size then
|
||||
start_i = start_i - 9*3
|
||||
end
|
||||
|
||||
if start_i < 0 or start_i >= inventory.inventory_size then
|
||||
start_i = 0
|
||||
end
|
||||
|
||||
inventory.set_player_formspec(player, start_i, start_i / (9*3) + 1)
|
||||
end)
|
||||
|
||||
local gm_priv = false
|
||||
|
||||
if minetest.setting_getbool("creative_mode")==false then
|
||||
gm_priv = true
|
||||
elseif minetest.setting_getbool("creative_mode")==true then
|
||||
gm_priv = false
|
||||
end
|
||||
|
||||
minetest.register_chatcommand('gamemode',{
|
||||
params = "1, c | 0, s",
|
||||
description = 'Switch your gamemode',
|
||||
privs = {gamemode = gm_priv},
|
||||
func = function(name, param)
|
||||
if param == "1" or param == "c" then
|
||||
playerdata[name]['gamemode'] = "Creative"
|
||||
save_player_data()
|
||||
minetest.chat_send_player(name, 'Your gamemode is now: '..playerdata[name]['gamemode'])
|
||||
updategamemode(name)
|
||||
elseif param == "0" or param == "s" then
|
||||
playerdata[name]['gamemode'] = "Survival"
|
||||
save_player_data()
|
||||
minetest.chat_send_player(name, 'Your gamemode is now: '..playerdata[name]['gamemode'])
|
||||
updategamemode(name)
|
||||
else
|
||||
minetest.chat_send_player(name, "Error: That player does not exist!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
--[[minetest.register_on_punchnode(function(pos, node, puncher)
|
||||
local pos = pos
|
||||
local pname = puncher:get_player_name()
|
||||
if playerdata[pname]['gamemode'] == "Creative" then
|
||||
minetest.after(0.1, function()
|
||||
minetest.env:remove_node(pos)
|
||||
end)
|
||||
end
|
||||
end)]]
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
local pname = placer:get_player_name()
|
||||
if playerdata[pname]['gamemode'] == "Creative" then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_privilege("gamemode", "Permission to use /gamemode.")
|
||||
local time_to_load= os.clock() - init
|
||||
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))
|
||||
|
|
@ -1 +0,0 @@
|
|||
name = mcl_inventory
|
Before Width: | Height: | Size: 147 B |
Before Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 147 B |
Before Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 613 B |
Before Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 823 B |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 859 B |
Before Width: | Height: | Size: 748 B |
Before Width: | Height: | Size: 1.7 KiB |