Compare commits

..

5 Commits

Author SHA1 Message Date
loveaabb 195b193260 remove trailing whitespace 2024-05-24 01:39:11 +00:00
loveaabb 83a651d375 change a misset global variable to local 2024-05-18 15:25:03 +00:00
loveaabb 19190d92e7 revert f50ef6b52a
revert 更新 mods/ITEMS/mcl_shields/init.lua

change commit info
2024-05-18 15:21:38 +00:00
loveaabb f50ef6b52a 更新 mods/ITEMS/mcl_shields/init.lua 2024-05-18 15:15:42 +00:00
loveaabb 50fda3e844 Several improvements to the Shield
changes:
1. removed the limitation to block while pointing a node wielding an item
2. check whether the player is pointing to a node defined with right-click Formspec (to avoid the formspec bug while blocking) and whether the player is wielding a node (to avoid continous node placing not functioning) before blocking
3. decreased the interval between right click and block
2024-05-16 15:33:32 +00:00
15 changed files with 231 additions and 112 deletions

View File

@ -314,7 +314,6 @@ function mcl_mobs.register_mob(name, def)
return self:mob_activate(staticdata, def, dtime)
end,
after_activate = def.after_activate,
attack_state = def.attack_state, -- custom attack state
on_attack = def.on_attack, -- called after attack, useful with otherwise predefined attack states (not custom)
harmed_by_heal = def.harmed_by_heal,

View File

@ -31,9 +31,20 @@ local place_frequency_min = 235
local place_frequency_max = 245
minetest.register_entity("mobs_mc:ender_eyes", {
visual = "mesh",
mesh = "mobs_mc_spider.b3d",
visual_size = {x=1.01/3, y=1.01/3},
textures = {
"mobs_mc_enderman_eyes.png",
},
on_step = function(self)
self.object:remove()
if self and self.object then
if not self.object:get_attach() then
self.object:remove()
end
end
end,
glow = 50,
})
local S = minetest.get_translator("mobs_mc")
@ -55,8 +66,142 @@ end
local pr = PseudoRandom(os.time()*(-334))
-- Texuture overrides for enderman block. Required for cactus because it's original is a nodebox
-- and the textures have tranparent pixels.
local block_texture_overrides
do
local cbackground = "mobs_mc_enderman_cactus_background.png"
local ctiles = minetest.registered_nodes["mcl_core:cactus"].tiles
local ctable = {}
local last
for i=1, 6 do
if ctiles[i] then
last = ctiles[i]
end
table.insert(ctable, cbackground .. "^" .. last)
end
block_texture_overrides = {
["mcl_core:cactus"] = ctable,
-- FIXME: replace colorize colors with colors from palette
["mcl_core:dirt_with_grass"] =
{
"mcl_core_grass_block_top.png^[colorize:green:90",
"default_dirt.png",
"default_dirt.png^(mcl_core_grass_block_side_overlay.png^[colorize:green:90)",
"default_dirt.png^(mcl_core_grass_block_side_overlay.png^[colorize:green:90)",
"default_dirt.png^(mcl_core_grass_block_side_overlay.png^[colorize:green:90)",
"default_dirt.png^(mcl_core_grass_block_side_overlay.png^[colorize:green:90)"}
}
end
-- Create the textures table for the enderman, depending on which kind of block
-- the enderman holds (if any).
local create_enderman_textures = function(block_type, itemstring)
local base = "mobs_mc_enderman.png^mobs_mc_enderman_eyes.png"
--[[ Order of the textures in the texture table:
Flower, 90 degrees
Flower, 45 degrees
Held block, backside
Held block, bottom
Held block, front
Held block, left
Held block, right
Held block, top
Enderman texture (base)
]]
-- Regular cube
if block_type == "cube" then
local tiles = minetest.registered_nodes[itemstring].tiles
local textures = {}
local last
if block_texture_overrides[itemstring] then
-- Texture override available? Use these instead!
textures = block_texture_overrides[itemstring]
else
-- Extract the texture names
for i = 1, 6 do
if type(tiles[i]) == "string" then
last = tiles[i]
elseif type(tiles[i]) == "table" then
if tiles[i].name then
last = tiles[i].name
end
end
table.insert(textures, last)
end
end
return {
"blank.png",
"blank.png",
textures[5],
textures[2],
textures[6],
textures[3],
textures[4],
textures[1],
base, -- Enderman texture
}
-- Node of plantlike drawtype, 45° (recommended)
elseif block_type == "plantlike45" then
local textures = minetest.registered_nodes[itemstring].tiles
return {
"blank.png",
textures[1],
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
base,
}
-- Node of plantlike drawtype, 90°
elseif block_type == "plantlike90" then
local textures = minetest.registered_nodes[itemstring].tiles
return {
textures[1],
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
base,
}
elseif block_type == "unknown" then
return {
"blank.png",
"blank.png",
"unknown_node.png",
"unknown_node.png",
"unknown_node.png",
"unknown_node.png",
"unknown_node.png",
"unknown_node.png",
base, -- Enderman texture
}
-- No block held (for initial texture)
elseif block_type == "nothing" or block_type == nil then
return {
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
base, -- Enderman texture
}
end
end
-- Select a new animation definition.
local select_rover_animation = function(animation_type)
local select_enderman_animation = function(animation_type)
-- Enderman holds a block
if animation_type == "block" then
return {
@ -109,8 +254,8 @@ local psdefs = {{
texture = "mcl_portals_particle"..math.random(1, 5)..".png",
}}
mcl_mobs.register_mob("mobs_mc:rover", {
description = S("Rover"),
mcl_mobs.register_mob("mobs_mc:enderman", {
description = S("Enderman"),
type = "monster",
spawn_class = "passive",
can_despawn = true,
@ -122,11 +267,23 @@ mcl_mobs.register_mob("mobs_mc:rover", {
xp_max = 5,
collisionbox = {-0.3, -0.01, -0.3, 0.3, 2.89, 0.3},
visual = "mesh",
mesh = "vl_rover.b3d",
textures = { "vl_mobs_rover.png^vl_mobs_rover_face.png" },
glow = 100,
visual_size = {x=10, y=10},
mesh = "mobs_mc_enderman.b3d",
textures = create_enderman_textures(),
visual_size = {x=3, y=3},
makes_footstep_sound = true,
on_spawn = function(self)
local spider_eyes=false
for n = 1, #self.object:get_children() do
local obj = self.object:get_children()[n]
if obj:get_luaentity() and self.object:get_luaentity().name == "mobs_mc:ender_eyes" then
spider_eyes = true
end
end
if not spider_eyes then
minetest.add_entity(self.object:get_pos(), "mobs_mc:ender_eyes"):set_attach(self.object, "head.top", vector.new(0,2.54,-1.99), vector.new(90,0,180))
minetest.add_entity(self.object:get_pos(), "mobs_mc:ender_eyes"):set_attach(self.object, "head.top", vector.new(1,2.54,-1.99), vector.new(90,0,180))
end
end,
sounds = {
-- TODO: Custom war cry sound
war_cry = "mobs_sandmonster",
@ -135,8 +292,8 @@ mcl_mobs.register_mob("mobs_mc:rover", {
random = {name="mobs_mc_enderman_random", gain=0.5},
distance = 16,
},
walk_velocity = 2,
run_velocity = 4,
walk_velocity = 0.2,
run_velocity = 3.4,
damage = 7,
reach = 2,
particlespawners = psdefs,
@ -147,7 +304,7 @@ mcl_mobs.register_mob("mobs_mc:rover", {
max = 1,
looting = "common"},
},
animation = select_rover_animation("normal"),
animation = select_enderman_animation("normal"),
_taken_node = "",
can_spawn = function(pos)
return #minetest.find_nodes_in_area(vector.offset(pos,0,1,0),vector.offset(pos,0,3,0),{"air"}) > 2
@ -191,7 +348,6 @@ mcl_mobs.register_mob("mobs_mc:rover", {
-- AGRESSIVELY WARP/CHASE PLAYER BEHAVIOUR HERE.
if self.state == "attack" then
self.object:set_properties({textures={"vl_mobs_rover.png^vl_mobs_rover_face_angry.png"}})
if self.attack then
local target = self.attack
local pos = target:get_pos()
@ -202,7 +358,6 @@ mcl_mobs.register_mob("mobs_mc:rover", {
end
end
else --if not attacking try to tp to the dark
self.object:set_properties({textures={"vl_mobs_rover.png^vl_mobs_rover_face.png"}})
if dim == 'overworld' then
local light = minetest.get_node_light(enderpos)
if light and light > minetest.LIGHT_MAX then
@ -334,17 +489,38 @@ mcl_mobs.register_mob("mobs_mc:rover", {
minetest.remove_node(take_pos)
local dug = minetest.get_node_or_nil(take_pos)
if dug and dug.name == "air" then
local node_obj = vl_held_item.create_item_entity(take_pos, node.name)
if node_obj then
node_obj:set_attach(self.object, "held_node")
self._node_obj = node_obj
self._taken_node = node.name
node_obj:set_properties({visual_size={x=0.02, y=0.02}})
end
self._taken_node = node.name
self.persistent = true
local def = minetest.registered_nodes[self._taken_node]
self.animation = select_rover_animation("block")
-- Update animation and texture accordingly (adds visibly carried block)
local block_type
-- Cube-shaped
if def.drawtype == "normal" or
def.drawtype == "nodebox" or
def.drawtype == "liquid" or
def.drawtype == "flowingliquid" or
def.drawtype == "glasslike" or
def.drawtype == "glasslike_framed" or
def.drawtype == "glasslike_framed_optional" or
def.drawtype == "allfaces" or
def.drawtype == "allfaces_optional" or
def.drawtype == nil then
block_type = "cube"
elseif def.drawtype == "plantlike" then
-- Flowers and stuff
block_type = "plantlike45"
elseif def.drawtype == "airlike" then
-- Just air
block_type = nil
else
-- Fallback for complex drawtypes
block_type = "unknown"
end
self.base_texture = create_enderman_textures(block_type, self._taken_node)
self.object:set_properties({ textures = self.base_texture })
self.animation = select_enderman_animation("block")
self:set_animation(self.animation.current)
if def and def.sounds and def.sounds.dug then
if def.sounds and def.sounds.dug then
minetest.sound_play(def.sounds.dug, {pos = take_pos, max_hear_distance = 16}, true)
end
end
@ -366,14 +542,12 @@ mcl_mobs.register_mob("mobs_mc:rover", {
local def = minetest.registered_nodes[self._taken_node]
-- Update animation accordingly (removes visible block)
self.persistent = false
self.animation = select_rover_animation("normal")
self.animation = select_enderman_animation("normal")
self:set_animation(self.animation.current)
if def and def.sounds and def.sounds.place then
if def.sounds and def.sounds.place then
minetest.sound_play(def.sounds.place, {pos = place_pos, max_hear_distance = 16}, true)
end
self._node_obj:remove()
self._node_obj = nil
self._taken_node = nil
self._taken_node = ""
end
end
end
@ -471,21 +645,6 @@ mcl_mobs.register_mob("mobs_mc:rover", {
--end
end
end,
after_activate = function(self, staticdata, def, dtime)
if not self._taken_node or self._taken_node == "" then
self.animation = select_rover_animation("normal")
self:set_animation(self.animation.current)
return
end
self.animation = select_rover_animation("block")
self:set_animation(self.animation.current)
local node_obj = vl_held_item.create_item_entity(self.object:get_pos(), self._taken_node)
if node_obj then
node_obj:set_attach(self.object, "held_node")
self._node_obj = node_obj
node_obj:set_properties({visual_size={x=0.02, y=0.02}})
end
end,
armor = { fleshy = 100, water_vulnerable = 100 },
water_damage = 8,
view_range = 64,
@ -493,17 +652,9 @@ mcl_mobs.register_mob("mobs_mc:rover", {
attack_type = "dogfight",
})
-- compat
minetest.register_entity("mobs_mc:enderman", {
on_activate = function(self, staticdata, dtime)
minetest.add_entity(self.object:get_pos(), "mobs_mc:rover", staticdata)
self.object:remove()
end,
})
-- End spawn
mcl_mobs:spawn_specific(
"mobs_mc:rover",
"mobs_mc:enderman",
"end",
"ground",
{
@ -523,7 +674,7 @@ mcl_vars.mg_end_min,
mcl_vars.mg_end_max)
-- Overworld spawn
mcl_mobs:spawn_specific(
"mobs_mc:rover",
"mobs_mc:enderman",
"overworld",
"ground",
{
@ -672,7 +823,7 @@ mcl_vars.mg_overworld_max)
-- Nether spawn (rare)
mcl_mobs:spawn_specific(
"mobs_mc:rover",
"mobs_mc:enderman",
"nether",
"ground",
{
@ -689,7 +840,7 @@ mcl_vars.mg_nether_max)
-- Warped Forest spawn (common)
mcl_mobs:spawn_specific(
"mobs_mc:rover",
"mobs_mc:enderman",
"nether",
"ground",
{
@ -704,5 +855,4 @@ mcl_vars.mg_nether_min,
mcl_vars.mg_nether_max)
-- spawn eggs
mcl_mobs.register_egg("mobs_mc:rover", S("Rover"), "#252525", "#151515", 0)
minetest.register_alias("mobs_mc:enderman", "mobs_mc:rover")
mcl_mobs.register_egg("mobs_mc:enderman", S("Enderman"), "#252525", "#151515", 0)

View File

@ -1,40 +0,0 @@
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
vl_held_item = {}
local mod = vl_held_item
local held_item_entity = {
initial_properties = {
hp_max = 1,
physical = true,
pointable = false,
collide_with_objects = true,
static_save = false, -- TODO remove/change later when needed to persist
-- WARNING persisting held items not recommended, mob can recreate it after_activate
collision_box = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 },
},
visual = "wielditem",
textures = { "mcl_core:dirt_with_grass" },
}
function held_item_entity:on_activate(staticdata, dtime_unloaded)
local staticdata = minetest.deserialize(staticdata)
self._staticdata = staticdata
local props = {
visual = "wielditem",
textures = { staticdata.itemname },
}
self.object:set_properties(props)
end
function held_item_entity:get_staticdata()
return minetest.serialize(self._staticdata)
end
minetest.register_entity("vl_held_item:held_item_entity", held_item_entity)
function mod.create_item_entity(pos, itemname)
local staticdata = {
itemname = itemname
}
return minetest.add_entity(pos, "vl_held_item:held_item_entity", minetest.serialize(staticdata))
end

View File

@ -1,4 +0,0 @@
name = vl_held_item
author = teknomunk, Herowl
description = An entity that represents an item held by a mob
depends = mcl_core

View File

@ -249,7 +249,7 @@ function ARROW_ENTITY.on_step(self, dtime)
end
-- Punch target object but avoid hurting enderman.
if not lua or lua.name ~= "mobs_mc:rover" then
if not lua or lua.name ~= "mobs_mc:enderman" then
if not self._in_player then
damage_particles(vector.add(pos, vector.multiply(self.object:get_velocity(), 0.1)), self._is_critical)
end

View File

@ -470,7 +470,7 @@ function ARROW_ENTITY.on_step(self, dtime)
end
-- Punch target object but avoid hurting enderman.
if not lua or lua.name ~= "mobs_mc:rover" then
if not lua or lua.name ~= "mobs_mc:enderman" then
if self._in_player == false then
damage_particles(self.object:get_pos(), self._is_critical)
end

View File

@ -119,7 +119,7 @@ pumpkin_face_base_def.groups.non_combat_armor=1
pumpkin_face_base_def.groups.armor_head=1
pumpkin_face_base_def.groups.non_combat_armor_head=1
pumpkin_face_base_def._mcl_armor_mob_range_factor = 0
pumpkin_face_base_def._mcl_armor_mob_range_mob = "mobs_mc:rover"
pumpkin_face_base_def._mcl_armor_mob_range_mob = "mobs_mc:enderman"
pumpkin_face_base_def._mcl_armor_element = "head"
pumpkin_face_base_def._mcl_armor_texture = "mcl_farming_pumpkin_face.png"

View File

@ -39,7 +39,7 @@ end
local doll_size_overrides = {
["mobs_mc:guardian"] = { x = 0.6, y = 0.6 },
["mobs_mc:guardian_elder"] = { x = 0.72, y = 0.72 },
["mobs_mc:rover"] = { x = 0.8, y = 0.8 },
["mobs_mc:enderman"] = { x = 0.8, y = 0.8 },
["mobs_mc:iron_golem"] = { x = 0.9, y = 0.9 },
["mobs_mc:ghast"] = { x = 1.05, y = 1.05 },
["mobs_mc:wither"] = { x = 1.2, y = 1.2 },

View File

@ -266,7 +266,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
-- Punch target object but avoid hurting enderman.
if lua then
if lua.name ~= "mobs_mc:rover" then
if lua.name ~= "mobs_mc:enderman" then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=self._damage},

View File

@ -251,6 +251,15 @@ local function remove_shield_entity(player, i)
end
end
local function is_node_stack(itemstack)
return itemstack:get_definition().drawtype -- only node's definition table contains element "drawtype"
end
local function is_rmb_conflicting_node(nodename)
local nodedef = minetest.registered_nodes[nodename]
return nodedef.on_rightclick
end
local function handle_blocking(player)
local player_shield = mcl_shields.players[player]
local rmb = player:get_player_control().RMB
@ -266,7 +275,7 @@ local function handle_blocking(player)
local pos = player:get_pos()
if shield_in_hand then
if not_blocking then
minetest.after(0.25, function()
minetest.after(0.05, function()
if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then
player_shield.blocking = 2
set_shield(player, true, 2)
@ -277,11 +286,16 @@ local function handle_blocking(player)
end
elseif shield_in_offhand then
local pointed_thing = mcl_util.get_pointed_thing(player, true)
local offhand_can_block = (wielded_item(player) == "" or not pointed_thing)
and (minetest.get_item_group(wielded_item(player), "bow") ~= 1 and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1)
local wielded_stack = player:get_wielded_item()
local offhand_can_block = (minetest.get_item_group(wielded_item(player), "bow") ~= 1
and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1)
if pointed_thing and pointed_thing.type == "node" then
if minetest.get_item_group(minetest.get_node(pointed_thing.under).name, "container") > 1 then
local pointed_node = minetest.get_node(pointed_thing.under)
if minetest.get_item_group(pointed_node.name, "container") > 1
or is_rmb_conflicting_node(pointed_node.name)
or is_node_stack(wielded_stack)
then
return
end
end
@ -290,7 +304,7 @@ local function handle_blocking(player)
return
end
if not_blocking then
minetest.after(0.25, function()
minetest.after(0.05, function()
if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then
player_shield.blocking = 1
set_shield(player, true, 1)

View File

@ -34,7 +34,7 @@ end, function(minp,maxp,blockseed)
table.shuffle(nn)
if nn and #nn > 0 then
for i=1,pr:next(1,math.min(5,#nn)) do
minetest.add_entity(vector.offset(nn[i],0,1,0),"mobs_mc:rover")
minetest.add_entity(vector.offset(nn[i],0,1,0),"mobs_mc:enderman")
end
end
end, 15, true)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 B