Skip to content

Commit

Permalink
- Add back item equipped sensor, but versioned
Browse files Browse the repository at this point in the history
  • Loading branch information
Xterionix committed Sep 19, 2023
1 parent 74b7aff commit 716f806
Showing 1 changed file with 48 additions and 43 deletions.
91 changes: 48 additions & 43 deletions app/renderer/src/bridgeCore/ItemHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 716f806

Please sign in to comment.