Advanced Peripherals

Advanced Peripherals

29M Downloads

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

SirEndii opened this issue ยท 6 comments

commented

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,

does not contain the item even after
public void setStackInSlot(int slot, @NotNull ItemStack stack) {
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 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

public void updatePeripheralsAndModules(IItemHandler itemHandler) {
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

commented

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

commented

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

commented

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...

commented

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

commented

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

commented

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

I think some of the smart glasses systems need some changes