Page 1 of 1

[1.1.6] LuaPlayer.hand_location does not account for blueprint book inventories

Posted: Wed Dec 16, 2020 6:23 pm
by Xorimuth
player.hand_location returns

inventory :: defines.inventory
slot :: uint

If you access hand_location whilst holding a blueprint in the 3rd slot of a blueprint book in the players inventory then it will have inventory = 1, slot = 3. If you then write that same information back to player.hand_location it will not behave as expected (and crash if there is already an item in the 3rd slot of the player's inventory).

This means that in certain situations

Code: Select all

player.hand_location = player.hand_location
will cause the mod to crash.

Re: [1.1.6] LuaPlayer.hand_location does not account for blueprint book inventories

Posted: Fri Dec 18, 2020 5:03 pm
by Rseding91
I'm not sure if this will get fixed. Adding read/write support for the hand location to the mod API was a "well I guess; if it works" but it has always been a super iffy thing to allow mods to touch.

The "fix" might be to just remove writing from the mod API.

Re: [1.1.6] LuaPlayer.hand_location does not account for blueprint book inventories

Posted: Fri Dec 18, 2020 5:30 pm
by Xorimuth
Rseding91 wrote:
Fri Dec 18, 2020 5:03 pm
The "fix" might be to just remove writing from the mod API.
Please don't do that! I don't actually need to access the hand inside of blueprint books, it just came up because my mod was running a piece of code when it wasn't supposed to and I thought that it should be reported. Just a simple warning in the docs would be sufficient :)