Skip to content

An extended minecraft function format for datapack makers

License

Notifications You must be signed in to change notification settings

benazarenko/MCE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCE

An extended minecraft function format for datapack makers

About MCE

MCE is an extension of mcfunction files that are used in Minecraft datapacks. An mce file uses additional syntax that allows it to be split into multiple mcfunction files. You can also say that it combines multiple mcfunction files into one single mce file.

Motivation

Why would you need this? It's simple - doing datapack logic requires you to write multiple files and calling them using selectors. The most horrible thing here is controlling it's logic in real time. It's easy to do with main file and 1-2 subfiles. But let's say you create a minigame, and of course you will write a state machine to make it work. Now imagine how many states do you need to make for a simple game with lobby and a start game button? A simple gungame I made had 5 states with 6 separate mcfunction files. You physically can't control these much information with it being in separate files. Using MCE format makes it 200% easier to control any datapack state machine.

Another thing I found MCE useful with is dealing with multiple files with copy/paste code. Same gungame, but now you want to add different classes - soldier, sniper, medic, etc. All of them have copy/paste code inside for initialization and some different lines that give items the players need to have. But after some time I decided to change the default meele weapon they had. I had to open every file and change it by hand. I could have used bulk find/replace but I don't trust these things unless I do it to a single file (who knows what else it will change, and usually text editors won't let you undo bulk replace changes). With MCE I did it with a simple Replace All in a single file. The other way to solve this problem was refactoring the code to move copy/paste parts into a separate file. But we again stumble into growing amount of files problem.

Requirements

  • Python >=3.6

Syntax and Usage

The mce file consists of begin/end blocks with filename definitions after def keyword. Inside these blocks you can write any mcfunction code, including comments. All of it will be transfered to the mcfunction file as you write it. The only thing that will be trimmed is the indentation.

If you want to create a file with the same name and in the same folder as the mce file is, you need to write def __main__. Every other mcfunction file will be placed in a folder with the name of your mce file.

After creating your mce file you need to run a translator. It requires python3 to run. There are ready to use scripts in releases for Windows and Linux. Unzip them and run the script. It will process every mce file in the folder and it's subfolders.

USE WITH CAUTION! Sometimes you might want to be sure that your destination folder is empty, for cleanup purpose. You can write clean at the first line. When translator sees this word, it will remove every file in the mce subfolder and the subfolder itself. Then it will create the folder and place files inside. Might be useful if you don't want to keep old files when renaming/removing definitions in mce. It will remove EVERY file and folder in the subfolder. Be sure you don't have anything important inside.

Let's see this test.mce file example here:

clean
def file1 begin
	effect clear @s minecraft:resistance
end

def file2 begin
	effect clear @s minecraft:slowness
	effect clear @s minecraft:darkness
end

def __main__ begin
	effect clear @s minecraft:slowness
	effect clear @s minecraft:darkness
end

Processing this will remove folder test and create 3 mcfunction files:

.
├── test.mcfunction
└── test/
    ├── file1.mcfunction
    └── file2.mcfunction

The file contents are the same as in the def blocks you see in the test.mce file with corresponding names.

FAQ

  • You can use words begin, end, clean and def as filenames.
  • Every generated file will have a comment line that it was autogenerated from an .mce file.
  • The translator will ignore empty files, but won't ignore empty begin/end blocks.
  • The translator will ignore everything you write between blocks.
  • Coding style doesn't matter. You can write begin at the end of def line, or at the new line.
  • Every end should be the only word in a line for it to match.
  • The translator doesn't validate the mcfunction code or filenames. It'll return an error if you break the system rules, or if try to process the files with spaces and forbidden symbols. For more information, see here.

Contributing

If you want to help me out, write a fix, add new functionality (not sure if there's anything new to add here, but anyway), change existing behavior - you're always welcome! I'm open to any new ideas. If you want to discuss something personaly then see the links in my profile.

About

An extended minecraft function format for datapack makers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages