Posted 25 August 2019 - 03:06 PM
EDIT: Please move this into the proper category, I have no idea when I clicked on "tutorials" but this is definitely the wrong section! sorry
I'm using the latest CC: Tweaked 1.83.1
To optimize miners, I want to map the entire inventory into a table, and keep track of it during mining without manually looping over all of the slots with 'turtle.getItemDetail([slot])' as I don't know what impact that may have on server performance with 20+ turtles running.
The official Wiki page for this event shows a very basic unrealistic use case of this event, but does tell us, that it has no return values.
The in-game help message is a little bit more useful, suggesting that we use "comparison operations" to see what changes have been made.
What "comparison operations" does this have in mind? It can't be 'turtle.compareTo(number slot)', or any of the other 'turtle.compare' methods. The same goes for all of the other API methods. If this just goes back "keep the old state of the inventory and on this event, iterate through the whole thing again and compare the slots"… then that's dissapoiting.
Note:
If this can't be done within the current API, could anyone willing and knowledgeable enough do a quick test if a return value (slot number / table slots that changed / etc) can be added to the event?
From a quick glance at the source, it seems plausible enough assuming the 'm_previousInventory' has not changed yet.
The calling function in 'main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java' does have access to the 'm_previousInventory', and 'm_inventory' - I just couldn't find where this function is called from and don't know if the inventories weren't synced by this point.
I'm using the latest CC: Tweaked 1.83.1
To optimize miners, I want to map the entire inventory into a table, and keep track of it during mining without manually looping over all of the slots with 'turtle.getItemDetail([slot])' as I don't know what impact that may have on server performance with 20+ turtles running.
The official Wiki page for this event shows a very basic unrealistic use case of this event, but does tell us, that it has no return values.
The in-game help message is a little bit more useful, suggesting that we use "comparison operations" to see what changes have been made.
Events fired by the Turtle API: "turtle_inventory" when any of the items in the inventory are changed. Use comparison operations to inspect the changes.
What "comparison operations" does this have in mind? It can't be 'turtle.compareTo(number slot)', or any of the other 'turtle.compare' methods. The same goes for all of the other API methods. If this just goes back "keep the old state of the inventory and on this event, iterate through the whole thing again and compare the slots"… then that's dissapoiting.
Note:
If this can't be done within the current API, could anyone willing and knowledgeable enough do a quick test if a return value (slot number / table slots that changed / etc) can be added to the event?
From a quick glance at the source, it seems plausible enough assuming the 'm_previousInventory' has not changed yet.
The calling function in 'main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java' does have access to the 'm_previousInventory', and 'm_inventory' - I just couldn't find where this function is called from and don't know if the inventories weren't synced by this point.
@Override
public void update()
{
super.update();
m_brain.update();
if( !getWorld().isRemote && m_inventoryChanged )
{
ServerComputer computer = getServerComputer();
if( computer != null ) computer.queueEvent( "turtle_inventory" );
m_inventoryChanged = false;
for( int n = 0; n < getSizeInventory(); n++ )
{
m_previousInventory.set( n, InventoryUtil.copyItem( getStackInSlot( n ) ) );
}
}
}
Edited on 31 August 2019 - 10:08 PM