Fix #295 handle invalid values in set_count

This commit is contained in:
Misode
2022-10-20 05:22:38 +02:00
parent 5fe7121ea9
commit f6b6a6bf7d
3 changed files with 8 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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<string, (params: any) => 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)