More randomness for slime chunks #4466
No reviewers
Labels
No Label
#P1 CRITICAL
#P2: HIGH
#P3: elevated
#P4 priority: medium
#P6: low
#Review
annoying
API
bug
code quality
combat
commands
compatibility
configurability
contribution inside
controls
core feature
creative mode
delayed for engine release
documentation
duplicate
enhancement
environment
feature request
gameplay
graphics
ground content conflict
GUI/HUD
help wanted
incomplete feature
invalid / won't fix
items
looking for contributor
mapgen
meta
mineclone2+
Minecraft >= 1.13
Minecraft >= 1.17
missing feature
mobile
mobs
mod support
model needed
multiplayer
Needs adoption
needs discussion
needs engine change
needs more information
needs research
nodes
non-mob entities
performance
player
possible close
redstone
release notes
schematics
Skyblock
sounds
Testing / Retest
tools
translation
unconfirmed
mcl5
mcla
Media missing
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: VoxeLibre/VoxeLibre#4466
Loading…
Reference in New Issue
No description provided.
Delete Branch "kno10/VoxeLibre:slime-spawning"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The old code caused a diagonal pattern. If some x,z was a slime chunk, then so was x+1,z-1.
Use a classic pseudo-random hashing approach instead, by multiplication of chunk numbers
with large primes that should be more random.
This pull does not modify spawn frequency, only the chunk logic.
Because this replaces the computation of slime chunks, do not expect slimes to spawn in the same places as before. For testing, you can increase the slime chunk density, e.g., to 2 (every other chunk). There is a commented log that will print, e.g.,
Chunk 1182545475 is a slime chunk: false
andChunk 2924583950 is a slime chunk: true
Aside of the typo in a comment, lgtm... as long as slimes don't spawn on the surface more than they do without this patch.
Haven't tested yet.
@ -9,0 +13,4 @@
local slime_max_light = (tonumber(minetest.settings:get_bool("mcl_mobs_slime_max_light", true)) or minetest.LIGHT_MAX) + 1
-- maximum light level for swamp spawning
local swamp_light_max = 7
-- maximum highzt to spawn in slime chunks
Typo:
height
nothighzt
?ee0db05876
to0edcfce8d4
Fixed the typo, thanks.
Next time you fix something, please mark the conversation as 'Resolved'.
Here's your review.
I haven't been able to get any slimes to spawn. Perhaps it's because of all the settings being so broken?
@ -9,0 +8,4 @@
-- slime density, where default N=10 is every 10th chunk
local slime_density = math.floor(tonumber(minetest.settings:get("mcl_mobs_slime_density")) or 10)
-- use 3D chunking instead of 2d chunks
local slime_3d_chunks = minetest.settings:get("mcl_mobs_slime_3d_chunks") or false
get
method is... bizarre.get_bool
can handle default values as its second argument, see http://api.minetest.net/class-reference/#methods_16.@ -9,0 +10,4 @@
-- use 3D chunking instead of 2d chunks
local slime_3d_chunks = minetest.settings:get("mcl_mobs_slime_3d_chunks") or false
-- maximum light level, for slimes in caves only, not magma/swamps
local slime_max_light = (tonumber(minetest.settings:get_bool("mcl_mobs_slime_max_light", true)) or minetest.LIGHT_MAX) + 1
So now you're getting an integer value through
get_bool
, withtrue
as the default value. O_oLOL, put that into the wrong line...
@ -88,2 +27,2 @@
assert(calculate_chunk_value(vector.new(16,0,64)) == (3), "calculate_chunk_value failed")
assert(calculate_chunk_value(vector.new(-160,0,-160)) == 0, "calculate_chunk_value failed")
local math_floor = math.floor
local math_max = math.max
Why localize these functions if you're already using them unlocalized a few lines above (when handling settings)?
Following this pattern from other modules, although the minetest "vector" class does not seem to bother.
My guess was that this can help with performance in functions that are frequently called (as it is not necessary to check if someone modified math.floor in the meantime).
For the settings, which supposedly is only executed once and hence not performance critical, I would prefer the standard version.
But I have to rely on your experience whether localizing is beneficial or not.
I did a profile of this recently (local access compared to accessing a global) and accessing a local was about 3 times faster on my hardware than a simple global access (see #4338 (comment)). I haven't profiled it this specific thing, but I would expect accessing a field thru a global would be a bit less than an additional 2x. But even then, we are talking about 3.1 ns for a local access and an estimated 16.3 ns (2 * (9.7 - 3.1) + 3.1) for the non-local access so unless this is in an inner loop it probably doesn't matter that much. Defaulting to the faster method when they behave (or should behave) the same is a good habit to get into though.
Probably easy enough just to move the local variable assignment to near the top of the file and use it everywhere.
@ -224,0 +224,4 @@
# Slime chunk density
mcl_mobs_slime_density (Slime chunk density, default is one in ten, 0 to disable cave slime) int 10 0
# Use 3d chunking instead of 2d chunking
mcl_mobs_slime_3d_chunks (Use 3d chunking instead of 2d chunking) bool false
Reduce all of these settings to from
mcl_mobs_slime_...
toslime_...
(and don't forget to update the .lua file for that). Explanation:mcl_mobs
. They are defined inmobs_mc
.Also, consider making the visible names of these settings a lot shorter and prepending all of them with "Slime". If the 3D/2D chunking is only relevant for slimes, it should be apparent for the player that it's only relevant for slimes.
The names get cut off, and it's even worse when you're using a custom font.
UPD: I think I know what the issue was. You've mixed up text in comment (which is the description for a setting) and in brackets (which is the visible name of a setting). Still, you don't have to repeat the same thing for
slime_3d_chunks
name and description if there's no more info to add.0edcfce8d4
to9c759d4f6b
9c759d4f6b
to2adf3a9904
@rudzik8, updated. Please let me know whether I should de-localize these functions.
First:
Second, after reading through teknomunk's comment, I don't think you should.
@rudzik8 you can use worldedit to rip out large areas underground and see if slimes are spawning there.
@rudzik8 @the-real-herowl I updated the patch to use
PcgRandom
. This makes the code simpler.Chunk density can now also be float, so a value of 12.34 is one in 12.34 blocks on average has slime.
@ -9,0 +5,4 @@
local SEED_OFFSET = 362 -- module specific seed
local world_seed = (minetest.get_mapgen_setting("seed") + SEED_OFFSET) % 4294967296
-- slime density, where default N=10 is every 10th chunk
local slime_density = tonumber(minetest.settings:get("slime_density")) or 10
If increasing this value means decreasing slime density, then it should be called Slime chunk rarity.
As this is a new control, what type of control would you prefer? I'm a probability guy, I would prefer 0.10 for 10% chance, but I figure that many people would prefer 10 for 10%, or 10 for "1 in 10" as used in other parts (note that these are opposite, 5% is not 1 in 5).
Looking at the rest of the code,
chance
andrarity
seems to be the name used to describe 1 in N probability. The minetest API useschance
,rarity
orscarcity
, each in different contexts, for the same thing.Overall, it looks quite good to me, with just a couple of items. Testing shows that slime chunks are no longer along diagonals.
@ -103,0 +24,4 @@
if slime_density == 1 then return true end -- slime everywhere
local bpos = vector.new(math_floor(pos.x / MAPBLOCK_SIZE), slime_3d_chunks and math.floor(pos.y / MAPBLOCK_SIZE) or 0, math_floor(pos.z / MAPBLOCK_SIZE))
local p = PcgRandom(minetest.hash_node_position(bpos) + world_seed):next(0,1e9)/1e9
return p * slime_density < 1
Is there a difference between what you have here and
return PcgRandom(...):next(0, slime_density - 1) == 0
?support for floating point values.
@ -164,3 +80,2 @@
local swamp_light_max = 7
-- FIXME: redundant check?
Looks like there are two separate checks in the mob spawning code, one in the spawning definition and one in the mob definition. This function overrides the default light level checks. I don't think we can remove this right now.
c24039be71
to4916c59e1d
Code LGTM. Haven't tested personally. Count this as half an approval.
@ -222,2 +222,4 @@
mcl_mobs_overworld_passive_threshold (Combined light threshold to stop animal and npc spawns in the Overworld) int 7 0 14
# Slime chunk density, default is one in ten, 0 to disable cave slime
slime_chance (Slime chunk chance) float 10.0 0.0
Still not satisfied.
Let's just settle on rarity. A control that is 1 in N is okay, it's just that it should be named appropriately.
Maybe we should then really go for slime_chunk_percentage, and not 1:N, that name is likely least confusing?
MCLA has
mcl_villages_village_chance
which is also 1:N.A possible name for the 1:N value would be
slime_chunk_ratio
?Maybe, but ratio is not a common word and may not be understood as well as rarity.
Percentage is fine, even though we don't seem to be ever using that. That's just switching from 1:N to N:100.
I am not sure if rarity is that common, and if people will have a good understanding of what semantics a "rarity" number gives.
In google books, ratio is much more common https://books.google.com/ngrams/graph?content=rarity%2C+ratio and ratios are widely used in sport bets, aren't they?
4916c59e1d
to142ef3b41b
142ef3b41b
tof448495d53
Two minor issues and a nitpick. I think we should be good to merge this after the two minor issues are addressed.
@ -102,1 +22,3 @@
return slime_chunk
if not pos then return end -- no position given
if slime_ratio == 0 then return end -- no slime chunks
if slime_ratio == 1 then return true end -- slime everywhere
I think this should be
if slime_ratio <= 1
. The conditional below will always be true whenslime_ratio
between0
and1
.@ -103,0 +22,4 @@
if not pos then return end -- no position given
if slime_ratio == 0 then return end -- no slime chunks
if slime_ratio == 1 then return true end -- slime everywhere
local bpos = vector.new(math_floor(pos.x / MAPBLOCK_SIZE), slime_3d_chunks and math.floor(pos.y / MAPBLOCK_SIZE) or 0, math_floor(pos.z / MAPBLOCK_SIZE))
Both
math_floor
andmath.floor
in this line.@ -559,3 +470,4 @@ mcl_mobs:non_spawn_specific("mobs_mc:magma_cube_big","overworld",0, minetest.LIG
mcl_mobs.register_egg("mobs_mc:slime_big", S("Slime"), "#52a03e", "#7ebf6d")
-- FIXME: add spawn eggs for small and tiny slimes and magma cubes
Nitpick: I believe that for this project, we don't add an empty line at the end of the file, though, this does not appear in the code guidelines. @the-real-herowl, perhaps it should?
Maybe. Should deal with file ending problems. I think most files do have that. This is not an issue here though.
f448495d53
to16f0d85be8
16f0d85be8
to8eb0433659