zlainsama / CosmeticArmorReworked

This mod allows you to wear two sets of armor, one for display, one for function.
https://minecraft.curseforge.com/projects/cosmetic-armor-reworked
Other
17 stars 18 forks source link

API usage of setSkinArmor #94

Closed snakehugo closed 9 months ago

snakehugo commented 9 months ago

I'm using CosmeticArmorReworked-1.16.5-v5 in both server and clients.

When calling setSkinArmor(3, true) I can hide the player's helmet but other players will not see that change. Also it doesn't save it at disconnect/reconnect. So it might be an issue on the API not sending informations to the server and that could explain both of this issues. Let me know what can we do about this.

Also do you have a discord server, it might be more usefull to use that to communicate?

snakehugo commented 9 months ago

With this code: CAStacksBase invCosArmor = CosArmorAPI.getCAStacksClient(player.getUniqueID()); if(invCosArmor.isSkinArmor(3)) // helmet is hidden { invCosArmor.setSkinArmor(3, false); } else { invCosArmor.setSkinArmor(3, true); }

zlainsama commented 9 months ago

As stated here, you should only make changes on server side. If you need to make changes on client side, you will need to manually send sync packets yourself, and make sure your changes is invoked on the correct thread.

I do not have a Discord server.

snakehugo commented 9 months ago

I don't get it. My system is like this: Players can hit a key to open a menu and if they click on a button on this menu, it will call CAStacksBase invCosArmor = CosArmorAPI.getCAStacksClient(player.getUniqueID()); if(invCosArmor.isSkinArmor(3)) // helmet is hidden { invCosArmor.setSkinArmor(3, false); } else { invCosArmor.setSkinArmor(3, true); }

To toggle the visibility of the helmet. And it works fine for the player perspective, but other players won't see any changes.

So it is like your buttons that we have to click to show each of the slots but it doesn't work properly with the API (1.16.5-v5)

I want to call your code but not use your inventory buttons. Is that not the right code to use? I'm confused, I'm really sorry to bother you with that. Sorry again

zlainsama commented 9 months ago

Basically, if your button executes code on client side, you need this ModObjects.network.sendToServer(new PacketSetSkinArmor(3, invCosArmor.isSkinArmor(3))) after setSkinArmor(). And, if your button executes code on server side, you don't need to do that.

snakehugo commented 9 months ago

Thanks, it solved it! I didn't know that we had to deal with packets, didn't see the comment in code