Skip to content

Commit

Permalink
Fix seedHashcode
Browse files Browse the repository at this point in the history
- Zero (0) is no longer a special case
- Trim before operating
  • Loading branch information
Dianliang233 committed Aug 8, 2024
1 parent 14e8dca commit 41d71f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export default antfu({
'unused-imports/no-unused-vars': 'warn',
'node/prefer-global/process': 'off',
'vue/html-self-closing': 'off',
'vue/html-indent': 'off',
},
})
15 changes: 6 additions & 9 deletions src/tools/seedHashcode/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,23 @@ const seed = ref('Minecraft Wiki')

<div>
{{ t('seedHashcode.actual') }}
<template v-if="seed === ''">
<template v-if="seed.trim() === ''">
{{ t('seedHashcode.emptyString') }}
</template>
<template v-else-if="seed === '0'">
{{ t('seedHashcode.zero') }}
</template>
<code v-else>{{ hashCode(seed) }}</code>
<code v-else>{{ hashCode(seed.trim()) }}</code>
</div>

<CdxMessage
v-if="
/^[+-]?\d+$/.test(seed) &&
(BigInt(seed) > BigInt(2) ** BigInt(63) - BigInt(1) ||
BigInt(seed) < -(BigInt(2) ** BigInt(63)))
/^[+-]?\d+$/.test(seed.trim()) &&
(BigInt(seed.trim()) > BigInt(2) ** BigInt(63) - BigInt(1) ||
BigInt(seed.trim()) < -(BigInt(2) ** BigInt(63)))
"
type="warning"
>
{{ t('seedHashcode.outOfRange') }}
</CdxMessage>
<CdxMessage v-else-if="/^[+-]?\d+$/.test(seed)" type="warning">
<CdxMessage v-else-if="/^[+-]?\d+$/.test(seed.trim())" type="warning">
{{ t('seedHashcode.number') }}
</CdxMessage>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/tools/seedHashcode/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"seedHashcode.actual": "Actual seed:",
"seedHashcode.emptyString": "Empty string should result in 0, but Minecraft actually generates a random number as the seed.",
"seedHashcode.number": "A number would be used directly. This is the theoretical hash derived from the number.",
"seedHashcode.zero": "0 is a special case. Minecraft actually generates a random number as the seed.",
"seedHashcode.outOfRange": "This number is exceeds the limit of 64-bit signed integer. The above seed is actually used."
}

0 comments on commit 41d71f9

Please sign in to comment.