Skip to content

Implement Float Property Truncation Fix plugin and fix finalizeBuild being consumed #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

outercloudstudio
Copy link
Member

@outercloudstudio outercloudstudio commented Mar 2, 2025

Fixes the issue where float properties would be saved by the compiler like this:

"properties": {
	"bridge:test": {
		"type": "float",
		"default": 1,
		"range": [
			-2,
			5
		],
		"client_sync": true
	}
}

While minecraft expected the values to end with a .0.

This optional built in plugin fixes this specific case to instead result in

"properties": {
	"bridge:test": {
		"type": "float",
		"default": 1.0,
		"range": [
			-2.0,
			5.0
		],
		"client_sync": true
	}
}

This plugin is built in as floatPropertyTruncationFix and can be used like

"compiler": {
	"plugins": [
		"generatorScripts",
		"typeScript",
		"entityIdentifierAlias",
		"customEntityComponents",
		"customItemComponents",
		"customBlockComponents",
		"customCommands",
		"moLang",
		"formatVersionCorrection",
		"floatPropertyTruncationFix",
		[
			"simpleRewrite",
			{
				"packName": "My pack name"
			}
		]
	]
}

This would fix
#1162

Update (Added utility for custom compiler extensions to call)

Example usage:

jsonStringifyWithFloatFix(fileContent, [
	{
		pathGlob: 'minecraft:entity/description/properties/*/value',
		apply(path, traversedObjects) {
			if (traversedObjects.length === 0) return false

			if (traversedObjects[traversedObjects.length - 1].type !== 'float') return false

			return true
		},
	},
	{
		pathGlob: 'minecraft:entity/description/properties/*/range/*',
		apply(path, traversedObjects) {
			if (traversedObjects.length < 2) return false

			if (traversedObjects[traversedObjects.length - 2].type !== 'float') return false

			return true
		},
	},
])

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@ThomasOrs
Copy link
Member

@outercloudstudio I think it might be good to move the custom json.stringify replacer into commonutils and expose it to other extensions. Something like a json minifier compiler plugin might yeet the .0 before or after this one.

@outercloudstudio
Copy link
Member Author

Good Idea 👍

@outercloudstudio
Copy link
Member Author

outercloudstudio commented Mar 6, 2025

I think what I can do here, is provide the exact json to string functionality that the extension provides, then also add the spacing options the vanilla JSON.toString provides. In this case of minification, it'll either need to operate on this string or provide its own correction behavior.

@outercloudstudio
Copy link
Member Author

outercloudstudio commented Mar 9, 2025

@ThomasOrs I've exposed the function and made it customizable. Let me know if this looks good. See the example usage.

@outercloudstudio
Copy link
Member Author

Publishing current progress as 0.13.0-beta for testing.

@outercloudstudio outercloudstudio added the bug Something isn't working label Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants