Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Support for literal to constant and literal (any combination) #4

Open
ChloeDawn opened this issue Jun 28, 2019 · 1 comment
Open

Support for literal to constant and literal (any combination) #4

ChloeDawn opened this issue Jun 28, 2019 · 1 comment

Comments

@ChloeDawn
Copy link

There are cases where you may wish to unpick any number of constants and literals as a math operation in place of a single literal. An example in Minecraft would be with entity events, wherein Mojang use the following values:

PERMISSION_LEVEL_SET_TO_0 = 24; // Permission level was set to 0 on the server
PERMISSION_LEVEL_SET_TO_1 = 25; // Permission level was set to 1 on the server
PERMISSION_LEVEL_SET_TO_2 = 26; // Permission level was set to 2 on the server
PERMISSION_LEVEL_SET_TO_3 = 27; // Permission level was set to 3 on the server
PERMISSION_LEVEL_SET_TO_4 = 28; // Permission level was set to 4 on the server

But when analyzing the deserialization of the event, the permission level is determined as event - 24, which leads to the suspicion that they in fact only have one constant,

PERMISSION_LEVEL_SET = 24; // Permission level was updated on the server

And that they serialize in the following forms at call sites:

PERMISSION_LEVEL_SET + 0; // Permission level was set to 0 on the server
PERMISSION_LEVEL_SET + 1; // Permission level was set to 1 on the server
PERMISSION_LEVEL_SET + 2; // Permission level was set to 2 on the server
PERMISSION_LEVEL_SET + 3; // Permission level was set to 3 on the server
PERMISSION_LEVEL_SET + 4; // Permission level was set to 4 on the server

To recreate this form, explicit support will be needed for this kind of unpicking.

@Daomephsta
Copy link
Collaborator

Are there any other examples of this kind of format, in Minecraft or otherwise? It's not the most intuitive thing when read IMO. I'm pretty sure this will be somewhat tricky to implement, so if it's just used this once in some questionable quality code, I'd rather not implement it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants