Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ddec67d894985516aabc8fc608cd339ff99684f5
Author: Fabian <[email protected]>
Date:   Thu Aug 17 19:40:39 2023 +0200

    Update package-lock.json

commit 840fe845236b696c362b25baa522d9241ceec65c
Author: Fabian <[email protected]>
Date:   Sun Aug 13 12:25:25 2023 +0200

    Changelog adjustment

commit 4ead6c13306a36134c01c1611806b65578b84a47
Author: Fabian <[email protected]>
Date:   Sun Aug 13 12:24:32 2023 +0200

    Instruction images

commit b3189ba7dd1d9e9b6a6039147652806782eb9d5e
Merge: 49e5f9e 32f844c
Author: Fabian <[email protected]>
Date:   Sun Aug 13 08:01:47 2023 +0200

    Merge branch 'trunk' into dev

commit 49e5f9e
Author: Fabian <[email protected]>
Date:   Sun Aug 6 15:05:23 2023 +0200

    Update changelog.json

commit 91d4b4a
Author: Fabian <[email protected]>
Date:   Sun Aug 6 14:37:49 2023 +0200

    Update changelog.json

commit 3ac9742
Author: Fabian <[email protected]>
Date:   Sun Aug 6 14:28:32 2023 +0200

    Changelog and version updated

commit 126e68d
Author: Fabian <[email protected]>
Date:   Sun Aug 6 14:21:10 2023 +0200

    Fix Firefox deadlock

    * In certain circumstances, reading from ReadableStreamDefaultReader causes a deadlock in Firefox. Causing a bit of delay seems to prevent the issue.

    (addresses #47)

commit 9017fd8
Author: Fabian <[email protected]>
Date:   Sun Aug 6 10:12:00 2023 +0200

    Seed adjustments

    * Seeds are now generated using BigInt, to provide a 64 bit range

    (addresses #5)
  • Loading branch information
Fasguy committed Dec 6, 2023
1 parent be5a8e4 commit 49ddc1b
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toolbox",
"version": "1.3.2",
"version": "1.3.3",
"type": "commonjs",
"scripts": {
"ng": "ng",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ export class CraftingRecipeRandomizerService implements OnInit, OnDestroy {
}

type RandomizeOptions = {
seed: number;
seed: bigint;
selectedCraftingRecipes: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CraftingRecipeRandomizerWorker {
private _intermediaryDatapack!: Datapack;
private _finalDatapack!: Datapack;

private _seed!: number;
private _seed!: bigint;

public async loadDataFromBlob(blob: Blob) {
const textDecoder = new TextDecoder();
Expand Down Expand Up @@ -89,7 +89,7 @@ export class CraftingRecipeRandomizerWorker {
}
}

public prepareDataPack(seed: number, selectedCraftingRecipes: string[]) {
public prepareDataPack(seed: bigint, selectedCraftingRecipes: string[]) {
this._seed = seed;

this._intermediaryDatapack = new Datapack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class LootTableRandomizerService implements OnDestroy, OnInit {
}

type RandomizeOptions = {
seed: number;
seed: bigint;
dropChance100: boolean;
deadEndIndicator: boolean;
selectedLootTables: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
<tbx-sub-section>
<h2>Installing during world creation (Minecraft v1.16+)</h2>
<ol>
<li>On the main menu go to <u>Singleplayer</u> -> <u>Create New World</u></li>
<li>Go into the <u>Data Packs</u> menu</li>
<li>Drag and drop the downloaded data pack into Minecraft</li>
<li>Confirm that you want to import the data pack</li>
<li>Click on the icon of the data pack to move it from the <u>Available</u> list to the <u>Selected</u> list</li>
<li>Click Done</li>
<li>Generate the world</li>
<li>
<div>On the main menu go to <u>Singleplayer</u> -> <u>Create New World</u></div>
<img src="resources/images/instructions/datapack/1.png">
<img src="resources/images/instructions/datapack/2.png">
</li>
<li>
<div>Go into the <u>Data Packs</u> menu</div>
<img src="resources/images/instructions/datapack/3.png">
</li>
<li>
<div>Drag and drop the downloaded data pack into Minecraft</div>
<img src="resources/images/instructions/datapack/4a.png">
<div>Alternatively, you can click on "Open pack folder" and copy the file into the opened folder</div>
<img src="resources/images/instructions/datapack/4b1.png">
<img src="resources/images/instructions/datapack/4b2.png">
</li>
<li>
<div>Confirm that you want to import the data pack</div>
<img src="resources/images/instructions/datapack/5.png">
</li>
<li>
<div>Click on the icon of the data pack to move it from the <u>Available</u> list to the <u>Selected</u> list</div>
<img src="resources/images/instructions/datapack/6.png">
</li>
<li>
<div>Click Done</div>
<img src="resources/images/instructions/datapack/7.png">
</li>
</ol>
</tbx-sub-section>
<tbx-sub-section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

ol {
padding-left: 4em;
}

img {
max-width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class LootTableRandomizerWorker {
private _intermediaryDatapack!: Datapack;
private _finalDatapack!: Datapack;

private _seed!: number;
private _seed!: bigint;

public async loadDataFromBlob(blob: Blob) {
const textDecoder = new TextDecoder();
Expand Down Expand Up @@ -102,7 +102,7 @@ export class LootTableRandomizerWorker {
}
}

public async prepareDataPack(seed: number, selectedLootTables: string[]) {
public async prepareDataPack(seed: bigint, selectedLootTables: string[]) {
this._seed = seed;

this._intermediaryDatapack = new Datapack();
Expand Down
51 changes: 23 additions & 28 deletions projects/toolbox-main/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { deserialize, serialize } from "src/lib/serialize-form";
import { Datapack } from "./ts-datapack/datapack";
import { GenericAdvancement } from "./ts-datapack/generic-advancement";

export const MAX_SIGNED_64_BIT_INTEGER = 9223372036854775807n;

export function duckCheck(obj: any, ...properties: any[]) {
for (const property of properties) {
if (typeof obj[property] === "undefined") {
Expand All @@ -16,20 +18,20 @@ export function duckCheck(obj: any, ...properties: any[]) {
return true;
}

export function seededRandom(seed: number) {
const baseSeeds = [101182939, 495868718, 999091121, 39475253];
export function seededRandom(seed: BigInt) {
const baseSeeds = [101182939n, 495868718n, 999091121n, 39475253n];

let [x, y, z, w] = baseSeeds;

const random = () => {
const t = x ^ (x << 11);
const t = (x ^ (x << BigInt(11))) % MAX_SIGNED_64_BIT_INTEGER;
[x, y, z] = [y, z, w];
w = w ^ (w >> 19) ^ (t ^ (t >> 8));
return w / 0x7fffffff;
w = (((w ^ (w >> BigInt(19))) % MAX_SIGNED_64_BIT_INTEGER) ^ ((t ^ (t >> BigInt(8))) % MAX_SIGNED_64_BIT_INTEGER)) % MAX_SIGNED_64_BIT_INTEGER;
return Number(w * 100n / MAX_SIGNED_64_BIT_INTEGER) / 100;
};

[x, y, z, w] = baseSeeds.map(i => i + seed);
[x, y, z, w] = [0, 0, 0, 0].map(() => Math.round(random() * 1e16));
[x, y, z, w] = [0, 0, 0, 0].map(() => BigInt(Math.round(random() * 1e16)));

return random;
}
Expand Down Expand Up @@ -77,20 +79,21 @@ export function shuffle<T>(array: T[], random = Math.random) {
return array;
}

export function tryParseInt(str: string) {
const result = parseInt(str);

return {
success: !isNaN(result),
value: result
export function tryParseBigInt(str: string) {
try {
return {
success: true,
value: BigInt(str)
};
}
catch {
return {
success: false,
value: BigInt(NaN)
};
}
}

/*
#5 TODO: It may be worth investigating, if cyrb53 is better suited for this.
There's no real reason to emulate how Minecraft handles hash generation and using all available 53 bits, instead of the 32 with this current method, decreases the likelyhood of collisions.
https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
*/
export function hashCode(input: string) {
if (input.length === 0) return 0;

Expand Down Expand Up @@ -273,16 +276,8 @@ export function mergeDeep(target: any, ...sources: any): any {
}

export function seedHelper(submittedSeed: string) {
//There's one thing to note about how seeds work here:
//I wanted to emulate how Minecraft handles seeds as much as possible.
//Therefore, the seed input is a string. If i can parse it to a Number, I'll use that.
//Otherwise, i'll use the hash code of the string.
//A problem arises with how JavaScript handles numbers.
//We have a maximum safe integer precision of 53 bits, so we can't use the full range of numbers, that Minecraft would normally allow.
//This means, that if we actually *have* a number that's outside those bounds, the last 3 digits will essentially be dropped.

let parsedSeed = tryParseInt(submittedSeed);
let seed: number;
let parsedSeed = tryParseBigInt(submittedSeed);
let seed: bigint;

if (parsedSeed.success && parsedSeed.value !== 0) {
seed = parsedSeed.value;
Expand All @@ -291,7 +286,7 @@ export function seedHelper(submittedSeed: string) {
}

if (seed === 0) {
seed = parseInt(randomMinecraftSeed());
seed = BigInt(randomMinecraftSeed());
}

return seed;
Expand Down
12 changes: 12 additions & 0 deletions projects/toolbox-main/src/media/data/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,17 @@
"removals": []
},
"notes": ""
},
{
"version": "",
"build_date": "",
"changes": {
"additions": [],
"modifications": [
"Seeds are now 64-Bit instead of 53-Bit"
],
"removals": []
},
"notes": "The seed adjustment is a breaking change. Using old seeds will not guarantee the same output."
}
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 49ddc1b

Please sign in to comment.