Fix automated wool farm crash and elytra fly over unknown block crash #3809

Merged
ancientmarinerdev merged 3 commits from fix_unknown_block_crash into master 2023-06-21 22:53:36 +02:00

Wool crash bug

AsyncErr: Lua: Runtime error from mod 'mesecons' in callback environment_Step(): ...s/mineclone2/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua:181: attempt to index a nil value
stack traceback:
	...s/mineclone2/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua:181: in function 'action_on'
	...mes/mineclone2/mods/ITEMS/REDSTONE/mesecons/internal.lua:203: in function <...mes/mineclone2/mods/ITEMS/REDSTONE/mesecons/internal.lua:196>
	.../mineclone2/mods/ITEMS/REDSTONE/mesecons/actionqueue.lua:97: in function 'execute'
	.../mineclone2/mods/ITEMS/REDSTONE/mesecons/actionqueue.lua:86: in function <.../mineclone2/mods/ITEMS/REDSTONE/mesecons/actionqueue.lua:63>
	/usr/share/minetest/builtin/game/register.lua:446: in function </usr/share/minetest/builtin/game/register.lua:432>
	

Crash line:

minetest.add_item(pos, entity.drops[2].name .. " " .. math.random(1, 3))

Basically, we remove the second drop when they are sheared. We need to add it back immediately so when observer sees grass eaten, it triggers shears and shears can find the required drop.

I've made this a bit safer so it checks the drop is there first.

Elytra flying above unknown bug


2023-06-19 16:06:36: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'mcl_playerplus' in callback environment_Step(): ...games/mineclone2/mods/PLAYER/mcl_playerplus/init.lua:260: attempt to index field '?' (a nil value)

We try to check walkable, but if it isn't a registers block, it crashes. So made this safer and non-crashable.

Testing

Tested flying above unknown blocks (tested on cherry blossom trees which aren't on this branch). It no longer crashes.

Changed replace rate to 1 on sheep and change grass grown and mycellium abm to every second. Automated farm will now shear sheep and sheep eats and it shears and it eats etc. etc.

### Wool crash bug ``` AsyncErr: Lua: Runtime error from mod 'mesecons' in callback environment_Step(): ...s/mineclone2/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua:181: attempt to index a nil value stack traceback: ...s/mineclone2/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua:181: in function 'action_on' ...mes/mineclone2/mods/ITEMS/REDSTONE/mesecons/internal.lua:203: in function <...mes/mineclone2/mods/ITEMS/REDSTONE/mesecons/internal.lua:196> .../mineclone2/mods/ITEMS/REDSTONE/mesecons/actionqueue.lua:97: in function 'execute' .../mineclone2/mods/ITEMS/REDSTONE/mesecons/actionqueue.lua:86: in function <.../mineclone2/mods/ITEMS/REDSTONE/mesecons/actionqueue.lua:63> /usr/share/minetest/builtin/game/register.lua:446: in function </usr/share/minetest/builtin/game/register.lua:432> ``` Crash line: `minetest.add_item(pos, entity.drops[2].name .. " " .. math.random(1, 3))` Basically, we remove the second drop when they are sheared. We need to add it back immediately so when observer sees grass eaten, it triggers shears and shears can find the required drop. I've made this a bit safer so it checks the drop is there first. ### Elytra flying above unknown bug ``` 2023-06-19 16:06:36: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'mcl_playerplus' in callback environment_Step(): ...games/mineclone2/mods/PLAYER/mcl_playerplus/init.lua:260: attempt to index field '?' (a nil value) ``` We try to check walkable, but if it isn't a registers block, it crashes. So made this safer and non-crashable. ### Testing Tested flying above unknown blocks (tested on cherry blossom trees which aren't on this branch). It no longer crashes. Changed replace rate to 1 on sheep and change grass grown and mycellium abm to every second. Automated farm will now shear sheep and sheep eats and it shears and it eats etc. etc.
ancientmarinerdev added the
#P1 CRITICAL
label 2023-06-19 18:59:59 +02:00
chmodsayshello requested changes 2023-06-21 12:26:20 +02:00
chmodsayshello left a comment
Member

I got a (very nitpicky) suggestion

I got a (very nitpicky) suggestion
@ -6,6 +6,8 @@ local S = minetest.get_translator("mobs_mc")
--################### SHEEP
--###################
local WOOL_REPLACE_RATE = 80
Member

It seems like this variable ONLY get used once, unless you consider adding a setting for the replace rate, it should stay hardcoded in my opinion

It seems like this variable ONLY get used once, unless you consider adding a setting for the replace rate, it should stay hardcoded in my opinion
Author
Owner

I appreciate the feedback, but I don't agree with that. From a computer perspective (if the PC was the only thing reading the code), your suggestion makes sense. However in most languages, it is often standard practice to put things that change or can change at the top in a constant. I often change this variable when testing sheep and wool farms, and digging through code every time is a PITA to find the changeable values. As a result, I tend to put these sort of values at the top of files in a constant.

I appreciate the feedback, but I don't agree with that. From a computer perspective (if the PC was the only thing reading the code), your suggestion makes sense. However in most languages, it is often standard practice to put things that change or can change at the top in a constant. I often change this variable when testing sheep and wool farms, and digging through code every time is a PITA to find the changeable values. As a result, I tend to put these sort of values at the top of files in a constant.
Member

Sure, this is why #define in C and C++ exists, however, in that situation, it makes no difference as the compiler takes care of it...

Anyways, I agree, in the end, it is just 8 bytes of RAM (lua uses 64 bit doubles), which makes pretty much no difference on a modern computer.

Sure, this is why `#define` in C and C++ exists, however, in that situation, it makes no difference as the compiler takes care of it... Anyways, I agree, in the end, it is just 8 bytes of RAM (lua uses 64 bit doubles), which makes pretty much no difference on a modern computer.
chmodsayshello marked this conversation as resolved
ancientmarinerdev force-pushed fix_unknown_block_crash from 1f1d1ca1f5 to 8b9b4b00e5 2023-06-21 22:48:07 +02:00 Compare
ancientmarinerdev added this to the 0.84.0 - Very Nice milestone 2023-06-21 22:53:23 +02:00
ancientmarinerdev merged commit a286cb5046 into master 2023-06-21 22:53:36 +02:00
ancientmarinerdev deleted branch fix_unknown_block_crash 2023-06-21 22:53:43 +02:00
Sign in to join this conversation.
No reviewers
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: VoxeLibre/VoxeLibre#3809
No description provided.