Script guide
From AdventureCraft
| Type | Tutorial Script |
| Author(s) | Tyrope and CyborgDragon |
| Date Published | May 11, 2011 |
| Date Updated | ? |
Intro
This guide is written to help two groups of users.
Readers with no previous scripting or coding experience should start at The Bare Basics.
Readers with previous scripting or coding experience, start at AdventureCraft Scripting Features and use Classes and Objects for a reference.
The Bare Basics
So you're new to programming. Let me be the first to welcome you!
Once you realize how a programmer's brain work, you'll be better in JavaScript and AC's script blocks!
Logical Thinking
Normally, when people think of a thing that might happen, they say: "I'm going to say hello when the door opens."
Although this is grammatically correct, a programmer is more likely say: "If the door opens, I'm going to say hello."
This is because of how the syntax, or sentence structure, for most programming and scripting languages work.
Scripting Syntax
Hello World!
Yes, this example has been overused...but it's a good start, so why not! Many languages don't simply output whatever you type. for example, a JavaScript file containing just the words "Hello world" will blow up in your face.
To make JavaScript do something, you must put it in a 'function' or 'method'. The function for showing a message is pretty straight forward.
chat.print("Hello world!");
Let's split this into 3 parts: chat., print(); and "Hello world!"
The chat. part is the 'object' we're going to use, in this case we want to display a message in the chat window, so we use the 'chat' object.
The print(); part is the 'function', functions are parts of the script that actually do something. Most of the functions are either part of JavaScript, or created by Cryect. However, you can define your own functions, but that will come at a later part in the tutorial.
The "Hello world!" is a 'parameter' of the function, parameters are the input of a function, so the structure of this line would be:
object.function(parameter1);
Conditional Statements
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
In JavaScript we have the following conditional statements:
- if
- use this statement to execute some code only if a specified condition is true
- if...else
- use this statement to execute some code if the condition is true and another code if the condition is false
- if...else if....else
- use this statement to select one of many blocks of code to be executed
- switch
- use this statement to select one of many blocks of code to be executed
if
Here, we will go back to the logical thinking bit. Now, let's say you want to show a message when the player dies. You would probably say, "Say 'Game Over!' when the player dies." But a programmer would say, "If player is not alive, say 'Game Over!'"
if (!player.isAlive())
{
chat.print("Game Over!");
}
Let's split this up as well. if() {}, !, player., isAlive(), and chat.print("Game Over!");
The if() {} part is the if statement. Inside the parentheses is your condition, and inside the brackets is what it will do if the conditions are true.
The ! is the not symbol. If the player is not alive.
The player. part is the object. It represents the player.
The isAlive() is the function. It says 'true' if the object running it is alive. "If the player is not alive," becomes "If not true."
The chat.print("Game Over!"); is the parameter. The parameters run when the condition is true.
The structure of an if statement is:
if (condition)
{
parameter1;
parameter2;
parameter3;
etc;
}
if...else
Now, let's say you still want to show a message when the player dies, however you also want something done if the player is still alive.
if (!player.isAlive())
{
chat.print("Game Over!");
} else {
//Player is still alive
}
if...else if...else
This builds on what is learned in the previous
if (var == 0)
{
chat.print("var = 0!");
} else if (var == 1) {
chat.print("var = 1!"):
} else {
chat.print("var = ?!");
}
switch
Alternative to if...else if...else
switch(var)
{
case 0:
chat.print("var = 0!");
break;
case 1:
chat.print("var = 1!"):
break;
default:
chat.print("var = ?!");
break;
}
AdventureCraft Scripting Features
- Scripts for AdventureCraft must be in the .js (JavaScript) format and must be in the scripts folder:
-
AdventureCraft Folder/maps/Your Map/scripts
-
- Simple variables persist between saves in AdventureCraft (includes strings, booleans, and number variables).
- You can assign three scripts globally using the /config command. These are:
- onNewSave, which runs once and only when a new save is created from the map.
- onLoad, which runs once each time the save is loaded.
- onUpdate, which runs every tick, or twentieth a second, when the save is loaded.
- Where textures are used, the filename is from the main map folder, as in "/mob/example.png"
- Where sounds are used, the filename to play a sound like "/sounds/my sound.ogg" would be "sounds.my sound".
- Customizable Mob Spawners have a special variable, spawnedEntities, that is an array of the entities they spawn.
- Script Blocks have their coordinates loaded into xCoord, yCoord, and zCoord.
- Scripts named item_##.js will be executed when the player tries to use an item with the ID ##. For subtypes, it's item_aa_bb.js, where 'aa' is the item ID and 'bb' is the damage value.
- the lastItemUsed variable will contain the item that was last used. Make note that when a scripted item is used and is in the offhand, it is swapped into the main hand for an instant.
- the hitEntity variable will contain the creature that was last hit.
- the hitBlock variable will contain the block that was last hit.
- Scripts named item_onAddToSlot_##.js will be executed when an item with the ID ## is added to a previously empty slot and item_onRemovedFromSlot_##.js when an item stack is removed from a slot. Subtypes work the same way as before.
- the slotID variable will contain the respective slot.
Music Scripts
Using the musicScripts.txt file in your map's folder, you can assign scripts to certain patterns of notes. An example would be:
555, driveMad.js, Song of Madness
Notes can be played using 0-9 on the keyboard. So, the above example would run the script called driveMad.js when the player plays 5 three times. Sharps are played using shift+number. 2, 6, and 9 do not have sharps. To represent sharps in scripts, use shift+number. If you want the player to play 4-sharp 5 7 4-sharp 5 7, you'd use the following:
$57$57, driveMad.js, Song of Madness
Classes and Objects
Chat Object
Functions
print(String msg, Object ...args)
- Prints the string
msgor whatever it's passed.
Effect Object
Functions
spawnParticle(String particleType, double x, double y, double z, double arg1, double arg2, double arg3)
- Spawns a particle of
particleTypeat positionx, y, zwith the argumentsarg1, arg2, arg3and returns the spawned particle as aScriptEntity.
replaceTexture(String textureToReplace, String replacement)
- Attempts to replace the texture
textureToReplacewith the texturereplacementand returnstrueif it is successful.
getReplaceTexture(String replacedTexture)
- Returns the path to the texture that replaces
replacedTexture
revertTextures()
- Reverts all textures to the map defaults.
setOverlay(String overlay)
- Sets the texture
overlayfrom the overlays folder as an overlay on the screen.
getOverlay()
- Returns the overlay currently used.
clearOverlay()
- Removes the overlay if there is any.
setFogColor(float r, float g, float b)
- Sets the fog color to
r, g, b, red green blue values ranging from0to1.
revertFogColor()
- Reverts the fog color to its original state that changes from white to black based on the light level around the player.
setFogDensity(float start, float end)
- Sets the start of the fog to
startdistance. Everything past theenddistance is not rendered.
revertFogDensity()
- Reverts the fog density to its original state that is based on the fog distance settings and auto far clip setting.
getLightRampValue(int i)
- Returns the currently set light ramp value for a light value of
i(0..15).
setLightRampValue(int i, float f)
- Sets the light ramp value for a light value of
itof.
resetLightRampValues()
- Resets all light ramp values to the defaults.
registerTextureAnimation(String animName, String texName, String animatedTex, int x, int y, int width, int height)
- Animates the
animNameimage width ananimatedTexreplacement at thex, ycoordinates of the image width dimensionswidth, heightand nameanimName.
ScriptEntity Class
Class Attributes
These attributes can be manipulated directly.
immuneToFire
- A Boolean for whether this
ScriptEntityis immune to fire or not.
fireLevel
- The amount of time this
ScriptEntitywill burn, in seconds. Divided byfireResistance.
fireResistance
- The divisor for
fireLevel, in seconds.fireLeveldivided byfireResistanceis the amount of time, in seconds, thisScriptEntitywill burn.
air
- The amount of breath this
ScriptEntitycurrently has, in ticks. When this runs out thisScriptEntitywill start drowning.
maxAir
- The amount of breath this
ScriptEntityhas, in ticks, when first entering the water.
stunned
- The amount of time this
ScriptEntityis stunned, in ticks.
collidesWithClipBlocks
- A Boolean for whether this
ScriptEntitycan pass through clip blocks or not.
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
position
- The position of this
ScriptEntity, stored as aScriptVec3.
rotation
- The rotation of this
ScriptEntity, stored as aScriptVecRot.
velocity
- The velocity of this
ScriptEntity, stored as aScriptVec3.
burning
- A Boolean for whether this
ScriptEntityis burning or not.
alive
- A Boolean for whether this
ScriptEntityis alive or not.
riding
- A Boolean for whether this
ScriptEntityis mounted on another entity or not.
sneaking
- A Boolean for whether this
ScritpEntityis sneaking or not.
mountedEntity
- The
ScriptEntitythat thisScriptEntityis mounted on, returnsnullif it isn't mounted.
insideOfWater
- A Boolean for whether this
ScriptEntityis submerged in water or not.
insideOfLava
- A Boolean for whether this
ScriptEntityis submerged in lava or not.
entityID
- An int of the entities ID, read by
yourEntity.entityID.
Methods
getPosition()
- Returns this
ScriptEntity's position as aScriptVec3.
setPosition(double x, double y, double z)
- Sets this
ScriptEntity's position.
getRotation()
- Returns this
ScriptEntity's rotation as aScriptVecRot.
setRotation(float yaw, float pitch)
- Sets this
ScriptEntity's rotation.
getVelocity()
- Returns this
ScriptEntity's velocity as aScriptVec3.
setVelocity(double x, double y, double z)
- Sets this
ScriptEntity's velocity.
addVelocity(double x, double y, double z)
- Adds this velocity to this
ScriptEntity's current velocity.
setDead()
- Kills this
ScriptEntity. Do not use on the player, as it only causes them to stutter. Instead set the player's health to zero.
mountEntity(ScriptEntity e)
- Mount this
ScriptEntityonScriptEntity e.
isBurning()
- Returns
trueif thisScriptEntityis burning.
isAlive()
- Returns
trueif thisScriptEntityisn't dead.
isRiding()
- Returns
trueif thisScriptEntityis mounted on another.
isSneaking()
- Returns
trueif thisScriptEntityis sneaking.
getEntitiesWithinRange(double dist)
- Finds all
ScriptEntitieswithin the rangedistof thisScriptEntityand returns them in an array.
getMountedEntity()
- Returns the
ScriptEntitythat thisScriptEntityis mounted on. If it isn't mounted, returnsnull.
isInsideOfWater()
- Returns
trueif thisScriptEntityis submerged in water.
isInsideOfLava()
- Returns
trueif thisScriptEntityis submerged in lava.
dropItem(Item item)
- Spawns a new item entity from this
ScriptEntityas if it dropped it.
getImmuneToFire()
- Returns
trueif thisScriptEntityis immune to fire.
setImmuneToFire(boolean b)
- Makes this
ScriptEntityimmune to fire ifbistrue or 1, or makes it susceptible to fire ifbisfalse or 0.
getFireLevel()
- Returns the current
fireLevelof thisScriptEntityas an integer.
setFireLevel(int seconds)
- Sets the
fireLevelof thisScriptEntity.fireLeveldivided byfireResistanceis the amount of time, in seconds, that thisScriptEntitywill burn.
getFireResistance()
- Returns the current
fireResistanceof thisScriptEntityas an integer.
setFireResistance(int divisor)
- Sets the
fireResistanceof thisScriptEntity.fireLeveldivided byfireResistanceis the amount of time, in seconds, that thisScriptEntitywill burn.
getAir()
- Returns the amount of breath this
ScriptEntityhas left, as an integer.
setAir(int ticks)
- Sets the amount of breath this
ScriptEntityhas left.
getMaxAir()
- Returns the amount of breath this
ScriptEntitywill have upon being submerged in water, as an integer.
setMaxAir(int ticks)
- Sets the amount of breath this
ScriptEntitywill have upon being submerged in water.
getStunned()
- Returns the amount of time this
ScriptEntityis stunned for, as an integer.
setStunned(int ticks)
- Sets the amount of time this
ScriptEntitywill be stunned for.
attackEntityFrom(ScriptEntity e, int i)
- Makes this
ScriptEntityattackScriptEntity e. Also doesidamage to thisScriptEntity.
getClassType()
- Returns this
ScriptEntity's class type as a string.
getCollidesWithClipBlocks()
- Returns
trueif thisScriptEntitycan't pass through clip blocks.
setCollidesWithClipBlocks(boolean b)
- Sets whether this
ScriptEntitycan pass through clip blocks or not.
EntityLiving Subclass
Class Attributes
These attributes can be manipulated directly.
health
- The health of this
ScriptEntity.
maxHealth
- The maximum health of this
ScriptEntity.
texture
- The texture this
ScriptEntityuses.
hurtTime
- The amount of the time, in ticks, this
ScriptEntitywill be invincible to all damage lower than or equal tohurtTimeResistance.
hurtTimeResistance
- This
ScriptEntitywill be invincible to all damage equal to or less than this value whenhurtTimeis above 0.
heldItem
- The item that will be held by this
ScriptEntity. Only bipeds like skeletons, zombies, and NPCs will actually show the item.
canWallJump
- Can this entity wall jump or not by jumping when colliding against a wall
timesCanJumpInAir
- The number of times this entity can jump in the air
jumpsInAirLeft
- The number of jumps remaining for this entity while in the air (this gets reset to timesCanJumpInAir upon landing)
moveSpeed
- The speed at which the entity moves.
canLookRandomly
- Determines if this entity try to look around randomly. If set to
false, the entity will still look at the player if they are in the entity's FOV.
randomLookRate
- How often will the entity try to look randomly (in ticks)
randomLookRateVariation
- Max amount of ticks to add to the randomLookRate
randomLookVelocity
- How fast will this entity look when randomly looking
randomLookNext
- How many ticks before choosing a new random look velocity
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
onLadder
- A Boolean for whether this
ScriptEntityis on a ladder or not.
target
- The entity that is this
ScriptEntity's target.
lookVec
- The direction this
ScriptEntityis looking, stored as a ScriptVec3.
Methods
playLivingSound()
- If this
ScriptEntityhas a living sound(e.g. pigs snorting, skeletons rattling), play it.
spawnExplosionParticle()
- Spawns 'poof' particles on this
ScriptEntityas if it just spawned or just died.
heal(int i)
- Adds
ihealth to thisScriptEntityup to its max health.
isOnLadder()
- Returns
trueif thisScriptEntityis on a ladder.
getTarget()
- Returns this
ScriptEntity's target as aScriptEntityif it has one, otherwise returnsnull.
getLookVec()
- Returns this
ScriptEntity's view angle as aScriptVec3.
getHealth()
- Returns this
ScriptEntity's current health, as an integer.
setHealth(int i)
- Sets this
ScriptEntity's current health.
getMaxHealth()
- Returns this
ScriptEntity's maximum health, as an integer.
setMaxHealth(int i)
- Sets this
ScriptEntity's maximum health.
getTexture()
- Returns the texture this
ScriptEntityis currently using.
setTexture(string s)
- Sets the texture this
ScriptEntitywill use.
getHurtTime()
- Returns the time, in ticks, remaining for this
ScriptEntity's invincibility.
setHurtTime(int i)
- Sets the time, inticks, this
ScriptEntitywill be invincible toi.
getHurtTimeResistance()
- Returns the amount of damage this entity will resist while invincible during
hurtTime.
setHurtTimeResistance(int i)
- Sets the amount of damage this entity will resist while invincible during
hurtTime.
getHeldItem()
- Returns the
Itemheld by thisScriptEntity.
setHeldItem(Item item)
- Sets the
Itemheld by thisScriptEntitytoitem.
getCanWallJump()
- Returns true if this
ScriptEntitycan wall jump.
setCanWallJump(boolean b)
- Sets whether or not this
ScriptEntitycan wall jump.
getTimesCanJumpInAir()
- Returns with how many times
ScriptEntitycan jump in midair.
setTimesCanJumpInAir(int i)
- Sets the number of times
ScriptEntitycan jump in midair.
getJumpsInAirLeft()
- Returns with how many jumps are remaining for this
ScriptEntityin the air (this gets reset totimesCanJumpInAirupon landing).
setJumpsInAirLeft(int i)
- Sets how many jumps are remaining for this
ScriptEntityin the air (this gets reset totimesCanJumpInAirupon landing).
getMoveSpeed()
- Returns with the speed at which this
ScriptEntitymoves.
setMoveSpeed(int i)
- Sets the speed at which this
ScriptEntitymoves.
EntityCreature Subclass
Class Attributes
These attributes can be manipulated directly.
target
- The
ScriptEntitythat is thisScriptEntity's target.
canPathRandomly
- Determines whether the entity will wander around randomly. This seems to get reset to true on loads.
fov
- Sets the entity's field of view (in degrees)
Methods
setTarget(Entity e)
- Sets this
ScriptEntity's target toScriptEntity e.
getTarget()
- Returns this
ScriptEntity's target as aScriptEntityif it has one, otherwise returnsnull.
hasPath()
- Returns
trueif thisScriptEntityhas a path.
pathToEntity(Entity e)
- Supposed to make this
ScriptEntitymove toScriptEntity e's location, however this method currently does not function as it should.
pathToBlock(int x, int y, int z)
- Supposed to make this
ScriptEntitymove to the position marked byx, y, z, however this method currently does not function as it should.
EntityMob Subclass
Class Attributes
These attributes can be manipulated directly.
attackStrength
- The amount of damage this
ScriptEntitywill do.
Methods
setAttackStrength(int i)
- Sets the amount of damage this
ScriptEntitywill do toi.
getAttackStrength
- Returns the amount of damage this
ScriptEntitywill do.
Arrow Subclass
Class Attributes
These attributes can be manipulated directly.
These are assumed and should be tested, Using Methods would be best.
inBlockID
- An
intof the ID of the block which the arrow is stuck in.
inBlockCoords
- A
ScriptVec3of the position of the block the arrow is stuck in.
isPlayersArrow
- A
Booleanof whether or not the player can pick up the arrow.
getOwner
- A
ScriptEntityto which spawned this arrow.
Methods
getInBlockID()
- Returns the ID of the block the arrow is stuck in.
getInBlockCoords()
- Returns a
ScriptVec3of the position of the block the arrow is stuck in.
getIsPlayersArrow()
- Returns whether or not the player can pick up the arrow.
setIsPlayersArrow(boolean b)
- Sets whether or not the player can pick up the arrow.
getOwner()
- Returns the
ScriptEntitywhich spawned this arrow.
Player Object
Attributes
cloak
This is the string used for the player's cloak. If there is none, this is null.
Methods
getInventory()
- Returns the player's inventory as an
Inventoryobject. This is not a 'static snapshot,' you only need to set one variable to this and it will be updated as the player's inventory changes.
swingMainHand()
- Swings the item in the player's right hand.
swingOffHand()
- Swings the item in the player's left hand.
getCloak()
- Returns the path to the texture currently used for the cloak.
setCloak(string texture)
- Sets the cloak to
texture
Inventory Class
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
sizeInventory
- The size of this
Inventory, an integer that is not zero-based.
name
- The name of the
Inventory. The player's inventory is called 'Inventory', whether this is true for others has yet to be tested.
stackLimit
- The maximum quantity of any stack of
Items for thisInventory.
Methods
getSizeInventory()
- Returns the size of this
Inventory, as an integer that is not zero-based.
getName()
- Returns the name of this
Inventory, as a string.
getStackLimit()
- Returns the maximum quantity
Items in thisInventorycan stack to.
getItemInSlot(int slot)
- Returns the
Iteminslot, if there is noItem, it returnsnull.
decrementItem(int slot, int amount)
- Returns the
Iteminslotafter decrementing its quantity byamount. If there is noItem, it returnsnull.
setSlot(int slot, Item item)
- Puts the
Item itemintoslot.
emptySlot(int slot)
- Removes the
Iteminslotif there is one.
PlayerInventory Subclass
Class Attributes
cursorItem
- The
Itemthat is held by the player's cursor. Isnullif there is nothing.
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
armorValue
- The quantitative value assigned to armor. Full leather armor is five, full diamond is twenty.
currentItem
- The
Itemthat is in the player's right hand. Isnullif there is nothing.
offhandItem
- The
Itemthat is in the player's left hand. Isnullif there is nothing.
Methods
getSlotContainingItem(int itemID)
- Returns the slot that contains an
Itemwith an ID ofitemID. Returns -1 if no matching item is found.
getSlotContainingItemDamage(int itemID, int damage)
- Returns the slot that contains an
Itemwith an ID ofitemIDand a damage value ofdamage. Returns -1 if no matching item is found.
setCurrentItem(int itemID)
- Switches the current item to an
Itemwith the IDitemID, if there is one on the quick bar.
changeCurrentItem(int i)
- Switches the current item to the left if
iis a positive value. Conversely, switches it to the right ifiis a negative value.
consumeItem(int itemID)
- Attempts to consume a single unit of an
Itemwith the IDitemID. Returnstrueif it succeeds.
consumeItemAmount(int itemID, int damage, int amount)
- Attempts to consume
amountof anItemwith the IDitemIDand damage valuedamage. Returnstrueif it succeeds.
getArmorValue()
- Returns the quantitative value assigned to armor, as an integer.
dropAllItems()
- Makes the player's items spill everywhere as if he died.
getCurrentItem()
- Returns the
Itemthat is in the player's right hand. Returnsnullif there is nothing.
getOffhandItem()
- Returns the
Itemthat is in the player's left hand. Returnsnullif there is nothing.
swapOffhandWithMain()
- Swaps the left and right hand.
addItem(Item item)
- Attempts to add
Item itemto the player's inventory and returnstrueif it succeeds.
getCursorItem()
- Returns the
Itemthat is held by the player's cursor. Returnsnullif there is nothing.
setCursorItem(Item item)
- Sets the
Itemthat is held by the player's cursor toitem.
Item Class
Class Attributes
These attributes can be manipulated directly.
itemID
- The ID of this
Item.
quantity
- The quantity of this
Item.
damage
- The damage value of this
Item.
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
maxDamage
- The maximum damage this
Itemwill take before breaking.
Methods
getItemID()
- Returns the ID of this
Item, as an integer.
setItemID(int itemID)
- Sets the ID of this
Item.
getQuantity()
- Returns the quantity of this
Item, as an integer.
setQuantity(int i)
- Sets the quantity of this
Item.
getDamage()
- Returns the damage value of this
Item, as an integer.
setDamage(int i)
- Sets the damage value of this
Item.
getMaxDamage()
- Returns the maximum damage this
Itemcan sustain, as an integer.
copy()
- Returns a copy of this
Itemthat is not bound to a inventory. If you don't use this or one of the constructors to make a newItemobject, any changes you make to anItemwill affect theItemdirectly in the inventory.
Constructors
Item(int itemID)
- Creates a new
Itemobject with the IDitemID, no damage value, and only one in quantity.
Item(int itemID, int quantity)
- Creates a new
Itemobject with the IDitemIDand a quantity ofquantity, with no damage value.
Item(int itemID, int quantity, int damage)
- Creates a new
Itemobject with the IDitemID, a quantity ofquantity, and a damage value ofdamageThedamagevalue could also be used as the ID value of an item (for example Dyes:Item(351,1,5)= Purple Dye).
ScriptVec3 Class
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
x
- The x value of the vector.
y
- The y value of the vector.
z
- The z value of the vector.
Methods
add(ScriptVec3 other)
- Adds
otherto this vector
subtract(ScriptVec3 other)
- Subtracts
otherfrom this vector
length()
- Returns the length of this vector
distance(ScriptVec3 other)
- Returns the distance between the endpoints of the two vectors
scale(double s)
- Multiplies the length of the vector by
s
ScriptVecRot Class
Read-Only Class Attributes
These attributes cannot be manipulated directly, only read.
yaw
- The yaw of this rotation vector.
pitch
- The pitch of this rotation vector.
Sound Object
Functions
playSoundUI(string soundName)
- Plays a normal 2d sound
playSoundUI(string soundName, int volume, int pitch)
- Plays a 2d sound with a set volume and pitch change
playSound3D(string soundName, int x, int y, int z)
- Plays a sound at the specified 3d position
playSound3D(string soundName, int x, int y, int z, int volume, int pitch)
- Plays a sound at the specified 3d position, volume, and pitch change.
playMusic(string musicName)
- Plays the specified music
playMusic(string musicName, int fadeOut, int fadeIn)
- Plays the specified music, with fading out the current playing music over x ms and fades in the new music over y ms.
stopMusic()
- Stops the current music
Time Object
Attributes
These attributes can be manipulated directly.
time
- The currrent time. 6000 is noon, 18000 midnight, 24000 and 0 dawn, and 12000 dusk.
rate
- The rate at which time progresses. 1 means a day lasts twenty minutes. 2 means ten minutes, etc.
Read-Only Attributes
These attributes cannot be manipulated directly, only read.
tickCount
- The number of ticks that have happened during throughout the map. This is stored for each save and will keep counting up as the player plays.
Functions
get()
- Returns the current time, as a float.
set(long time)
- Sets the current time. 6000 is noon, 18000 midnight, 24000 and 0 dawn, and 12000 dusk.
getTime()
- Returns the current time, as a float.
setTime(long time)
- Sets the current time. 6000 is noon, 18000 midnight, 24000 and 0 dawn, and 12000 dusk.
getRate()
- Returns the current rate at which time progresses, as a float.
setRate(float rate)
- Sets the rate at which time progresses.
getTickCount()
- Returns the current number of ticks for this save, as a long.
sleep(float seconds)
- Used to make scripts pause for
secondsseconds. The minimum is 0.5 seconds.
UI Class
Class Attributes
x
- The current position of the UI element along the x axis of the screen. 0 is the very left edge.
y
- The current position of the UI element along the y axis of the screen. 0 is the very top edge.
Methods
addToScreen()
- Adds a UI element back to the screen at the top if it's been removed.
removeFromScreen()
- Removes a UI element from the screen.
pushToFront()
- Moves a UI element to the front of the screen, displaying on top of everything else.
pushToBack()
- Moves a UI element to the back of the screen, displaying behind everything else.
Read-Only Attributes
height
- The height of the user's screen.
width
- The width of the user's screen.
Functions
getHeight()
- Returns the height of the user's screen.
getWidth()
- Returns the width of the user's screen.
getStringWidth(String s)
- Returns the width
String swould be when displayed on the screen.
UIContainer Subclass
Methods
add(UIElement)
- Adds the
UIElementto thisUIContainer. TheUIElement'sx, yposition are now offsets from thisUIContainer's position.
addToBack(UIElement)
- Adds the
UIElementto thisUIContainerat the back, making it render first, and thus everything else in thisUIContainerrender after and on top of it. TheUIElement'sx, yposition are now offsets from this from thisUIContainer's position.
remove(UIElement)
- Stops
UIElementfrom rendering.
clear()
- Removes all
UIElements from this container and stops them from rendering.
Constructors
UIContainer(int x, int y)
- Creates a new
UIContainerobject at positionx, y.
UILabel Subclass
Class Attributes
text
- The current text shown by the
UILabel.
red
- How red the text is, ranging from 0 to 1.
green
- How green the text is, ranging from 0 to 1.
blue
- How blue the text is, ranging from 0 to 1.
alpha
- How transparent the text is, ranging from 0 (opaque) to 1(invisible).
shadow
- A boolean for whether or not the text has a shadow.
centered
- A boolean, if this is set, the text will be centered about (x) instead of having its left side there
Constructors
UILabel(string text, int x, int y)
- Creates a new
UILabelobject with the texttextat positionx, y. It is best to assign it to a variable so that you can manipulate it further.
UIRect Subclass
Class Attributes
width
- The width of the
UIRect.
height
- The height of the
UIRect.
red
- How red the
UIRectis, ranging from 0 to 1.
green
- How green the
UIRectis, ranging from 0 to 1.
blue
- How blue the
UIRectis, ranging from 0 to 1.
alpha
- How transparent the
UIRectis, ranging from 0 (transparent) to 1 (opaque).
Constructors
UIRect(int x, int y, int width, int height, float red, float green, float blue, float alpha)
- Creates a new
UIRectobject at positionx, ywith the width and height ofwidth, height, and with the RGBA valuesred, green, blue, alpha.
UISprite Subclass
Class Attributes
texture
- Sets this
UISprite's current texture.
width
- The width of the
UISprite.
height
- The height of the
UISprite
u
- The starting x position in the texture.
v
- The starting y position in the texture.
red
- How much red of the texture to show, ranging from 0 to 1.
green
- How much green of the texture to show, ranging from 0 to 1.
blue
- How much blue of the texture to show, ranging from 0 to 1.
alpha
- How transparent the
UISpriteis, ranging from 0 (opaque) to 1(invisible).
Constructors
UISprite(string texture, int x, int y, int width, int height, int u, int v)
- Creates a new
UISpriteobject using the texturetextureat positionx, ywith the width and height ofwidth, height, and starting theu, vposition in the texture.
World Object
Functions
getBlockID(int x, int y, int z)
- Returns the ID of the block at
x, y, z, as an integer.
setBlockID(int x, int y, int z, int id)
- Sets the ID of the block at
x, y, ztoid.
getMetadata(x, y, z)
- Returns the metadata of the block at
x, y, z, as an integer.
setMetadata(int x, int y, int z, int metadata)
- Sets the metadata of the block at
x, y, ztometadata.
setBlockIDAndMetadata(int x, int y, int z, int id, int metadata)
- Sets the ID and metadata of the block at
x, y, ztoidandmetadata, respectively.
getLightValue(int blockX, int blockY, int blockZ)
- Returns the current light value of the specified block.
triggerBlock(int blockX, int blockY, int blockZ)
- Quick trigger on and off for the specified block coords
triggerArea(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
- Quick trigger on and off for the specified area.
setTriggerArea(int blockX, int blockY, int blockZ, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
- Enables an active trigger for the specified area from a specified block. Trigger area will remain active till its removed.
setTriggerArea(int blockX, int blockY, int blockZ, int areaID, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
- Enables an active trigger for the specified area from a specified block with a specified areaID. Trigger area will remain active till its removed.
removeTriggerArea(int blockX, int blockY, int blockZ, int areaID)
- Removes a trigger for a specified block coord and areaID.
removeTriggerAreas(int blockX, int blockY, int blockZ)
- Removes all triggers for a specified block coord.
spawnEntity(string entityType, int x, int y, int z)
- Spawns and then returns an Entity of
EntityTypeat given location.
Weather Object
These attributes can be manipulated directly.
Attributes
precipitating
- A boolean for whether it's raining/snowing or not.
temperatureOffset
- The offset of the biome temperatures across the world. If this is
1and it's precipitating, it'll rain everywhere, even in places that would otherwise be snowy. Vice versa, if this is-1and it's precipitating, it'll snow everywhere.
thundering
- A boolean for whether it's thundering or not.
Functions
setPrecipitating(boolean precipate)
- Sets whether it's raining/snowing or not.
getPrecipitating()
- Returns
trueif it's raining/snowing.
setTemperatureOffset(double tempOffset)
- Sets the temperature offset for the world.
getTemperatureOffset()
- Returns the temperature offset for the world.
setThundering(boolean thunder)
- Sets whether it's thundering or not.
getThundering()
- Returns
trueif it's thundering.
Script Object
runScript(fileName)
- Runs a .js script from the scripts folder.
- Returns the last evaluated object (or function), like
prognin common lisp - Note: The other script can't use the
time.sleepcommand, but if you want to do so, then create a function in another file on loading and use thetime.sleepcommand within the function.
openUrl(String url)
- Asks the player to open the specified url.
openUrl(String url, String msg)
- Asks the player the specified message to open the chosen url.
Keyboard Object
Attributes
These attributes can be manipulated directly.
keyID
- has the key pressed and
keyState
- has whether the key was pressed down/up
- If the last line returns false then it will be as if the player didn't press that key
keyForwardScript
- Script to run when pressing forward
keyBackScript
- Script to run when pressing back
keyLeftScript
- Script to run when pressing left
keyRightScript
- Script to run when pressing right
keyJumpScript
- Script to run when pressing jump
keySneakScript
- Script to run when pressing sneak
Functions
bindKey(int keyID, string scriptName)
- Executes the specified script whenever the specified key is pressed.
unbindKey(int keyID)
- Removes the script bound to the specified keyID.
bindAllKeyScript(string scriptName)
- Whenever any key is pressed, the specified script is run. The variable keyID contains the ID of the key pressed.
unbindAllKeyScript()
- Removes the binding to the script for all key presses.
isKeyDown(int keyID)
- Returns if the specified key is down.
getKeyName(int keyID)
- Returns the name of the specified keyID.
getKeyID(String keyName)
- Returns the ID of the specified key name.
Model Class
Attributes
These attributes can be manipulated directly.
texture
- A string for the current texture used by the model
attachedTo
- The entity this model is attached to
modelAttachment
- The model this model is attached to
Functions
addBox(String boxName, float offsetX, float offsetY, float offsetZ, int width, int height, int depth, int u, int v)
- Creates a box (at the location specified by offset from the model's origin) of size width by height by depth, using the last texture set starting at point (u,v)
addBoxExpanded(String boxName, float offsetX, float offsetY, float offsetZ, int width, int height, int depth, int u, int v, float expand)
- Creates a box (at the location specified by offset from the model's origin) of size width by height by depth, using the last texture set starting at point (u,v) and then expands it by specified value (stretching the texture)
setPosition(double newX, double newY, double newZ)
- Sets the previous position as well so it won't lerp between the old and new
moveTo(double newX, double newY, double newZ)
- Sets just the current position so it will lerp over a tick
moveBy(double moveX, double moveY, double moveZ)
- Moves the model taking into account the rotation.
setRotation(float newYaw, float newPitch, float newRoll)
- Sets the Yaw, Pitch and Roll of the model.
rotateTo(float newYaw, float newPitch, float newRoll)
- Rotates the Yaw, Pitch and Roll to specified values.
rotateBy(float rYaw, float rPitch, float rRoll)
- Adds specified values to Yaw, Pitch and Roll.
removeFromRendering()
- Stops the model from rendering
addToRendering()
- Adds the model for rendering
Constructors
Model()
- Creates a model with a texture size of 64x32, stretching the texture to that size.
Model(int width, int height)
- Creates a model with a texture size specified by the arguments, stretching the texture to that size.

