From f6b6a6bf7d37345f25df1dc5116e243b6f9909ac Mon Sep 17 00:00:00 2001 From: Misode Date: Thu, 20 Oct 2022 05:22:38 +0200 Subject: [PATCH] Fix #295 handle invalid values in set_count --- src/app/Utils.ts | 2 +- src/app/previews/Decorator.ts | 6 +++--- src/app/previews/LootTable.ts | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/Utils.ts b/src/app/Utils.ts index f65b0ad4..ce119830 100644 --- a/src/app/Utils.ts +++ b/src/app/Utils.ts @@ -183,7 +183,7 @@ export function square(a: number) { } export function clamp(a: number, b: number, c: number) { - return Math.max(a, Math.min(b, c)) + return Math.max(b, Math.min(a, c)) } export function clampedLerp(a: number, b: number, c: number): number { diff --git a/src/app/previews/Decorator.ts b/src/app/previews/Decorator.ts index 68f1043c..52d16f76 100644 --- a/src/app/previews/Decorator.ts +++ b/src/app/previews/Decorator.ts @@ -69,9 +69,9 @@ export function decorator(state: any, img: ImageData, options: DecoratorOptions) if (pos[0] < 0 || pos[1] < 0 || pos[2] < 0 || pos[0] >= options.size[0] || pos[1] >= options.size[1] || pos[2] >= options.size[2]) continue const i = (pos[2] * (img.width * 4)) + (pos[0] * 4) const color = feature < featureColors.length ? featureColors[feature] : stringToColor(ctx.features[feature]) - data[i] = clamp(50, 205, color[0]) - data[i + 1] = clamp(50, 205, color[1]) - data[i + 2] = clamp(50, 205, color[2]) + data[i] = clamp(color[0], 50, 205) + data[i + 1] = clamp(color[1], 50, 205) + data[i + 2] = clamp(color[2], 50, 205) data[i + 3] = 255 } diff --git a/src/app/previews/LootTable.ts b/src/app/previews/LootTable.ts index ca58dfda..76e623f8 100644 --- a/src/app/previews/LootTable.ts +++ b/src/app/previews/LootTable.ts @@ -46,6 +46,7 @@ export function generateLootTable(lootTable: any, options: LootOptions) { const ctx = createLootContext(options) const result: Item[] = [] generateTable(lootTable, item => result.push(item), ctx) + console.log('...', result) const mixer = StackMixers[options.stackMixer] return mixer(result, ctx) } @@ -303,8 +304,9 @@ const LootFunctions: Record LootFunction> = { const { min, max } = prepareIntRange(limit, ctx) item.count = clamp(item.count, min, max ) }, - set_count: ({ count }) => (item, ctx) => { - item.count = computeInt(count, ctx) + set_count: ({ count, add }) => (item, ctx) => { + const oldCount = add ? (item.count) : 0 + item.count = clamp(oldCount + computeInt(count, ctx), 0, 64) }, set_damage: ({ damage, add }) => (item, ctx) => { const maxDamage = MaxDamageItems.get(item.id)