From e4617df6ea10261cc0d49aaf3f8128c7255c4267 Mon Sep 17 00:00:00 2001 From: leaftail1880 <110915645+leaftaul1880@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:30:04 +0300 Subject: [PATCH] fix: blending --- src/modules/world-edit/tools/create-region.ts | 40 ++++++------- src/modules/world-edit/tools/multi-brush.ts | 14 +++-- src/modules/world-edit/tools/multi-shovel.ts | 25 ++++---- src/modules/world-edit/tools/shovel.ts | 58 +++++++++---------- src/modules/world-edit/utils/blending.ts | 7 +-- 5 files changed, 69 insertions(+), 75 deletions(-) diff --git a/src/modules/world-edit/tools/create-region.ts b/src/modules/world-edit/tools/create-region.ts index 3ae2bc24..ca81531c 100644 --- a/src/modules/world-edit/tools/create-region.ts +++ b/src/modules/world-edit/tools/create-region.ts @@ -1,4 +1,4 @@ -import { ContainerSlot, Player } from '@minecraft/server' +import { ContainerSlot, ItemStack, Player } from '@minecraft/server' import { createableRegions, ModalForm, Region } from 'lib' import { Items } from 'lib/assets/custom-items' import { ActionbarPriority } from 'lib/extensions/on-screen-display' @@ -55,31 +55,27 @@ class RegionTool extends WorldEditTool { }) } - constructor() { - super() + onUse(player: Player, _: ItemStack, storage: Storage): void { + if (!storage.regionKind) return - this.onInterval(10, (player, storage) => { - if (!storage.regionKind) return - - const createableRegion = createableRegions.find(e => e.region.kind === storage.regionKind) - if (!createableRegion) - return player.onScreenDisplay.setActionBar( - `§cUnknown region type: ${storage.regionKind}`, - ActionbarPriority.UrgentNotificiation, - ) + const createableRegion = createableRegions.find(e => e.region.kind === storage.regionKind) + if (!createableRegion) + return player.onScreenDisplay.setActionBar( + `§cUnknown region type: ${storage.regionKind}`, + ActionbarPriority.UrgentNotificiation, + ) - const regions = storage.minDistanceSameKind ? createableRegion.region.instances() : Region.regions - if (regions.some(r => r.area.isNear(player.location, storage.minDistance))) - return player.onScreenDisplay.setActionBar(`§7Рядом другие регионы`, ActionbarPriority.PvP) + const regions = storage.minDistanceSameKind ? createableRegion.region.instances() : Region.regions + if (regions.some(r => r.area.isNear(player.location, storage.minDistance))) + return player.onScreenDisplay.setActionBar(`§7Рядом другие регионы`, ActionbarPriority.PvP) - createableRegion.region.create( - new SphereArea({ center: player.location, radius: storage.radius }, player.dimension.type), - ) + createableRegion.region.create( + new SphereArea({ center: player.location, radius: storage.radius }, player.dimension.type), + ) - const msg = t`§aРегион создан!` - player.success(msg) - player.onScreenDisplay.setActionBar(msg, ActionbarPriority.UrgentNotificiation) - }) + const msg = t`§aРегион создан!` + player.success(msg) + player.onScreenDisplay.setActionBar(msg, ActionbarPriority.UrgentNotificiation) } } diff --git a/src/modules/world-edit/tools/multi-brush.ts b/src/modules/world-edit/tools/multi-brush.ts index c1327fa1..9b301c32 100644 --- a/src/modules/world-edit/tools/multi-brush.ts +++ b/src/modules/world-edit/tools/multi-brush.ts @@ -12,12 +12,16 @@ class MultiBrushTool extends WorldEditMultiTool { typeId = Items.WeBrush onUse(player: Player, itemStack: ItemStack, storage: ToolsDataStorage | undefined) { - this.forEachTool(itemStack, (proxiedItem, tool, toolData) => { - if (!tool.onUse) return + this.forEachTool( + itemStack, + (proxiedItem, tool, toolData) => { + if (!tool.onUse) return - const proxiedPlayer = storage?.spread ? this.proxyPlayer(player, storage.spread) : player - tool.onUse(proxiedPlayer, proxiedItem, toolData) - }) + const proxiedPlayer = storage?.spread ? this.proxyPlayer(player, storage.spread) : player + tool.onUse(proxiedPlayer, proxiedItem, toolData) + }, + storage?.tools, + ) } private proxyPlayer(player: Player, spread: number): Player { diff --git a/src/modules/world-edit/tools/multi-shovel.ts b/src/modules/world-edit/tools/multi-shovel.ts index 070ec3f4..dbb32506 100644 --- a/src/modules/world-edit/tools/multi-shovel.ts +++ b/src/modules/world-edit/tools/multi-shovel.ts @@ -1,5 +1,6 @@ +import { ItemStack, Player } from '@minecraft/server' import { Items } from 'lib/assets/custom-items' -import { WorldEditMultiTool } from '../lib/world-edit-multi-tool' +import { ToolsDataStorage, WorldEditMultiTool } from '../lib/world-edit-multi-tool' import { WorldEditTool } from '../lib/world-edit-tool' import { weRegionTool } from './create-region' import { weShovelTool } from './shovel' @@ -11,19 +12,15 @@ class MultiShovelTool extends WorldEditMultiTool { name = 'Мульти-лопата' typeId = Items.WeShovel - constructor() { - super() - this.onInterval(10, (player, storage, slot, settings) => { - this.forEachTool( - slot, - (proxiedSlot, tool, toolStorage) => { - if (!tool.interval10) return - - tool.interval10(player, toolStorage.d, proxiedSlot, settings) - }, - storage.tools, - ) - }) + onUse(player: Player, item: ItemStack, storage: ToolsDataStorage): void { + this.forEachTool( + item, + (proxiedItem, tool, toolStorage) => { + if (!tool.onUse) return + tool.onUse(player, proxiedItem, toolStorage.d) + }, + storage.tools, + ) } } diff --git a/src/modules/world-edit/tools/shovel.ts b/src/modules/world-edit/tools/shovel.ts index f854f3e2..63fdfe2b 100644 --- a/src/modules/world-edit/tools/shovel.ts +++ b/src/modules/world-edit/tools/shovel.ts @@ -1,4 +1,4 @@ -import { ContainerSlot, Player, world } from '@minecraft/server' +import { ContainerSlot, ItemStack, Player, world } from '@minecraft/server' import { ModalForm, Vector } from 'lib' import { Items } from 'lib/assets/custom-items' import { ActionbarPriority } from 'lib/extensions/on-screen-display' @@ -107,39 +107,37 @@ class ShovelTool extends WorldEditTool { } } }) - this.onInterval(10, (player, storage) => { - if (this.isLookingUp(player)) return - - const permutations = getBlocksInSet(storage.blocksSet) - if (!permutations.length) - return player.onScreenDisplay.setActionBar( - '§cНабор блоков лопаты пустой!', - ActionbarPriority.UrgentNotificiation, - ) + } - const { offset, radius, height } = storage - const replaceTargets = getReplaceTargets(storage.replaceBlocksSet) - const center = Vector.floor(player.location) - const from = Vector.add(center, new Vector(-radius, offset - height, -radius)) - const to = Vector.add(center, new Vector(radius, offset, radius)) - - WorldEdit.forPlayer(player).backup( - `§eЛопата §7радиус §f${radius} §7высота §f${height} §7сдвиг §f${ - offset - }\n§7блоки: §f${stringifyBlockWeights(permutations.map(toReplaceTarget))}`, - from, - to, - ) + onUse(player: Player, _: ItemStack, storage: Storage) { + if (this.isLookingUp(player)) return - for (const vector of Vector.foreach(from, to)) { - if (skipForBlending(storage, { vector, center })) continue + const permutations = getBlocksInSet(storage.blocksSet) + if (!permutations.length) + return player.onScreenDisplay.setActionBar('§cНабор блоков лопаты пустой!', ActionbarPriority.UrgentNotificiation) - const block = world.overworld.getBlock(vector) - if (!block) continue + const { offset, radius, height } = storage + const replaceTargets = getReplaceTargets(storage.replaceBlocksSet) + const center = Vector.floor(player.location) + const from = Vector.add(center, new Vector(-radius, offset - height, -radius)) + const to = Vector.add(center, new Vector(radius, offset, radius)) - replaceWithTargets(replaceTargets, getReplaceMode(storage.replaceMode), block, permutations) - } - }) + WorldEdit.forPlayer(player).backup( + `§eЛопата §7радиус §f${radius} §7высота §f${height} §7сдвиг §f${ + offset + }\n§7блоки: §f${stringifyBlockWeights(permutations.map(toReplaceTarget))}`, + from, + to, + ) + + for (const vector of Vector.foreach(from, to)) { + if (skipForBlending(storage, { vector, center })) continue + + const block = world.overworld.getBlock(vector) + if (!block) continue + + replaceWithTargets(replaceTargets, getReplaceMode(storage.replaceMode), block, permutations) + } } private isLookingUp(player: Player) { diff --git a/src/modules/world-edit/utils/blending.ts b/src/modules/world-edit/utils/blending.ts index d4fab765..b9545b2f 100644 --- a/src/modules/world-edit/utils/blending.ts +++ b/src/modules/world-edit/utils/blending.ts @@ -1,7 +1,7 @@ import { LimitedSet } from 'lib/database/persistent-set' import { Vector } from 'lib/vector' -const blendStorage = new LimitedSet(1_000) +const doNotBlendStorage = new LimitedSet(1_000) const dontBlend = false export function skipForBlending( @@ -21,15 +21,14 @@ export function skipForBlending( const vectorId = Vector.string(vector) if (radius > toBlend) { - if (blendStorage.has(vectorId)) return true + if (doNotBlendStorage.has(vectorId)) return true const blendingFactor = 1 + factor * 0.01 if (Math.randomInt(toBlend, radius) < distance * blendingFactor) { - blendStorage.add(vectorId) return true } } else { - blendStorage.add(vectorId) + doNotBlendStorage.add(vectorId) return true } }