mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-25 02:00:21 +01:00
sneak and punch mob with mob reset stick to add custom texture
This commit is contained in:
parent
a1d4e9bbfc
commit
26a520e214
60
crafts.lua
60
crafts.lua
@ -223,6 +223,8 @@ minetest.register_craft({
|
|||||||
-- this tool spawns same mob and adds owner, protected, nametag info
|
-- this tool spawns same mob and adds owner, protected, nametag info
|
||||||
-- then removes original entity, this is used for fixing any issues.
|
-- then removes original entity, this is used for fixing any issues.
|
||||||
|
|
||||||
|
local tex_obj
|
||||||
|
|
||||||
minetest.register_tool(":mobs:mob_reset_stick", {
|
minetest.register_tool(":mobs:mob_reset_stick", {
|
||||||
description = "Mob Reset Stick",
|
description = "Mob Reset Stick",
|
||||||
inventory_image = "default_stick.png^[colorize:#ff000050",
|
inventory_image = "default_stick.png^[colorize:#ff000050",
|
||||||
@ -231,15 +233,16 @@ minetest.register_tool(":mobs:mob_reset_stick", {
|
|||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local privs = minetest.get_player_privs(user:get_player_name())
|
|
||||||
|
|
||||||
if pointed_thing.type ~= "object" then
|
if pointed_thing.type ~= "object" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local obj = pointed_thing.ref
|
local obj = pointed_thing.ref
|
||||||
|
|
||||||
if obj then
|
local control = user:get_player_control()
|
||||||
|
local sneak = control and control.sneak
|
||||||
|
|
||||||
|
if obj and not sneak then
|
||||||
|
|
||||||
local self = obj:get_luaentity()
|
local self = obj:get_luaentity()
|
||||||
local obj2 = minetest.add_entity(obj:get_pos(), self.name)
|
local obj2 = minetest.add_entity(obj:get_pos(), self.name)
|
||||||
@ -254,6 +257,7 @@ minetest.register_tool(":mobs:mob_reset_stick", {
|
|||||||
ent2.gotten = self.gotten
|
ent2.gotten = self.gotten
|
||||||
ent2.tamed = self.tamed
|
ent2.tamed = self.tamed
|
||||||
ent2.health = self.health
|
ent2.health = self.health
|
||||||
|
ent2.order = self.order
|
||||||
|
|
||||||
if self.child then
|
if self.child then
|
||||||
obj2:set_velocity({x = 0, y = self.jump_height, z = 0})
|
obj2:set_velocity({x = 0, y = self.jump_height, z = 0})
|
||||||
@ -264,6 +268,56 @@ minetest.register_tool(":mobs:mob_reset_stick", {
|
|||||||
obj:remove()
|
obj:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if obj and sneak then
|
||||||
|
|
||||||
|
tex_obj = obj
|
||||||
|
|
||||||
|
local name = user:get_player_name()
|
||||||
|
local tex = ""
|
||||||
|
|
||||||
|
minetest.show_formspec(name, "mobs_texture", "size[8,4]"
|
||||||
|
.. "field[0.5,1;7.5,0;name;"
|
||||||
|
.. minetest.formspec_escape(S("Enter texture:")) .. ";" .. tex .. "]"
|
||||||
|
.. "button_exit[2.5,3.5;3,1;mob_texture_change;"
|
||||||
|
.. minetest.formspec_escape(S("Change")) .. "]")
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
|
||||||
|
-- right-clicked with nametag and name entered?
|
||||||
|
if formname == "mobs_texture"
|
||||||
|
and fields.name
|
||||||
|
and fields.name ~= "" then
|
||||||
|
|
||||||
|
local name = player:get_player_name()
|
||||||
|
|
||||||
|
if not tex_obj then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- make sure nametag is being used to name mob
|
||||||
|
local item = player:get_wielded_item()
|
||||||
|
|
||||||
|
if item:get_name() ~= "mobs:mob_reset_stick" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- limit name entered to 64 characters long
|
||||||
|
if string.len(fields.name) > 64 then
|
||||||
|
fields.name = string.sub(fields.name, 1, 64)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- update texture
|
||||||
|
local self = tex_obj:get_luaentity()
|
||||||
|
|
||||||
|
self.base_texture = {fields.name}
|
||||||
|
|
||||||
|
tex_obj:set_properties({textures = {fields.name}})
|
||||||
|
|
||||||
|
-- reset external variable
|
||||||
|
tex_obj = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user