Merge pull request 'master' (#8) from MineClone2/MineClone2:master into master

Reviewed-on: NO11/MineClone2#8
This commit is contained in:
NO11 2021-09-19 09:15:43 +00:00
commit 4194a76db0
11 changed files with 195 additions and 64 deletions

View File

@ -67,14 +67,9 @@ function mcl_burning.set_on_fire(obj, burn_time)
end
if not storage.burn_time or burn_time >= storage.burn_time then
if obj:is_player() and not storage.fire_hud_id then
storage.fire_hud_id = obj:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
text = "mcl_burning_entity_flame_animated.png^[opacity:180^[verticalframe:" .. mcl_burning.animation_frames .. ":" .. 1,
z_index = 1000,
})
if obj:is_player() then
mcl_burning.channels[obj]:send_all(tostring(mcl_burning.animation_frames))
mcl_burning.channels[obj]:send_all("start")
end
storage.burn_time = burn_time
storage.fire_damage_timer = 0
@ -95,7 +90,6 @@ function mcl_burning.set_on_fire(obj, burn_time)
fire_entity:set_properties({visual_size = size})
fire_entity:set_attach(obj, "", offset, {x = 0, y = 0, z = 0})
local fire_luaentity = fire_entity:get_luaentity()
fire_luaentity:update_frame(obj, storage)
for _, other in pairs(minetest.get_objects_inside_radius(fire_entity:get_pos(), 0)) do
local other_luaentity = other:get_luaentity()
@ -111,9 +105,7 @@ function mcl_burning.extinguish(obj)
if mcl_burning.is_burning(obj) then
local storage = mcl_burning.get_storage(obj)
if obj:is_player() then
if storage.fire_hud_id then
obj:hud_remove(storage.fire_hud_id)
end
mcl_burning.channels[obj]:send_all("stop")
mcl_burning.storage[obj] = {}
else
storage.burn_time = nil

View File

@ -7,6 +7,7 @@ local get_item_group = minetest.get_item_group
mcl_burning = {
storage = {},
channels = {},
animation_frames = tonumber(minetest.settings:get("fire_animation_frames")) or 8
}
@ -54,12 +55,11 @@ minetest.register_on_joinplayer(function(player)
end
mcl_burning.storage[player] = storage
mcl_burning.channels[player] = minetest.mod_channel_join("mcl_burning:" .. player:get_player_name())
end)
minetest.register_on_leaveplayer(function(player)
local storage = mcl_burning.storage[player]
storage.fire_hud_id = nil
player:get_meta():set_string("mcl_burning:data", minetest.serialize(storage))
player:get_meta():set_string("mcl_burning:data", minetest.serialize(mcl_burning.storage[player]))
mcl_burning.storage[player] = nil
end)
@ -68,27 +68,28 @@ minetest.register_entity("mcl_burning:fire", {
initial_properties = {
physical = false,
collisionbox = {0, 0, 0, 0, 0, 0},
visual = "cube",
visual = "upright_sprite",
textures = {
name = "mcl_burning_entity_flame_animated.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0,
},
},
spritediv = {x = 1, y = mcl_burning.animation_frames},
pointable = false,
glow = -1,
backface_culling = false,
},
animation_frame = 0,
animation_timer = 0,
on_step = function(self, dtime)
local parent, storage = self:sanity_check()
if parent then
self.animation_timer = self.animation_timer + dtime
if self.animation_timer >= 0.1 then
self.animation_timer = 0
self.animation_frame = self.animation_frame + 1
if self.animation_frame > mcl_burning.animation_frames - 1 then
self.animation_frame = 0
end
self:update_frame(parent, storage)
end
else
on_activate = function(self)
self.object:set_sprite({x = 0, y = 0}, mcl_burning.animation_frames, 1.0 / mcl_burning.animation_frames)
end,
on_step = function(self)
if not self:sanity_check() then
self.object:remove()
end
end,
@ -96,23 +97,15 @@ minetest.register_entity("mcl_burning:fire", {
local parent = self.object:get_attach()
if not parent then
return
return false
end
local storage = mcl_burning.get_storage(parent)
if not storage or not storage.burn_time then
return
return false
end
return parent, storage
end,
update_frame = function(self, parent, storage)
local frame_overlay = "^[opacity:180^[verticalframe:" .. mcl_burning.animation_frames .. ":" .. self.animation_frame
local fire_texture = "mcl_burning_entity_flame_animated.png" .. frame_overlay
self.object:set_properties({textures = {"blank.png", "blank.png", fire_texture, fire_texture, fire_texture, fire_texture}})
if parent:is_player() then
parent:hud_change(storage.fire_hud_id, "text", "mcl_burning_hud_flame_animated.png" .. frame_overlay)
end
return true
end,
})

View File

@ -480,7 +480,7 @@ minetest.register_entity(":__builtin:item", {
end,
get_staticdata = function(self)
return minetest.serialize({
local data = minetest.serialize({
itemstring = self.itemstring,
always_collect = self.always_collect,
age = self.age,
@ -488,6 +488,39 @@ minetest.register_entity(":__builtin:item", {
_flowing = self._flowing,
_removed = self._removed,
})
-- sfan5 guessed that the biggest serializable item
-- entity would have a size of 65530 bytes. This has
-- been experimentally verified to be still too large.
--
-- anon5 has calculated that the biggest serializable
-- item entity has a size of exactly 65487 bytes:
--
-- 1. serializeString16 can handle max. 65535 bytes.
-- 2. The following engine metadata is always saved:
-- • 1 byte (version)
-- • 2 byte (length prefix)
-- • 14 byte “__builtin:item”
-- • 4 byte (length prefix)
-- • 2 byte (health)
-- • 3 × 4 byte = 12 byte (position)
-- • 4 byte (yaw)
-- • 1 byte (version 2)
-- • 2 × 4 byte = 8 byte (pitch and roll)
-- 3. This leaves 65487 bytes for the serialization.
if #data > 65487 then -- would crash the engine
local stack = ItemStack(self.itemstring)
stack:get_meta():from_table(nil)
self.itemstring = stack:to_string()
minetest.log(
"warning",
"Overlong item entity metadata removed: “" ..
self.itemstring ..
"” had serialized length of " ..
#data
)
return self:get_staticdata()
end
return data
end,
on_activate = function(self, staticdata, dtime_s)
@ -575,7 +608,7 @@ minetest.register_entity(":__builtin:item", {
return true
end,
on_step = function(self, dtime)
on_step = function(self, dtime, moveresult)
if self._removed then
self.object:set_properties({
physical = false
@ -642,6 +675,18 @@ minetest.register_entity(":__builtin:item", {
end
end
-- Destroy item when it collides with a cactus
if moveresult and moveresult.collides then
for _, collision in pairs(moveresult.collisions) do
local pos = collision.node_pos
if collision.type == "node" and minetest.get_node(pos).name == "mcl_core:cactus" then
self._removed = true
self.object:remove()
return
end
end
end
-- Push item out when stuck inside solid opaque node
if def and def.walkable and def.groups and def.groups.opaque == 1 then
local shootdir

View File

@ -233,4 +233,4 @@ mobs:spawn(spawn_grass)
mobs:register_egg("mobs_mc:rabbit", S("Rabbit"), "mobs_mc_spawn_icon_rabbit.png", 0)
-- Note: This spawn egg does not exist in Minecraft
mobs:register_egg("mobs_mc:killer_bunny", S("Killer Bunny"), "mobs_mc_spawn_icon_rabbit.png^[colorize:#FF0000:192", 0) -- TODO: Update inventory image
mobs:register_egg("mobs_mc:killer_bunny", S("Killer Bunny"), "mobs_mc_spawn_icon_rabbit_caerbannog.png", 0)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -425,6 +425,7 @@ function hb.hide_hudbar(player, identifier)
local name = player:get_player_name()
local hudtable = hb.get_hudtable(identifier)
if hudtable == nil then return false end
if hudtable.hudstate[name].hidden == true then return true end
if hb.settings.bar_type == "progress_bar" then
if hudtable.hudids[name].icon then
player:hud_change(hudtable.hudids[name].icon, "scale", {x=0,y=0})
@ -443,6 +444,7 @@ function hb.unhide_hudbar(player, identifier)
local name = player:get_player_name()
local hudtable = hb.get_hudtable(identifier)
if hudtable == nil then return false end
if hudtable.hudstate[name].hidden == false then return true end
local value = hudtable.hudstate[name].value
local max = hudtable.hudstate[name].max
if hb.settings.bar_type == "progress_bar" then

View File

@ -168,6 +168,60 @@ local dispenserdef = {
end
inv:set_stack("main", stack_id, stack)
-- Use shears on sheeps
elseif igroups.shears then
for _, obj in pairs(minetest.get_objects_inside_radius(droppos, 1)) do
local entity = obj:get_luaentity()
if entity and not entity.child and not entity.gotten then
local entname = entity.name
local pos = obj:get_pos()
local used, texture = false
if entname == "mobs_mc:sheep" then
minetest.add_item(pos, entity.drops[2].name .. " " .. math.random(1, 3))
if not entity.color then
entity.color = "unicolor_white"
end
entity.base_texture = { "blank.png", "mobs_mc_sheep.png" }
texture = entity.base_texture
entity.drops = {
{ name = mobs_mc.items.mutton_raw, chance = 1, min = 1, max = 2 },
}
used = true
elseif entname == "mobs_mc:snowman" then
texture = {
"mobs_mc_snowman.png",
"blank.png", "blank.png",
"blank.png", "blank.png",
"blank.png", "blank.png",
}
used = true
elseif entname == "mobs_mc:mooshroom" then
local droppos = vector.offset(pos, 0, 1.4, 0)
if entity.base_texture[1] == "mobs_mc_mooshroom_brown.png" then
minetest.add_item(droppos, mobs_mc.items.mushroom_brown .. " 5")
else
minetest.add_item(droppos, mobs_mc.items.mushroom_red .. " 5")
end
local oldyaw = obj:get_yaw()
obj:remove()
local cow = minetest.add_entity(pos, "mobs_mc:cow")
cow:set_yaw(oldyaw)
obj = cow
entity = cow:get_luaentity()
used = true
end
if used then
obj:set_properties({ textures = texture })
entity.gotten = true
minetest.sound_play("mcl_tools_shears_cut", { pos = pos }, true)
stack:add_wear(65535 / stackdef._mcl_diggroups.shearsy.uses)
inv:set_stack("main", stack_id, stack)
break
end
end
end
-- Spawn Egg
elseif igroups.spawn_egg then
-- Spawn mob

View File

@ -53,6 +53,15 @@ local function get_consumed_materials(tool, material)
return materials_used
end
local function contains(table, value)
for _, i in pairs(table) do
if i == value then
return true
end
end
return false
end
-- Given 2 input stacks, tells you which is the tool and which is the material.
-- Returns ("tool", input1, input2) if input1 is tool and input2 is material.
-- Returns ("material", input2, input1) if input1 is material and input2 is tool.
@ -60,9 +69,15 @@ end
local function distinguish_tool_and_material(input1, input2)
local def1 = input1:get_definition()
local def2 = input2:get_definition()
if def1.type == "tool" and def1._repair_material then
local r1 = def1._repair_material
local r2 = def2._repair_material
if def1.type == "tool" and r1 and type(r1) == "table" and contains(r1, input2) then
return "tool", input1, input2
elseif def2.type == "tool" and def2._repair_material then
elseif def2.type == "tool" and r2 and type(r2) == "table" and contains(r2, input1) then
return "material", input2, input1
elseif def1.type == "tool" and r1 then
return "tool", input1, input2
elseif def2.type == "tool" and r2 then
return "material", input2, input1
else
return nil
@ -121,11 +136,28 @@ local function update_anvil_slots(meta)
local distinguished, tool, material = distinguish_tool_and_material(input1, input2)
if distinguished then
local tooldef = tool:get_definition()
local repair = tooldef._repair_material
local has_correct_material = false
if string.sub(tooldef._repair_material, 1, 6) == "group:" then
has_correct_material = minetest.get_item_group(material:get_name(), string.sub(tooldef._repair_material, 7)) ~= 0
elseif material:get_name() == tooldef._repair_material then
has_correct_material = true
local material_name = material:get_name()
if type(repair) == "string" then
if string.sub(repair, 1, 6) == "group:" then
has_correct_material = minetest.get_item_group(material_name, string.sub(repair, 7)) ~= 0
elseif material_name == repair then
has_correct_material = true
end
else
if contains(repair, material_name) then
has_correct_material = true
else
for _, r in pairs(repair) do
if string.sub(r, 1, 6) == "group:" then
if minetest.get_item_group(material_name, string.sub(r, 7)) ~= 0 then
has_correct_material = true
end
end
end
end
end
if has_correct_material and tool:get_wear() > 0 then
local materials_used = get_consumed_materials(tool, material)

View File

@ -184,6 +184,7 @@ minetest.register_abm({
end,
})
-- Cactus mechanisms
minetest.register_abm({
label = "Cactus growth",
nodenames = {"mcl_core:cactus"},
@ -195,19 +196,31 @@ minetest.register_abm({
end,
})
-- Make cactus destroy items
minetest.register_abm({
label = "Cactus destroy items",
label = "Cactus mechanisms",
nodenames = {"mcl_core:cactus"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
for _,object in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do
for _, object in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do
local entity = object:get_luaentity()
if entity and entity.name == "__builtin:item" then
object:remove()
end
end
local posses = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }
for _, p in pairs(posses) do
if minetest.registered_nodes[minetest.get_node(vector.new(pos.x + p[1], pos.y, pos.z + p[2])).name].walkable then
local posy = pos.y
while minetest.get_node(vector.new(pos.x, posy, pos.z)).name == "mcl_core:cactus" do
local pos = vector.new(pos.x, posy, pos.z)
minetest.remove_node(pos)
minetest.add_item(vector.offset(pos, math.random(-0.5, 0.5), 0, math.random(-0.5, 0.5)), "mcl_core:cactus")
posy = posy + 1
end
break
end
end
end,
})

View File

@ -391,7 +391,3 @@ minetest.override_item("mcl_end:ender_eye", {
return itemstack
end,
})
minetest.override_item("mcl_core:bedrock", {
after_destruct = destroy_portal,
})

View File

@ -69,18 +69,19 @@ local function setSprinting(playerName, sprinting) --Sets the state of a player
local controls = player:get_player_control()
if players[playerName] then
players[playerName].sprinting = sprinting
local fov_old = players[playerName].fov
local fov_new = fov_old
local fade_time = .15
if sprinting == true
or controls.RMB
and string.find(player:get_wielded_item():get_name(), "mcl_bows:bow")
and player:get_wielded_item():get_name() ~= "mcl_bows:bow" then
if sprinting == true then
players[playerName].fov = math.min(players[playerName].fov + 0.05, 1.2)
players[playerName].fade_time = .15
fov_new = math.min(players[playerName].fov + 0.05, 1.2)
else
players[playerName].fov = .7
fov_new = .7
players[playerName].fade_time = .3
end
player:set_fov(players[playerName].fov, true, players[playerName].fade_time)
if sprinting == true then
playerphysics.add_physics_factor(player, "speed", "mcl_sprint:sprint", mcl_sprint.SPEED)
end
@ -88,12 +89,15 @@ local function setSprinting(playerName, sprinting) --Sets the state of a player
and player:get_wielded_item():get_name() ~= "mcl_bows:bow_0"
and player:get_wielded_item():get_name() ~= "mcl_bows:bow_1"
and player:get_wielded_item():get_name() ~= "mcl_bows:bow_2" then
players[playerName].fov = math.max(players[playerName].fov - 0.05, 1.0)
player:set_fov(players[playerName].fov, true, 0.15)
fov_new = math.max(players[playerName].fov - 0.05, 1.0)
if sprinting == false then
playerphysics.remove_physics_factor(player, "speed", "mcl_sprint:sprint")
end
end
if fov_new ~= fov_old then
players[playerName].fov = fov_new
player:set_fov(fov_new, true, fade_time)
end
return true
end
return false