mirror of
				https://codeberg.org/tenplus1/mobs_redo.git
				synced 2025-11-04 09:15:32 +01:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			34b06df758
			...
			c06d071220
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					c06d071220 | ||
| 
						 | 
					ccbfe93f12 | ||
| 
						 | 
					6750d176ee | ||
| 
						 | 
					246b2769f7 | 
							
								
								
									
										140
									
								
								api.lua
									
									
									
									
									
								
							
							
						
						
									
										140
									
								
								api.lua
									
									
									
									
									
								
							@@ -8,12 +8,12 @@ local use_cmi = minetest.global_exists("cmi")
 | 
			
		||||
 | 
			
		||||
mobs = {
 | 
			
		||||
	mod = "redo",
 | 
			
		||||
	version = "20210323",
 | 
			
		||||
	version = "20210407",
 | 
			
		||||
	intllib = S,
 | 
			
		||||
	invis = minetest.global_exists("invisibility") and invisibility or {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- localize math functions
 | 
			
		||||
-- localize common functions
 | 
			
		||||
local pi = math.pi
 | 
			
		||||
local square = math.sqrt
 | 
			
		||||
local sin = math.sin
 | 
			
		||||
@@ -112,7 +112,8 @@ local mob_class = {
 | 
			
		||||
	light_damage_min = 14,
 | 
			
		||||
	light_damage_max = 15,
 | 
			
		||||
	water_damage = 0,
 | 
			
		||||
	lava_damage = 0,
 | 
			
		||||
	lava_damage = 4,
 | 
			
		||||
	fire_damage = 4,
 | 
			
		||||
	air_damage = 0,
 | 
			
		||||
	suffocation = 2,
 | 
			
		||||
	fall_damage = 1,
 | 
			
		||||
@@ -164,6 +165,7 @@ local mob_class = {
 | 
			
		||||
 | 
			
		||||
local mob_class_meta = {__index = mob_class}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- play sound
 | 
			
		||||
function mob_class:mob_sound(sound)
 | 
			
		||||
 | 
			
		||||
@@ -982,7 +984,12 @@ local is_node_dangerous = function(self, nodename)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if self.lava_damage > 0
 | 
			
		||||
	and minetest.get_item_group(nodename, "igniter") ~= 0 then
 | 
			
		||||
	and minetest.get_item_group(nodename, "lava") ~= 0 then
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if self.fire_damage > 0
 | 
			
		||||
	and minetest.get_item_group(nodename, "fire") ~= 0 then
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
@@ -1068,37 +1075,47 @@ function mob_class:do_env_damage()
 | 
			
		||||
	local nodef = minetest.registered_nodes[self.standing_in]
 | 
			
		||||
 | 
			
		||||
	-- water
 | 
			
		||||
	if self.water_damage and nodef.groups.water then
 | 
			
		||||
	if self.water_damage ~= 0
 | 
			
		||||
	and nodef.groups.water then
 | 
			
		||||
 | 
			
		||||
		if self.water_damage ~= 0 then
 | 
			
		||||
		self.health = self.health - self.water_damage
 | 
			
		||||
 | 
			
		||||
			self.health = self.health - self.water_damage
 | 
			
		||||
		effect(pos, 5, "bubble.png", nil, nil, 1, nil)
 | 
			
		||||
 | 
			
		||||
			effect(pos, 5, "bubble.png", nil, nil, 1, nil)
 | 
			
		||||
 | 
			
		||||
			if self:check_for_death({type = "environment",
 | 
			
		||||
					pos = pos, node = self.standing_in}) then
 | 
			
		||||
				return true
 | 
			
		||||
			end
 | 
			
		||||
		if self:check_for_death({type = "environment",
 | 
			
		||||
				pos = pos, node = self.standing_in}) then
 | 
			
		||||
			return true
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	-- ignition source (fire or lava)
 | 
			
		||||
	elseif self.lava_damage and nodef.groups.igniter then
 | 
			
		||||
	-- lava damage
 | 
			
		||||
	elseif self.lava_damage ~= 0
 | 
			
		||||
	and nodef.groups.lava  then
 | 
			
		||||
 | 
			
		||||
		if self.lava_damage ~= 0 then
 | 
			
		||||
		self.health = self.health - self.lava_damage
 | 
			
		||||
 | 
			
		||||
			self.health = self.health - self.lava_damage
 | 
			
		||||
		effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true)
 | 
			
		||||
 | 
			
		||||
			effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true)
 | 
			
		||||
 | 
			
		||||
			if self:check_for_death({type = "environment", pos = pos,
 | 
			
		||||
					node = self.standing_in, hot = true}) then
 | 
			
		||||
				return true
 | 
			
		||||
			end
 | 
			
		||||
		if self:check_for_death({type = "environment", pos = pos,
 | 
			
		||||
				node = self.standing_in, hot = true}) then
 | 
			
		||||
			return true
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	-- damage_per_second node check
 | 
			
		||||
	elseif nodef.damage_per_second ~= 0 then
 | 
			
		||||
	-- fire damage
 | 
			
		||||
	elseif self.fire_damage ~= 0
 | 
			
		||||
	and nodef.groups.fire then
 | 
			
		||||
 | 
			
		||||
		self.health = self.health - self.fire_damage
 | 
			
		||||
 | 
			
		||||
		effect(pos, 15, "fire_basic_flame.png", 1, 5, 1, 0.2, 15, true)
 | 
			
		||||
 | 
			
		||||
		if self:check_for_death({type = "environment", pos = pos,
 | 
			
		||||
				node = self.standing_in, hot = true}) then
 | 
			
		||||
			return true
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
	-- damage_per_second node check (not fire and lava)
 | 
			
		||||
	elseif nodef.damage_per_second ~= 0
 | 
			
		||||
	and nodef.groups.lava == 0 and nodef.groups.fire == 0 then
 | 
			
		||||
 | 
			
		||||
		self.health = self.health - nodef.damage_per_second
 | 
			
		||||
 | 
			
		||||
@@ -2772,15 +2789,37 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- is mob protected?
 | 
			
		||||
	if self.protected and hitter:is_player()
 | 
			
		||||
	and minetest.is_protected(self.object:get_pos(),
 | 
			
		||||
			hitter:get_player_name()) then
 | 
			
		||||
	-- is mob protected
 | 
			
		||||
	if self.protected then
 | 
			
		||||
 | 
			
		||||
		minetest.chat_send_player(hitter:get_player_name(),
 | 
			
		||||
				S("Mob has been protected!"))
 | 
			
		||||
		-- did player hit mob and if so is it in protected area
 | 
			
		||||
		if hitter:is_player() then
 | 
			
		||||
 | 
			
		||||
		return true
 | 
			
		||||
			local player_name = hitter:get_player_name()
 | 
			
		||||
 | 
			
		||||
			if player_name ~= self.owner
 | 
			
		||||
			and minetest.is_protected(self.object:get_pos(), player_name) then
 | 
			
		||||
 | 
			
		||||
				minetest.chat_send_player(hitter:get_player_name(),
 | 
			
		||||
						S("Mob has been protected!"))
 | 
			
		||||
 | 
			
		||||
				return true
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
		-- if protection is on level 2 then dont let arrows harm mobs
 | 
			
		||||
		elseif self.protected == 2 then
 | 
			
		||||
 | 
			
		||||
			local ent = hitter and hitter:get_luaentity()
 | 
			
		||||
 | 
			
		||||
			if ent and ent._is_arrow then
 | 
			
		||||
 | 
			
		||||
				return true -- arrow entity
 | 
			
		||||
 | 
			
		||||
			elseif not ent then
 | 
			
		||||
 | 
			
		||||
				return true -- non entity
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local weapon = hitter:get_wielded_item()
 | 
			
		||||
@@ -2812,7 +2851,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			damage = damage + (tool_capabilities.damage_groups[group] or 0)
 | 
			
		||||
				* tmp * ((armor[group] or 0) / 100.0)
 | 
			
		||||
					* tmp * ((armor[group] or 0) / 100.0)
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
@@ -3149,8 +3188,7 @@ function mob_class:mob_activate(staticdata, def, dtime)
 | 
			
		||||
			def.textures = {def.textures}
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		self.base_texture = def.textures and
 | 
			
		||||
				def.textures[random(#def.textures)]
 | 
			
		||||
		self.base_texture = def.textures and def.textures[random(#def.textures)]
 | 
			
		||||
		self.base_mesh = def.mesh
 | 
			
		||||
		self.base_size = self.visual_size
 | 
			
		||||
		self.base_colbox = self.collisionbox
 | 
			
		||||
@@ -3557,6 +3595,7 @@ minetest.register_entity(name, setmetatable({
 | 
			
		||||
	light_damage_max = def.light_damage_max,
 | 
			
		||||
	water_damage = def.water_damage,
 | 
			
		||||
	lava_damage = def.lava_damage,
 | 
			
		||||
	fire_damage = def.fire_damage,
 | 
			
		||||
	air_damage = def.air_damage,
 | 
			
		||||
	suffocation = def.suffocation,
 | 
			
		||||
	fall_damage = def.fall_damage,
 | 
			
		||||
@@ -4460,8 +4499,9 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net,
 | 
			
		||||
		return false
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	-- cannot pick up if not owner
 | 
			
		||||
	if self.owner ~= name and force_take == false then
 | 
			
		||||
	-- cannot pick up if not owner (unless player has protection_bypass priv)
 | 
			
		||||
	if not minetest.check_player_privs(name, "protection_bypass")
 | 
			
		||||
	and self.owner ~= name and force_take == false then
 | 
			
		||||
 | 
			
		||||
		minetest.chat_send_player(name, S("@1 is owner!", self.owner))
 | 
			
		||||
 | 
			
		||||
@@ -4562,19 +4602,21 @@ function mobs:protect(self, clicker)
 | 
			
		||||
 | 
			
		||||
	local name = clicker:get_player_name()
 | 
			
		||||
	local tool = clicker:get_wielded_item()
 | 
			
		||||
	local tool_name = tool:get_name()
 | 
			
		||||
 | 
			
		||||
	if tool:get_name() ~= "mobs:protector" then
 | 
			
		||||
	if tool_name ~= "mobs:protector"
 | 
			
		||||
	and tool_name ~= "mobs:protector2" then
 | 
			
		||||
		return false
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if self.tamed == false then
 | 
			
		||||
	if not self.tamed then
 | 
			
		||||
		minetest.chat_send_player(name, S("Not tamed!"))
 | 
			
		||||
		return true -- false
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if self.protected == true then
 | 
			
		||||
	if self.protected then
 | 
			
		||||
		minetest.chat_send_player(name, S("Already protected!"))
 | 
			
		||||
		return true -- false
 | 
			
		||||
		return true
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if not mobs.is_creative(clicker:get_player_name()) then
 | 
			
		||||
@@ -4582,9 +4624,15 @@ function mobs:protect(self, clicker)
 | 
			
		||||
		clicker:set_wielded_item(tool)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	self.protected = true
 | 
			
		||||
	-- set protection level
 | 
			
		||||
	if tool_name == "mobs:protector" then
 | 
			
		||||
		self.protected = true
 | 
			
		||||
	else
 | 
			
		||||
		self.protected = 2 ; self.fire_damage = 0
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local pos = self.object:get_pos()
 | 
			
		||||
 | 
			
		||||
	pos.y = pos.y + self.collisionbox[2] + 0.5
 | 
			
		||||
 | 
			
		||||
	effect(self.object:get_pos(), 25, "mobs_protect_particle.png",
 | 
			
		||||
@@ -4682,12 +4730,12 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	local item = clicker:get_wielded_item()
 | 
			
		||||
	local name = clicker:get_player_name()
 | 
			
		||||
 | 
			
		||||
	-- if mob has been tamed you can name it with a nametag
 | 
			
		||||
	if item:get_name() == "mobs:nametag"
 | 
			
		||||
	and clicker:get_player_name() == self.owner then
 | 
			
		||||
 | 
			
		||||
		local name = clicker:get_player_name()
 | 
			
		||||
	and (name == self.owner
 | 
			
		||||
	or minetest.check_player_privs(name, "protection_bypass")) then
 | 
			
		||||
 | 
			
		||||
		-- store mob and nametag stack in external variables
 | 
			
		||||
		mob_obj[name] = self
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								api.txt
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								api.txt
									
									
									
									
									
								
							@@ -66,7 +66,10 @@ functions needed for the mob to work properly which contains the following:
 | 
			
		||||
                   water.
 | 
			
		||||
   'air_damage'    holds damage per second inflicted to mob when standing in air.
 | 
			
		||||
   'lava_damage'   holds the damage per second inflicted to mobs when standing
 | 
			
		||||
                   in lava or fire or an ignition source.
 | 
			
		||||
                   in lava.
 | 
			
		||||
   'fire_damage'   holds the damage per second inflicted to mobs when standing
 | 
			
		||||
                   in fire.
 | 
			
		||||
 | 
			
		||||
   'light_damage'  holds the damage per second inflicted to mobs when light
 | 
			
		||||
                   level is between the min and max values below
 | 
			
		||||
   'light_damage_min' minimum light value when mob is affected (default: 14)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								crafts.lua
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								crafts.lua
									
									
									
									
									
								
							@@ -115,6 +115,22 @@ minetest.register_craft({
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- level 2 protection rune
 | 
			
		||||
minetest.register_craftitem("mobs:protector2", {
 | 
			
		||||
	description = S("Mob Protection Rune (Level 2)"),
 | 
			
		||||
	inventory_image = "mobs_protector2.png",
 | 
			
		||||
	groups = {flammable = 2}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
minetest.register_craft({
 | 
			
		||||
	output = "mobs:protector2",
 | 
			
		||||
	recipe = {
 | 
			
		||||
		{"mobs:protector", "default:mese_crystal", "mobs:protector"},
 | 
			
		||||
		{"default:mese_crystal", "default:diamondblock", "default:mese_crystal"},
 | 
			
		||||
		{"mobs:protector", "default:mese_crystal", "mobs:protector"}
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- saddle
 | 
			
		||||
minetest.register_craftitem("mobs:saddle", {
 | 
			
		||||
	description = S("Saddle"),
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								textures/mobs_protector2.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								textures/mobs_protector2.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 164 B  | 
		Reference in New Issue
	
	Block a user