From 716f806b288a0b1230a4ab9dd0a7a3a17341c1e6 Mon Sep 17 00:00:00 2001 From: Xterionix <72647213+Xterionix@users.noreply.github.com> Date: Tue, 19 Sep 2023 06:26:21 +0500 Subject: [PATCH] - Add back item equipped sensor, but versioned --- app/renderer/src/bridgeCore/ItemHandler.ts | 91 ++++++++++++---------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/app/renderer/src/bridgeCore/ItemHandler.ts b/app/renderer/src/bridgeCore/ItemHandler.ts index 964ccc9a..292c3344 100644 --- a/app/renderer/src/bridgeCore/ItemHandler.ts +++ b/app/renderer/src/bridgeCore/ItemHandler.ts @@ -6,6 +6,7 @@ import ItemEquippedSensor from './item/ItemEquippedSensor' import { OnSaveData } from './main' import { promises as fs } from 'fs' import { iterateEvents } from './events/iterate' +import compareVersions from 'compare-versions' declare const __static: string export type ItemComponentData = Partial< @@ -64,17 +65,6 @@ export default async function ItemHandler({ `animation_controllers/bridge/custom_item_behavior.json` ) - //Make sure player file exists - //try { - // await fs.stat(player_file_path) - //} catch { - // await fs.mkdir(dirname(player_file_path), { recursive: true }) - // await fs.copyFile( - // join(__static, 'vanilla/BP/entities/player.json'), - // player_file_path - // ) - //} - //DATA let item = data['minecraft:item'] if (!item) return @@ -83,40 +73,55 @@ export default async function ItemHandler({ set(item, 'events', {}) let { components, description, events } = item - //ADDITIONAL FILES - //let PLAYER_MASK = await JSONFileMasks.get(player_file_path) - //PLAYER_MASK.reset(`item_component@${file_uuid}`) - //let A_C_MASK = await JSONFileMasks.get(a_c_file_path) - //A_C_MASK.reset(file_uuid) - //A_C_MASK.set(file_uuid, { - // format_version: '1.10.0', - // animation_controllers: { - // 'controller.animation.bridge_custom_item_behavior': { - // states: { default: {} }, - // }, - // }, - //}) + if (compareVersions.compare(data["format_version"], '1.16.0', '<=')) { + + //Make sure player file exists + try { + await fs.stat(player_file_path) + } catch { + await fs.mkdir(dirname(player_file_path), { recursive: true }) + await fs.copyFile( + join(__static, 'vanilla/BP/entities/player.json'), + player_file_path + ) + } + + //ADDITIONAL FILES + let PLAYER_MASK = await JSONFileMasks.get(player_file_path) + PLAYER_MASK.reset(`item_component@${file_uuid}`) + let A_C_MASK = await JSONFileMasks.get(a_c_file_path) + A_C_MASK.reset(file_uuid) + A_C_MASK.set(file_uuid, { + format_version: '1.10.0', + animation_controllers: { + 'controller.animation.bridge_custom_item_behavior': { + states: { default: {} }, + }, + }, + }) - //READ COMPONENTS - //for (let c in components) { - // const shouldRemove = transformComponents({ - // component_name: c, - // component: components[c], - // identifier: description.identifier || 'bridge:no_identifier', - // PLAYER_MASK, - // A_C_MASK, - // file_uuid, - // components, - // }) - // - // if (shouldRemove) delete components[c] - //} + //READ COMPONENTS + for (let c in components) { + const shouldRemove = transformComponents({ + component_name: c, + component: components[c], + identifier: description.identifier || 'bridge:no_identifier', + PLAYER_MASK, + A_C_MASK, + file_uuid, + components, + }) - //SAVE ADDITIONAL FILES - //await Promise.all([ - // JSONFileMasks.apply(player_file_path), - // JSONFileMasks.generateFromMask(a_c_file_path, ['default/on_entry']), - //]) + if (shouldRemove) delete components[c] + } + + //SAVE ADDITIONAL FILES + await Promise.all([ + JSONFileMasks.apply(player_file_path), + JSONFileMasks.generateFromMask(a_c_file_path, ['default/on_entry']), + ]) + + } // Needs to be after player file mask so the lightning cache entries actually get added to the item, not the player await iterateEvents(file_uuid, file_name, events)