Skip to content

Scripting

Tschipp edited this page Oct 29, 2021 · 42 revisions

Scripting is an advanced method that can be used for many different things.
You could for example make a script that renders all small entities on your shoulders instead of in your hands,
or you could have custom pickup conditions like XP levels, achievements and even positioning in the world.

For versions < 1.16: The scripts are simple json files, that can have any name and must be placed in the config/carryon-scripts/ folder.
For 1.16+: The scripts are simple json files, that can have any name and must be placed in a custom datapack. Inside the datapack, they are located at carryon/scripts/. This means, that if we made a datapack called myname, this would be the path for scripts: datapacks/myname/data/myname/carryon/scripts. You can find out about datapacks on the Minecraft Wiki. You also need to include files like the pack.mcmeta.

Content:

Pickup Object

The pickup object refers to which objects this script are affected by. The object can either be of type block or entity.

Block

Blocks can be specified using name for the blockname, meta for meta value, nbt for any NBT Tags. NBT structure works like vanilla's default nbt structure.
Blocks can also have a material type, which can be used to specify a block material. Valid material names here.
Blocks can also be matched based on resistance, meaning explosion resistance and hardness, meaning break time.

Entity

Entites also have a name type, which is used to specifiy the name. The height and weight types can be used to specify dimensions of the entity. They can, like blocks, be matched on nbt. They can also be matched based on health.

Examples

This probably sounds very strange, so let's explain with some examples.

{
	"object": 
	{
		"block":
		{
			"name" : "minecraft:gold_block"		
		}
	}
}

This script runs for Minecraft's Gold Block.

{
	"object": 
	{
		"block":
		{
			"hardness" : ">=1"		
		}
	}
}

This script runs for any block with a hardness value that's greater than or equal to 1 These types can be combined in any way.

{
	"object": 
	{
		"block":
		{
			"hardness" : ">=1",
			"material" : "rock",
			"meta" : "<=11",
			"nbt" : 
			{
				"SomeString" : "foo",
				"SomeInt" : 2
			}
		}
	}
}

This script runs for any block with a hardness that's greater than or equal to 1, has the material "rock" (like stone, bricks..), has a meta value that's below or equal to 11, and has an NBT tag with two tags, one called "SomeString" and one called "SomeInt". So as you can see, they can get very specific.

{
	"object": 
	{
		"entity":
		{
			"width" : "<=1",
			"height" : "<1.2",
			"health" : ">=20",
			"nbt" : 
			{
				"SomeString" : "foo",
				"SomeInt" : 2
			}
		}
	}
}

Likewise, for entities.

Conditions

The Pickup Object specify which scripts apply for which objects. The conditions check, if the player is allowed to carry said object. These are all possible conditions:

  • advancement (called achievement in versions < 1.12) A simple string, which symbolizes which achievement must be unlocked.
  • gamemode
    A numeric value, that specifies which gamemode the player must have.
  • gamestage
    A string, that corresponds to a Game Stage that must be unlocked. This of course only works if GameStages is actually installed.
  • position
    An advanced string, that states the position where the player must stand in the world.
  • xp
    A numeric value that determines, how many levels the player must have.
  • scoreboard
    A scoreboard score that the player must have.
  • effects
    A series of potion effects that the player must have.

Example

{
	"object": 
	{
		"block":
		{
			"name" : "minecraft:gold_block"		
		}
	},
	"conditions":
	{
		"xp" : "<=3",
		"advancement" : "minecraft:bake_cake",
		"gamemode" : 0,
		"gamestage" : "gold_blocks",
		"scoreboard" : "gold_score=32",
		"position" : "x=30,y=72,z=125,dx=65,dy=20,dz=200"
	}
}

This advanced example uses all possible conditions to determine, if the player should be able to pick up a gold block. The player will be able, if they have less than or equal to 3 levels, they have unlocked the achievement "bake cake", the are in survival mode, they have unlocked the gamestage "gold_block", have a scoreboard value of exactly 32 for the objective "gold_score" and are situated in a box from x=30,y=72,z=125 to x=95,y=92,z=325. The d-coordinates get added to the base coordinates. In 1.12+, the achievement condition is called advancement.

Render

Render can be used to change every aspect of how the object is rendered.
Important: Blocks must always be rendered as blocks, and entities must always be rendered as entites! Possible render options:

  • name_block
    The name of the block, that will be rendered.
  • name_entity
    The name of the entity, that will be rendered.
  • meta
    The metadata of the block, that will be rendered (does nothing with entities).
  • nbt
    A nbt tag, that the object will be rendered with. Can apply to both entities and blocks.
  • translation
    An advanced string, that specifies how the render will be translated.
  • rotation
    An advanced string, that specifies how the render will be rotated.
  • scale
    An advanced string, that specifies how the render will be scaled.
  • rotation_left_arm
    An advanced string, that specifies how the left arm will be rotated.
  • rotation_right_arm
    An advanced string, that specifies how the right arm will be rotated.
  • render_left_arm
    A boolean (true,false) that specifies, if the left arm should be rendered. If false, the vanilla arm renders.
  • render_right_arm
    A boolean (true,false) that specifies, if the right arm should be rendered. If false, the vanilla arm renders.

Effects

You can make scripts execute any command. Possible effects:

  • commandPickup
    This command gets executed once, when the player picks up the object.
  • commandLoop
    This command gets executed every tick while the player is carrying the object.
  • commandPlace
    This command gets exectued once, when the player places the object.

All commands get executed as the player at the position of the player.

Special formats

All tags, that accept numbers (except render's meta), accept conditional numbers, like <=3 "less than or equal to 3", >12 "greater than 12", =20 "equals 20" and just 20 (also "equals 20).

Some tags ask for more than one number (position, translation, rotation, scale, rotation_left_arm, and rotation_right_arm) These numbers must come in a format like: x=20,y=40,z=422 or x=12,z=34. Any values can be left out. position requires at least one d-value: x=20,z=20,dx=100,dz=200. In this example, the y-value is ignored.

More Examples

{
	"object": 
	{
		"block":
		{
			"name" : "minecraft:gold_block"		
		}
	},
	"conditions":
	{
		"xp" : "<=3",
                "effects" : "minecraft:strength#1"
	}
}

In this example, the player can pick up gold blocks, if they have more than 2 levels and strength II is active.

{
	"object": 
	{
		"entity":
		{
			"width" : "<=0.5",
			"height" : "<=1"
		}
	},
	"render":
	{
		"translation" : "y=0.7,x=-0.5,z=-0.7",
		"render_left_arm" : false,
		"render_right_arm" : false,
		"scale" : "x=0.5,y=0.5,z=0.5"
	}

}

In this example, all smaller entities are scaled down, and placed on the player's shoulder. Arm rendering is also disabled.

{
	"object": 
	{
		"entity":
		{
			"name" : "minecraft:bat"		
		}
	},
	"render":
	{
		"name_entity" : "minecraft:ender_dragon",
		"scale" : "x=0.5,y=0.5,z=0.5",
		"translation" : "y=-0.1,z=2",
		"rotation" : "y=180"
	}
}

In this example, the bat render is replaced with the ender dragon, and it's rescaled, translated and rotated a bit.

{
	"object":
	{
		"block":
		{
			"name" : "minecraft:cactus"
		}
	},
	"effects":
	{
		"commandPickup" : "effect give @p minecraft:instant_damage 1 0",
		"commandLoop" : "me is carrying a cactus!",
		"commandPlace" : "say @p placed the cactus!"
	}
}

In this example, the player gets hur once when they pick up the cactus, when they are carrying they spam the /me command and when they place it down, they execute the /say command.

{
	"object": 
	{
		"block":
		{
			"material" : "rock",
			"hardness" : ">=1.1"
		}
	},
	"conditions":
	{
		"gamemode" : "<=1",
		"position" : "x=212,z=128,dx=200,dz=400",
		"scoreboard" : "rock_lifter>=20",
                "effects" : "minecraft:night_vision#0,minecraft:speed#2"
	},
	"render":
	{
		"scale" : "x=3,y=3,z=3",
		"translation" : "z=-1.5,y=1.1",
		"block_name" : "minecraft:stone",
		"meta" : 1
	}
}

This final example pretty much combines everything. It applies to block with material type "rock" and hardness above 1.1. The player needs to be gamemode 0 or 1, be standing in a specific part of the world, and have the score "rock_lifter" of at least 20. They also need to have Night vision I and Speed III The block then gets enlarged, rescaled and rendered as stone with a meta of 1, meaning granite. Feel free to try any of these scripts.