-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for hashed block network ID's #97
Changes from 1 commit
a06705b
c7f1058
74e7072
cbf0bdb
a13b547
d50812d
7ebfa34
76fcf26
76681ed
caf0a5f
9201f6d
83f8bce
474c758
2cc9a11
6c6608f
f888398
86933a9
cdcdbec
7674fc1
6d2557e
740dd39
8d3d4dd
ae8239e
35adcbd
afd297f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,6 +381,15 @@ function provider (registry, { Biome, version }) { | |
return 0 | ||
} | ||
|
||
function getHashValue (states, name) { | ||
const tag = nbt.comp({ | ||
name: { type: 'string', value: name }, | ||
states: nbt.comp(states) | ||
}) | ||
const s = nbt.writeUncompressed(tag, 'little').toString() | ||
return fnv1a32(s) | ||
} | ||
|
||
function propValue (state, value) { | ||
if (state.type === 'enum') return state.values[value] | ||
if (state.type === 'bool') return !value | ||
|
@@ -391,3 +400,15 @@ function provider (registry, { Biome, version }) { | |
function mergeObject (to, from) { | ||
Object.defineProperties(to, Object.getOwnPropertyDescriptors(from)) | ||
} | ||
|
||
function fnv1a32 (s) { | ||
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV_hash_parameters | ||
const FNV1_OFFSET_32 = 0x811c9dc5 | ||
let h = FNV1_OFFSET_32 | ||
for (let i = 0; i < s.length; i++) { | ||
h ^= s.charCodeAt(i) & 0xff | ||
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) | ||
} | ||
|
||
return h & h | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hash only matched for that one block tested, other ones I tested didnt, not sure why this works either, I changed the test to block that didnt match. Also checked hashing online "hello" and with h & h it matched There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're not sure then please revert. The implication here is that that has a substantive effect and if it does it's not obvious to me (bitwise AND on two numbers yields the number itself, it does not turn signed to unsigned or anything like that). The only effect I can think would be to turn a floating point into an integer, but getting a float is not possible in the operation here. If it breaks without it then that needs some investigation because it doesn't seem to make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tested with my bot now and just returning "h" only works for some blocks, others hash collide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which ones? Can you be more specific with the inputs to trigger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The one block I changed in tests fails without "h & h", could be used as an example (i think its soul_soil or other soul_...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add tests that are failing or that show the collision. This duplication comment doesn't make any sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added new tests that illustrate difference in outputted numbers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this is because of dumb JavaScript behavior. The hash is exceeding the 32 bit boundary and because JS turns all |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a static method:
inside the Block instance constructor:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should first edit be made?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i get it now, ill try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should supportFeature be used as that "variable" that sets on start_game? Or other variable is still needed and supportFeature("blockHashes") will be true for mcbe >1.19.80?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, supportFeatures data should be inside minecraft-data features.json. It is used for handling features available in different minecraft versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it