Tslat/SmartBrainLib

Setting expirable memory repeatedly causes it to tick multiple times every tick

Closed this issue · 1 comments

When you set an expirable memory while there's an existing value, the SmartBrain does not check for duplicate entries and adds another instance of it, causing it to tick down multiple times every tick

Caused by SmartBrain.setMemoryInternal:

@Override
public <U> void setMemoryInternal(MemoryModuleType<U> memoryType, Optional<? extends ExpirableValue<?>> memory) {
    if (memory.isPresent() && memory.get().getValue()instanceof Collection<?> collection && collection.isEmpty())
        memory = Optional.empty();

    this.memories.put(memoryType, memory);

    if (memory.isPresent() && memory.get().canExpire()) //This does not check if the memory already exists in expirableMemories
        this.expirableMemories.add(memoryType);
}

Don't know what other versions this applies to, but I used forge 1.20.1 and sbl version 1.11 here