INJ Docs

Introduction

This page will introduce you briefly about INJ.

What is INJ?

INJ (picked from inject, pronounced as /ɪnˈʤɛ/, similar to "in-j") is a language with progressive design that does not alter the original syntax of Minecraft commands. You can use enhanced features like conditional statements and loops directly in mcfunction files without changing the existing command format.

Progressive design

Given the significant differences between Minecraft commands and typical programming languages, it is likely challenging to find an existing language that can perfectly express the logic of Minecraft commands.

So INJ is designed to be a progressive language, which means it will not alter the original syntax of Minecraft commands. This means you can quickly start to make use of INJ by adding just a little bit of INJ code into your current mcfunction files, leaving the rest of the code as before. With INJ, you can express your logic as before, while altering those parts that are not easy to express in Minecraft commands with INJ logic.

Slight view of INJ

// stone.mcfunction
if ("block ~ ~ ~ stone") {
  say "Here is a stone!"
  setblock ~ ~ ~ minecraft:wool
  say "Now we turn it into a wool!"
}

This code will check if the execution position is a stone, and if so, it will:

  • say "Here is a stone!"
  • turn it into a wool.
  • say "Now we turn it into a wool!"

You can see that except for the logical check part, the rest of the code is just the same as the original Minecraft command.

Then take a look at this:

// circle.mcfunction
for (let i = 0; i < 10; i++) {
  let x = Math.cos(i / 10 * Math.PI * 2) * 10
  let z = Math.sin(i / 10 * Math.PI * 2) * 10
  INJ.run(`particle minecraft:end_rod ~${x.toFixed(2)} ~ ~${z.toFixed(2)} 0 0 0 0 1`);
}

This will create a circle of end rods around the execution position.

Why do I use INJ.run here? Actually, INJ.run doesn't have any special function, it just means to run a Minecraft command at its position. The below two are the same effects:

setblock ~ ~ ~ minecraft:stone
INJ.run("setblock ~ ~ ~ minecraft:stone");

What is special about INJ.run is that you can inject JavaScript code into the Minecraft command it runs. This expands the possibilities of what you can do with INJ. You will learn more about the usage of INJ.run in the INJ.run section later.

Next Steps

If you are a beginner who don't know programming much, you can start with the Step-by-step tutorial.

Or, directly start with qucik-start

On this page