Skip to content

Commit

Permalink
Merge pull request #185 from PuckiSilver/main
Browse files Browse the repository at this point in the history
Implement 1.20.5 component system into data pack exporter
  • Loading branch information
SnaveSutit authored Apr 12, 2024
2 parents f0d9b34 + f539e34 commit 7efdfaa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
11 changes: 11 additions & 0 deletions exporters/datapackExporter/datapackExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export function loadExporter() {
}
}
),
use_component_system: new Settings.CheckboxSetting({
id: 'animated_java:datapack_exporter/use_component_system',
displayName: TRANSLATIONS.use_component_system.name,
description: TRANSLATIONS.use_component_system.description,
defaultValue: false,
docsLink: '/docs/exporters/datapack_exporter/settings#use_component_system',
}),
// Function Toggles
include_variant_summon_functions: new Settings.CheckboxSetting({
id: 'animated_java:datapack_exporter/include_variant_summon_functions',
Expand Down Expand Up @@ -157,6 +164,10 @@ export function loadExporter() {
type: 'setting',
settingId: 'animated_java:datapack_exporter/root_entity_nbt',
},
{
type: 'setting',
settingId: 'animated_java:datapack_exporter/use_component_system',
},
{
type: 'group',
title: TRANSLATIONS.function_toggles_group.title,
Expand Down
26 changes: 16 additions & 10 deletions exporters/datapackExporter/exporter/gen/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function getExportVersionId() {
function generateBonePassenger(uuid: string, bone: AnimatedJava.IRenderedNodes['Bone']) {
const passenger = deepslate.NbtTag.fromString(bone.nbt) as NbtCompound
const default_pose = G.exportData.rig.defaultPose.find(pose => pose.uuid === uuid)
const useComponents = G.exportData.exporterSettings.use_component_system.value

passenger.set('id', new deepslate.NbtString('minecraft:item_display'))

Expand All @@ -30,11 +31,11 @@ function generateBonePassenger(uuid: string, bone: AnimatedJava.IRenderedNodes['
if (!passenger.get('item')) passenger.set('item', new deepslate.NbtCompound())
const item = passenger.get('item') as InstanceType<typeof deepslate.NbtCompound>
item.set('id', new deepslate.NbtString(G.RIG_ITEM))
.set('Count', new deepslate.NbtByte(1))
.set(useComponents ? 'count' : 'Count', new deepslate.NbtByte(1))
.set(
'tag',
useComponents ? 'components' : 'tag',
new deepslate.NbtCompound().set(
'CustomModelData',
useComponents ? 'minecraft:custom_model_data' : 'CustomModelData',
new deepslate.NbtInt(bone.customModelData)
)
)
Expand Down Expand Up @@ -82,6 +83,7 @@ function generateLocatorPassenger(
) {
const { roundToN } = AnimatedJava.API
const passenger = deepslate.NbtTag.fromString(locator.nbt) as NbtCompound
const useComponents = G.exportData.exporterSettings.use_component_system.value
// const default_pose = G.exportData.rig.defaultPose.find(pose => pose.uuid === uuid)

passenger
Expand All @@ -99,10 +101,10 @@ function generateLocatorPassenger(
'Item',
new deepslate.NbtCompound()
.set('id', new deepslate.NbtString(G.RIG_ITEM))
.set('Count', new deepslate.NbtByte(1))
.set(useComponents ? 'count' : 'Count', new deepslate.NbtByte(1))
.set(
'tag',
new deepslate.NbtCompound().set('CustomModelData', new deepslate.NbtInt(1))
useComponents ? 'components' : 'tag',
new deepslate.NbtCompound().set(useComponents ? 'minecraft:custom_model_data' : 'CustomModelData', new deepslate.NbtInt(1))
)
)
.set(
Expand Down Expand Up @@ -196,6 +198,7 @@ function generateCameraPassenger(
) {
const { roundToN } = AnimatedJava.API
const passenger = deepslate.NbtTag.fromString(camera.nbt) as NbtCompound
const useComponents = G.exportData.exporterSettings.use_component_system.value
// const default_pose = G.exportData.rig.defaultPose.find(pose => pose.uuid === uuid)

passenger
Expand All @@ -213,10 +216,10 @@ function generateCameraPassenger(
'Item',
new deepslate.NbtCompound()
.set('id', new deepslate.NbtString(G.RIG_ITEM))
.set('Count', new deepslate.NbtByte(1))
.set(useComponents ? 'count' : 'Count', new deepslate.NbtByte(1))
.set(
'tag',
new deepslate.NbtCompound().set('CustomModelData', new deepslate.NbtInt(1))
useComponents ? 'components' : 'tag',
new deepslate.NbtCompound().set(useComponents ? 'minecraft:custom_model_data' : 'CustomModelData', new deepslate.NbtInt(1))
)
)
.set(
Expand Down Expand Up @@ -598,6 +601,7 @@ export function generateFunctions(folders: IFolders) {
const applyVariantsFolder = folders.project.functions.newFolder('apply_variant')
const internalApplyVariantsFolder =
folders.project.internalFunctions.newFolder('apply_variant')
const useComponents = G.exportData.exporterSettings.use_component_system.value
for (const variant of G.VARIANTS) {
// ANCHOR - function G.PROJECT_PATH/apply_variant/<variant_name>
applyVariantsFolder.newFile(`${variant.name}.mcfunction`, [
Expand Down Expand Up @@ -627,9 +631,11 @@ export function generateFunctions(folders: IFolders) {
? node
: G.exportData.rig.variantModels[variant.name][uuid]

const cmdPath = useComponents ? 'item.components.minecraft:custom_model_data' : 'item.tag.CustomModelData'

return `execute if entity @s[tag=${formatStr(G.TAGS.namedBoneEntity, [
node.name,
])}] run data modify entity @s item.tag.CustomModelData set value ${
])}] run data modify entity @s ${cmdPath} set value ${
variantBone.customModelData
}`
}),
Expand Down
6 changes: 6 additions & 0 deletions exporters/datapackExporter/exporter/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export function loadTranslations() {
'animated_java.datapack_exporter.settings.enable_outdated_rig_warning.description'
).split('\n'),
},
use_component_system: {
name: translate('animated_java.datapack_exporter.settings.use_component_system'),
description: translate(
'animated_java.datapack_exporter.settings.use_component_system.description'
).split('\n'),
},
root_entity_nbt: {
name: translate('animated_java.datapack_exporter.settings.root_entity_nbt'),
description: translate(
Expand Down
5 changes: 5 additions & 0 deletions exporters/datapackExporter/lang/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ animated_java.datapack_exporter.settings.enable_outdated_rig_warning: Warnung f
animated_java.datapack_exporter.settings.enable_outdated_rig_warning.description: |-
Ob eine Warnung im Spiel angezeigt werden soll, wenn ein Rig gefunden wird, das vor dem neuesten Export erschaffen wurde.
animated_java.datapack_exporter.settings.use_component_system: Komponentensystem Verwenden
animated_java.datapack_exporter.settings.use_component_system.description: |-
Ob das Komponentensystem für das exportierte Datenpaket verwendet werden soll.
Aktiviere diese Einstellung, damit das Datenpaket in 1.20.5 und neuer funktioniert.
animated_java.datapack_exporter.settings.root_entity_nbt: Ursprungsobjekt NBT
animated_java.datapack_exporter.settings.root_entity_nbt.description: |-
Benutzerdefinierte NBT, die beim Ursprungsobjekt angewendet werden soll.
Expand Down
5 changes: 5 additions & 0 deletions exporters/datapackExporter/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ animated_java.datapack_exporter.settings.enable_outdated_rig_warning: Enable Out
animated_java.datapack_exporter.settings.enable_outdated_rig_warning.description: |-
Whether to show a warning in-game when a Rig is found that was summoned before the most recent export.
animated_java.datapack_exporter.settings.use_component_system: Use Component System
animated_java.datapack_exporter.settings.use_component_system.description: |-
Whether to use the component system for the exported Data Pack.
Enable this setting to make the Data Pack work with 1.20.5 and above.
animated_java.datapack_exporter.settings.root_entity_nbt: Root Entity NBT
animated_java.datapack_exporter.settings.root_entity_nbt.description: |-
Custom NBT to apply to the root entity of the Rig.
Expand Down

0 comments on commit 7efdfaa

Please sign in to comment.