Lucky Block Documentation

Contents

3.2 Hash Variables

3.2 Hash Variables


Hash variables are a major part of Lucky Block syntax. Hash variables allow for properties to have dynamic values, dependent on a variety of factors relevant to specific hash variables. When the value of a property is processed, all occurrences of a hash variable are first replaced with a real value. The Lucky Block offers a variety of hash variables all of which can be used in different situations. The format of a hash variable is simply a # followed by the variable name.

#varName "This text contains a #varName hash variable"

 

Regular Hash Variables


Below is a table of all the hash variables that can be used in any Lucky Block property value, including in .luckystruct structure files. These hash values can all be used in a variety of situations.

 

Hash Variable Value Example Description
#circleOffset(integer) #circleOffset(integer,integer) (integer, 0, integer) type=entity,ID=Pig,amount=20,
posOffset=#circleOffset(2,3)
Returns X, Y and Z offsets to be used with the offsetPos property, in the format (offsetX, 0, offsetZ). 'offsetY' will always be 0. The offset will cause the entity to spawn in a circle around its position. The properties in the brackets specify the radius of the circle offset, i.e. how far away from central position the entity will spawn. If two properties are specified, the radius will be randomly selected between them.
#bPosX, #bPosY, #bPosZ integer, integer, integer type=entity,ID=Zombie,posX=#bPosX+5 Returns the X, Y and Z coordinates of the position at which the Lucky Block was harvested. These values are by default used as the position of a drop. the example will spawn a zombie 5 blocks to the east of the Lucky Block.
#bPos (integer, integer, integer) type=item,ID=diamond,pos=#bPos Returns the X, Y and Z coordinates the position at which the Lucky Block was harvested in the format (X,Y,Z), for use with the pos and pos2 properties. Added only for completeness, as this is the default position for the pos and pos2 properties, and therefore this hash value will rarely be necessary. The use of it in the example has no effect.
#eval(...) any value type=item,ID=#eval(256+(2*4+9))

Returns an evaluated expression from the text given in the brackets. The expression is evaluated using the JavaScript engine. See 3.2 Complex Values for more information. The example will give a stone shovel after evaluating the expression to 273.

#pPosX, #pPosY, #pPosZ integer, integer, integer type=block,ID=anvil,
posY=#posY+10
Returns the X, Y and Z coordinates of the player at the time of harvesting the Lucky Block. The example will spawn an anvil 10 blocks above the player.
#pPos (integer, integer, integer) type=structure,ID=sponge,
pos=#pPos

Returns the X, Y and Z coordinates of the player at the time of harvesting the Lucky Block in the format (X,Y,Z), for use with the pos and pos2 properties. The example will spawn a sponge at exactly the player's position.

#pName text type=message,ID="Hello there, #pName"

Returns the name of the player who harvested the Lucky Block. The example could output "Hello there, PlayerInDistress".

#pUUID text type=entity,ID=EntityHorse,NBTTag=(OwnerUUID=#pUUID)

Returns the UUID of the player who harvested the Lucky Block. The example spawn a tamed horse.

#pDirect integer type=structure,ID=ship,rotation=#pDirect

Returns a number representing direction toward which the player is facing at the time the Lucky Block is harvested. 0=North, 1=East, 2=South, 3=West.

#pYaw float type=message,ID="Player yaw: #pYaw"

Returns the exact yaw rotation of the player at the time the Lucky Block is harvested. This will be in standard Minecraft format: 180/-180=North, -90=East, 0=South, 90=West and all other values are in between.

#pPitch float type=message,ID="Player pitch: #pPitch"

Returns the exact pitch rotation of the player at the time the Lucky Block is harvested. This will be in standard Minecraft format: 90=Down,0=Straight,-90=Up.

#rand(integer,integer) integer type=item,ID=dye,damage=#rand(0,15)

Returns a random integer between the two integers specified in the brackets, inclusively. The example will drop a dye item with a random color.

#rand(float,float) float type=message,ID="A random float:
#rand(0.0,1.0)
OR
type=message,ID="A random float:
#rand(-10F,-5F)"

Returns a random real (floating point) number between the two floats specified in the brackets, inclusively.

#randPosNeg(integer, integer)
#randPosNeg(float, float)

integer, float type=message,ID="A random pos/neg integer:
#randPosNeg(50,100)"
type=message,ID="A random pos/neg float:
#randPosNeg(2.0,4.0)"

Similarly to #rand, #randPosNeg returns either an integer or real (floating point) number between the two values specified in the brackets, inclusively. This value then has a 50% chance of being positive, and 50% negative.

#randList(value1, value2...) any value type=message,ID="I had a #randList(good,bad) day"

type=item,ID=#randList(gold_ingot,diamond)

Returns a random value selected from the list of values specified in the brackets. The value may be of any type. The first example gives a message saying either "I had a good day or I had a bad day. The second example will either drop a gold ingot or a diamond.

#time integer type=time,ID=#time+1000

Returns the Minecraft world time in ticks. The example sets the time to the current time plus one Minecraft hour.

#ePosX, #ePosY, #ePosZ, #ePos integer type=explosion,delay=5,pos=#ePos

Returns the X, Y and Z coordinates of the entity hit by a Lucky Sword separately or in the format (X,Y,Z). The example will explode the entity 5 seconds after it was hit.

#bowPosX, #bowPosY, #bowPosZ, #bowPos integer type=entity,ID=Arrow,pos=#bowPos,NBTTag=(Motion=#bowMotion)

Returns the exact X, Y and Z coordinates of the position where a projectile should be placed when fired from a bow, separately or in the format (X,Y,Z). This is mainly used by projectiles shot from a Lucky Bow. The example will cause a Lucky Bow to shoot an arrow.

#bExactPos, #pExactPos, #eExactPos, #bExactPosX, #bExactPosY, #bExactPosZ etc. integer type=entity,ID=Zombie,pos=#pExactPos

Similar to all other position hash variables, but returns exact decimal coordinates instead.

 

Specific Hash Values


The hash values listed below are no different to regular hash values, except that they are designed for only one specific purpose.

 

Hash Variable Value Example Description
#randPotionDamage integer type=item,ID=potion,
damage=#randPotionDamage

Returns a random integer to be used as the damage value of a Minecraft potion. Any potion that can be brewed in Minecraft can be given using this hash variable.

#randPotionParticle integer type=particle,ID=2002,
damage=#randPotionParticle

Returns a random integer to be used as the damage value of a Minecraft potion breaking animation (See 2.6 Other / Particles). The value will change the color of the potion particles.

#randSpawnEggDamage integer type=spawn_egg,
damage=#randSpawnEggDamage

Returns the damage value of a random Minecraft spawn egg. Any spawn egg can be given using this hash variable.

 

NBT Hash Variables


NBT Hash Variables can only be used within NBT Tags. They will be replaced with a custom-made NBT Tag.

 

Hash Variable Value Example Description
#luckySwordEnchantments, #luckyAxeEnchantments, #luckyToolEnchantments, #luckyBowEnchantments, #luckyFishingRodEnchantments NBT Tag List ID=diamond_sword,NBTTag=(ench=#luckySwordEnchantments),
ID=diamond_axe,NBTTag=(ench=#luckyAxeEnchantments),
ID=diamond_hoe,NBTTag=(ench=#luckyToolEnchantments),
ID=bow,NBTTag=(ench=#luckyBowEnchantments),
ID=fishing_rod,NBTTag=(ench=#luckyFishingRodEnchantments)
Returns an NBT Tag List containing random enchantments to be used with a sword, axe, any tool, bow and fishing rod, respectively.
#luckyHelmetEnchantments, #luckyChestplateEnchantments, #luckyLeggingsEnchantments, #luckyBootsEnchantments NBT Tag List ID=diamond_helmet,NBTTag=(ench=#luckyHelmetEnchantments),
ID=diamond_chestplate,NBTTag=(ench=#luckyChestplateEnchantments),
ID=diamond_leggings,NBTTag=(ench=#luckyLeggingsEnchantments),
ID=diamond_boots,NBTTag=(ench=#luckyBootsEnchantments)
Returns an NBT Tag List containing random enchantments to be used with a helmet, chestplate, leggings and boot, respectively.
#randEnchantment NBT Tag List ID=enchanted_book,NBTTag=(StoredEnchantments=#randomEnchantment) Returns an NBT Tag List containing a single random enchantment. Useful when giving a random enchantment book, as in the example.
#randFireworksRocket NBT Tag Compound type=item,ID=fireworks,NBTTag=#randFireworksRocket

type=entity,ID=FireworksRocketEntity,
NBTTag=(LifeTime=20,FireworksItem=#randFireworksRocket)

Returns an NBT Tag Compound containing random properties of a fireworks item. This can be used directly with both fireworks items and entities (See 2.4 Entities). Entities also require the life (the amount of ticks before the firework explodes) to be specified.

#randLaunchMotion, #randLaunchMotion(power, angle) NBT Tag List type=entity,ID=PrimedTnt,amount=10,
NBTTag=(Fuse=50,Motion=#randLaunchMotion)

type=entity,ID=Arrow,amount=20,
NBTTag=(Motion=#randLaunchMotion(1.5,5))

Returns an NBT Tag List containing the X, Y and Z motion coordinates of an entity. The motion will launch the entity upward. The two value which can be specified in the brackets indicate the power and angle of the motion. This determines how high and how far off from the center the entity will travel when launched. If brackets are not specified, the two values will default to (0.9, 15). The first example will launch 10 TNT into the air with the default values, and the second will launch 20 arrows high and close to the center.

#motionFromDirection(yaw,pitch,power) NBT Tag List type=entity,ID=PrimedTnt,posY=#pExactPosY+0.4,NBTTag=(Fuse=50b,Motion=#motionFromDirection(#pYaw,#pPitch,0.5))

Returns an NBT Tag List containing the X, Y and Z motion coordinates of an entity. The motion will launch the entity in a certain direction defined by the yaw and pitch angles, and with a certain power. The example could be used by a Lucky Sword to launch TNT in the direction the player is facing.

#bowMotion, #bowMotion(power) #bowMotion(power,angleOffset) NBT Tag List type=entity,ID=Arrow,pos=#bowPos,NBTTag=(Motion=#bowMotion)

Returns an NBT Tag List containing the X, Y and Z motion coordinates of an entity. The motion will give a projectile the same motion as it would have when fired by a bow, and is used mainly by projectiles shot from a Lucky Bow. The power can be adjusted, and the offset will give the motion a random angular offset, useful when shooting multiple projectiles. The example will cause a Lucky Bow to shoot an arrow.

#chestVillageBlacksmith
#chestBonusChest
#chestDungeonChest

NBT Tag List type=block,ID=chest,tileEntity=(Items=#chestVillageBlacksmith)
type=block,ID=chest,tileEntity=(Items=#chestBonusChest)
type=block,ID=chest,tileEntity=(Items=#chestDungeonChest)

Returns an NBT Tag List containing item tags to be used with the 'Items' tag in a chest tile entity. This will generate the items of a specific chest type, in the same way as generated within Minecraft.

 

Structure Hash Variables


Certain hash variables may only be used in .luckystruct files (See 2.5 Structures). These provide information about the structure when it is generated. The most common use is when a .luckystruct file contains custom Lucky Block data (See 6.3 Block Data) relating to the structure it is spawned in. Specifically, if the Lucky Block intends to perform a function at certain coordinates relative to the structure, or requires data regarding the way in which it was spawned, these hash variables may be used to attain such information.

 

Hash Variable Value Example Description
#sPosX(x,y,z), #sPosY(x,y,z), #sPosZ(x,y,z) integer OR float posX=#sPosX(1,0,1)

Converts the given structure coordinates to the final world coordinates of the generated structure. Returns the resulting X, Y or Z coordinates for each hash variable, respectively. The return values will be floats if any of the given values is a float, and otherwise integers.

#sPos(x,y,z) (integer,integer,integer) OR (float,float,float) pos=#sPos(2,3,0)

Converts the given structure coordinates to the final world coordinates of the generated structure. Returns the resulting X, Y or Z coordinates in the format (X,Y,Z), for use with the pos and pos2 properties. The return value will consist of floats if any of the given values is a float, and otherwise integers.

#drops(name) any value rotation=#drop(rotation)

Returns the value of a property with which the structure was spawned. A name of any Lucky Block property can be provided, and the return value will be the value of the property.

 

The first four properties (#sPos) are used to obtain the final world coordinates that the given structure coordinates will appear in. For example, consider a 3x1x3 flat square structure. The north-most east-most (top-right) corner of the square could be defined as (2,0,2) in structure coordinates. Assume that the center point of the structure is located in the structure's center (1,0,1). If this structure were to be spawned at world coordinates (100,64,100), the north-most east-most corner would appear in world coordinates (101,64,99). The x coordinate increases because the corner is one block to the east (positive X) and the Z coordinate decreases because the corner is one block north (negative Z). Therefore, #sPos(2,0,2) would yield (101,64,99) if the structure where spawned at (100,64,100).

 

Next, it must be considered that structures allow for rotation. The #sPos hash variables also consider this when converting coordinates. For example, assume the previous square example was generated with a rotation of 1 (rotation=1). That is, the structure was rotated one quarter turn clockwise. The north-most east-most (top left) corner would become the south-most east-most (bottom left) corner, and therefore the world coordinates would result in (101,64,101). To complete the example, assume the structure contains a Lucky Block in its center. When the Lucky Block is harvested, it intends to spawn a Zombie in the north-most east-most corner. Below is an example demonstrating how this can be achieved in a .luckystruct file.

1,0,1,lucky:lucky_block,0,tileEntity=(Drops=["type=entity,ID=Zombie,pos=#sPos(2,0,2))"])

Lastly, the final hash variable (#drop) can be used to obtain the value of property with which the structure was spawned based on the provided name. This is the property of the original drop that generated the structure. The hash variable is most commonly used to find the pos and rotation properties and pass them on to a second structure. Consider the original example, and assume that the inner Lucky Block were to spawn a structure instead of an entity. This second structure is to be spawned in the exact same position and rotation as the first. Below is an example of this, also in a .luckystruct file.

1,0,1,lucky:lucky_block,0,tileEntity=(Drops=["type=structure,ID=inner_structure_ID,pos=drop(pos),rotation=#drop(rotation))"])

If the second structure were to have a different position, #sPos could be used instead. Finally, it should be noted that, in this case, #drop(pos) is the same as #sPos(1,0,1). This is because (1,0,1) is the center point of the original structure, and a structure will always be generated at its center point. Also, as noted in 3.1 Complex Values, hash variables in block data generally should be canceled with quotes ('#'hashVariable). This is not the case for these hash variables, as they are meant to be processed when the original structure is created.

 

Chest Hash Variable


The hash variable #chest(...) can be used to randomly generate chest contents. It will return an NBT Tag List containing item tags to be used with the Items tag in a chest tile entity. The generated items will be based on the data provided inside the brackets of the hash variable. The data is in the form of an NBT Tag (See 4. NBT Tags), the format is below.

 

NBT Tag Format: tileEntity=(contents=[(id="text",Damage=integer,tag=(...),minAmount=integer,maxAmount=integer,weight=integer),(...),(...)],maxTotalAmount=integer)

type=block,ID=chest,tileEntity=(Items=#chest(contents=[(id=diamond,maxAmount=5,weight=5),(id=dye,Damage=6,maxAmount=10,weight=10)],maxTotalAmount=5))

This will place a chest containing at most 5 item stacks. Each stack will be either diamonds (id=diamond,maxAmount=5,weight=5) or cyan dye (id=dye,Damage=6,maxAmount=10,weight=10). Dyes will appear twice as commonly as diamonds (weight=5 vs weight=10). maxTotalAmount specifies the maximum amount of item stacks that will spawn in the chest. Each tag in the contents tag list represents an item. The format of the item is the same as in 2.3 Blocks / Chest Examples. Alternatively, see here. However, the Count tag can be omitted, and there are three additional values:

  • minAmount - The minimum stack size of this item that can be spawned in the chest. Defaults to 1.
  • maxAmount - The maximum stack size of this item that can be spawned in the chest. Defaults to 2.
  • weight - The chance that this item will spawn in the chest, relative to the other weights. For example, if all items have a weight of 10 and one has a weight of 5, it will have half the chance of spawning as any other item. Defaults to 1.

type=block,ID=chest,tileEntity=(Items=#chest(contents=[(id=lucky:lucky_block,minAmount=3,maxAmount=5,weight=9),(id=golden_apple,Damage=1,maxAmount=2,weight=3)],maxTotalAmount=6))

This example will place a chest containing Lucky Blocks and enchanted golden apples. Lucky Blocks will appear three times more commonly than golden apples. There will always be 3 to 5 Lucky Blocks in a stack and single golden apples. The maximum amount of item stacks in the chest will be 6.

 

Text Formatting


Text found in Minecraft books, signs, and many other places can be formatted. The color of the text can be changed as well as properties such as bold and italics (See Minecraft formatting codes). This is done using the sector ยง symbol, however the Lucky Block allows for the dollar sign $ to be used instead. Similarly to regular hash variables, the dollar sign will be replaced with a sector sign when the value is processed. Below is an example of text formatting.

type=item,ID=diamond_pickaxe,NBTTag=(display=(Name="#b#lAmazing Pickaxe"))

This will drop a diamond pickaxe with the display name (See 2.2 Items) 'Amazing Pickaxe', in the color aqua and in bold.

 

Canceling Symbols


Both the hash # symbol and the dollar sign $ can be canceled if they are desired in literal form. This allows for the symbols to be displayed as themselves, rather than being replaced with a different value. To cancel a symbol, place single quotes on either side ('#' or '$'). The quotes will be removed when the value is processed, and the symbol will remain as itself. Note that this is generally unnecessary for hash symbols, as they are only replaced when used with specific hash variable text, but there can be cases when canceling is desired if the text is processed multiple times, see 3.1 Complex Values for more information (Note that as of the 1.8 Lucky Block Combat Update, canceling is done automatically in such cases, and can be prevented using [#]). The example below uses a dollar sign in its literal form in a message.

type=message,ID="I found '$'500"

Back Forward

Copyright Minecraft Ascending 2015