IntelligenceModding / AdvancedPeripherals

Advanced Peripherals adds many new features to the computercraft modification
https://advancedperipherals.netlify.app/
Apache License 2.0
100 stars 70 forks source link

[0.8] Modules only apply after closing and re-opening the glasses inventory #620

Closed SirEndii closed 2 months ago

SirEndii commented 3 months ago

Describe

Currently, when we put a module in the smart glasses, they only apply after closing and re-opening the glasses' menu. After some debugging, https://github.com/IntelligenceModding/AdvancedPeripherals/blob/db7de3093eadd99f70017b3534e503eebae835a0/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java#L21 does not contain the item even after https://github.com/IntelligenceModding/AdvancedPeripherals/blob/db7de3093eadd99f70017b3534e503eebae835a0/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesItemHandler.java#L125 was executed. However, placing a breakpoint into SmartGlassesItemHandler#setStackInSlot, placing an item into the modules slot and then skipping the called breakpoint(s) the module was recognized correctly, and the effects get applied to the glasses and https://github.com/IntelligenceModding/AdvancedPeripherals/blob/db7de3093eadd99f70017b3534e503eebae835a0/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/ModulePeripheral.java#L26 returns the function.

Weirdly enough, setStackInSlot gets called 6 times. Probably a client/server thing but 6 times seem wrong.

I tried to call the https://github.com/IntelligenceModding/AdvancedPeripherals/blob/db7de3093eadd99f70017b3534e503eebae835a0/src/main/java/de/srendi/advancedperipherals/common/smartglasses/SmartGlassesComputer.java#L133 after 3 ticks markDirty was called, but that also didn't work. I assume it's an issue of how we create the item handler?

        int tickCount = ServerLifecycleHooks.getCurrentServer().getTickCount();
        if (isDirty() && tickCount > (dirtyTickCount + 2)) {
            updatePeripheralsAndModules(itemHandler);

            isDirty = false;
        }

This issue mainly exists for my own forgetfulness and for contributors who want to help.

Steps to reproduce

  1. Open glasses
  2. Put night vision module into a modules slot
  3. No night vision effect, getModules also returns an empty table
  4. Close inventory
  5. Open inventory
  6. Module is loaded and you have night vision

Multiplayer?

No

Version

Own compiled build.

Minecraft, Forge and maybe other related mods versions

Forge 43.3.8 1.19.2

Screenshots or Videos

No response

Crashlog/log

No response

zyxkad commented 3 months ago

It's better if you can give a link to the actual code instead of pasting part of them

A link will include branch & file & line such useful information to help to position

SirEndii commented 3 months ago

It's better if you can give a link to the actual code instead of pasting part of them

A link will include branch & file & line such useful information to help to position

I agree The only thing was that I wrote this in a rush. I hadn't the time to do that Gonna edit the issue and add gh links to the actual code

SirEndii commented 3 months ago

I tried to test this on a dedicated server. But it seems that the modules don't work at all on a server. When inserting a module into the glasses, it never gets recognized by the glasses

It seems to be a client/server thing but I am unable to find a reason/fix for it...

zyxkad commented 3 months ago

After some random change now the module can work when inserting, and will stop to work when re-inserting 😓

And I found forge was doing some myth:

https://github.com/MinecraftForge/MinecraftForge/blob/1.20.x/src/main/java/net/minecraftforge/items/SlotItemHandler.java#L83

zyxkad commented 3 months ago

for some reason it's continuelly creating ModulePeripheral and SmartGlassesItemHandler.

SirEndii commented 3 months ago

for some reason it's continuelly creating ModulePeripheral and SmartGlassesItemHandler.

I think some of the smart glasses systems need some changes