ReadonlydimensionReadonlyidReadonlyisThis property can't be read in early-execution mode.
ReadonlyisThis property can't be read in early-execution mode.
ReadonlyisThis property can't be read in early-execution mode.
ReadonlyisThis property can't be read in early-execution mode.
ReadonlyisThis property can't be read in early-execution mode.
This property can't be edited in read-only mode.
This property can't be read in early-execution mode.
import { system, world } from "@minecraft/server";
system.runInterval(() => {
for (const entity of world.getDimension("overworld").getEntities()) {
// Force entity to not sneak
entity.isSneaking = false;
}
});
import { DimensionLocation, MolangVariableMap, Vector3, system, world } from "@minecraft/server";
function spawnConfetti(location: DimensionLocation) {
for (let i = 0; i < 100; i++) {
const molang = new MolangVariableMap();
molang.setColorRGB("variable.color", {
red: Math.random(),
green: Math.random(),
blue: Math.random(),
});
const newLocation: Vector3 = {
x: location.x + Math.floor(Math.random() * 8) - 4,
y: location.y + Math.floor(Math.random() * 8) - 4,
z: location.z + Math.floor(Math.random() * 8) - 4,
};
location.dimension.spawnParticle("minecraft:colored_flame_particle", newLocation, molang);
}
}
system.runInterval(() => {
for (const player of world.getPlayers()) {
if (player.isSneaking) {
spawnConfetti({
dimension: player.dimension,
x: player.location.x,
y: player.location.y,
z: player.location.z,
});
player.sendMessage("player is sneaking");
}
}
});
ReadonlyisThis property can't be read in early-execution mode.
ReadonlyisThis property can't be read in early-execution mode.
Readonlyisimport { system, world } from "@minecraft/server";
const zombie = world.getDimension("overworld").spawnEntity("minecraft:zombie", world.getDefaultSpawnLocation());
const id = system.runInterval(() => {
if (!zombie.isValid) {
system.clearRun(id);
return;
}
const location = zombie.location;
for (const player of world.getPlayers()) {
player.sendMessage(
`Zombie location: (${location.x.toFixed(2)}, ${location.y.toFixed(2)}, ${location.z.toFixed(2)})`
);
}
});
ReadonlylocalizationThis property can't be read in early-execution mode.
ReadonlylocationThis property can't be read in early-execution mode.
This property can't be edited in read-only mode.
This property can't be read in early-execution mode.
Optional ReadonlyscoreboardReadonlytypeimport { system, world } from "@minecraft/server";
// This event triggers when world is loaded
system.runInterval(() => {
const entity = world.getDimension("overworld").getEntities()[0];
// Finally, show that location as title
entity.runCommand(
`title @a actionbar X: ${Math.floor(entity.location.x)} | Y: ${Math.floor(entity.location.y)} | Z: ${Math.floor(
entity.location.z
)}`
);
});
Optionaloptions: EntityEffectOptionsThis function can't be called in read-only mode.
This function can throw errors.
minecraftcommon.ArgumentOutOfBoundsError
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: EntityApplyDamageByProjectileOptions | EntityApplyDamageOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
The following example (updated of the above - bounceSkeleton.ts) spawns several mobs, then applies a knockback to all skeletons.
import { EntityQueryOptions, DimensionLocation } from "@minecraft/server";
function bounceSkeletons(targetLocation: DimensionLocation) {
const mobs = ["creeper", "skeleton", "sheep"];
const horizontalForce = { x: 5, z: 4 }; // horizontal knockback strength - xz vector
const verticalStrength = 0.3; // upward knockback strength
// Spawn 10 mobs in a pattern
for (let i = 0; i < 10; i++) {
targetLocation.dimension.spawnEntity(
mobs[i % mobs.length],
targetLocation
);
}
const eqo: EntityQueryOptions = { type: "skeleton" };
// Apply knockback to all skeletons in the area
for (const entity of targetLocation.dimension.getEntities(eqo)) {
entity.applyKnockback(horizontalForce, verticalStrength);
}
}
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
OptionaluseEffects: booleanDefaults to: true
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: GetBlocksStandingOnOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: BlockRaycastOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { world } from "@minecraft/server";
for (const entity of world.getDimension("overworld").getEntities()) {
const blockHit = entity.getBlockFromViewDirection();
if (blockHit) {
console.log("Block Hit:");
console.log("Block:", blockHit.block);
console.log("Face:", blockHit.face);
console.log("Face Location:", JSON.stringify(blockHit.faceLocation));
} else {
console.log("No block in view direction.");
}
}
import { BlockPermutation, world } from "@minecraft/server";
const entity = world.getDimension("overworld").spawnEntity("minecraft:fox", { x: 0, y: 0, z: 0 });
const blockHit = entity.getBlockFromViewDirection();
if (blockHit) {
blockHit.block.setPermutation(BlockPermutation.resolve("minecraft:bedrock"));
} else {
console.log("No block in view direction.");
}
Optionaloptions: GetBlocksStandingOnOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { world } from "@minecraft/server";
for (const player of world.getPlayers()) {
const health = player.getComponent("health");
player.sendMessage("Your health is " + health.currentValue + "/" + health.effectiveMax);
health.setCurrentValue(15); // set player to 15 hp
health.resetToMaxValue(); // reset player to max hp
}
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { Vector3, system, world } from "@minecraft/server";
world.afterEvents.entitySpawn.subscribe((event) => {
event.entity.setDynamicProperty("spawn_location", event.entity.location); // set location spawn
});
world.beforeEvents.entityRemove.subscribe((event) => {
const location = event.removedEntity.getDynamicProperty("spawn_location") as Vector3; // get location spawn
const dimension = event.removedEntity.dimension;
system.run(() => {
dimension.spawnEntity<string>(event.removedEntity.typeId, location);
});
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe((event) => {
// Type /scriptevent bp:entries to see this message
if (event.id === "bp:entries" && event.sourceEntity instanceof Player) {
event.sourceEntity.sendMessage("Here's your dynamic properties entries:");
// Display all dynamic properties
for (const id of event.sourceEntity.getDynamicPropertyIds()) {
event.sourceEntity.sendMessage(`- ${id}: ${event.sourceEntity.getDynamicProperty(id)}`);
}
}
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe((event) => {
// Type /scriptevent dp:size to see this message
if (event.id === "dp:size" && event.sourceEntity instanceof Player) {
// Returns the total size, in bytes, of all the dynamic properties that are currently stored for this entity.
const byteCount = event.sourceEntity.getDynamicPropertyTotalByteCount();
// Send the byte count to the player
event.sourceEntity.sendMessage(`Dynamic Properties Byte Count: ${byteCount}`);
}
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { Player, world } from "@minecraft/server";
/**
@param {Player} player
/
function hasNightVision(player) {
const nightVision = player.getEffect("night_vision");
if (nightVision) {
return true;
} else return false;
}
for (const player of world.getAllPlayers()) {
if (hasNightVision(player)) {
player.sendMessage("You have night vision.");
} else {
player.sendMessage("You don't have night vision.");
}
}
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: EntityRaycastOptionsThis function can't be called in read-only mode.
This function can throw errors.
minecraftcommon.InvalidArgumentError
minecraftcommon.UnsupportedFunctionalityError
This function can't be called in early-execution mode.
import type { EntityRaycastOptions } from "@minecraft/server";
import { world } from "@minecraft/server";
// Optional: Configure ray cast options
const raycastOptions: EntityRaycastOptions = {
maxDistance: 10, // Set your desired maximum distance
};
// Perform the ray cast
for (const entity of world.getDimension("overworld").getEntities()) {
const entitiesInView = entity.getEntitiesFromViewDirection(raycastOptions);
// Log the results
entitiesInView.forEach((hit) => {
console.log(`Entity hit at distance ${hit.distance} blocks.`);
console.log("Entity details:", hit.entity); // You can access properties/methods of the hit entity
});
}
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { world } from "@minecraft/server";
world.beforeEvents.chatSend.subscribe((event) => {
const message = event.message;
const player = event.sender;
if (message === "rotation get") {
event.cancel = true;
const rotation = player.getRotation();
player.sendMessage(`Spawn point location: ${rotation.x} ${rotation.y}`);
}
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can throw errors.
minecraftcommon.InvalidArgumentError
minecraftcommon.UnsupportedFunctionalityError
This function can't be called in early-execution mode.
import { GameMode, system, world } from "@minecraft/server";
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
const isSpectating = player.matches({ gameMode: GameMode.Spectator });
if (isSpectating) {
player.onScreenDisplay.setActionBar("You are spectating");
}
}
});
Optionaloptions: PlayAnimationOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionalvalue: string | number | boolean | Vector3This function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { Vector3, system, world } from "@minecraft/server";
world.afterEvents.entitySpawn.subscribe((event) => {
event.entity.setDynamicProperty("spawn_location", event.entity.location); // set location spawn
});
world.beforeEvents.entityRemove.subscribe((event) => {
const location = event.removedEntity.getDynamicProperty("spawn_location") as Vector3; // get location spawn
const dimension = event.removedEntity.dimension;
system.run(() => {
dimension.spawnEntity<string>(event.removedEntity.typeId, location);
});
});
OptionaluseEffects: booleanDefaults to: true
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can throw errors.
minecraftcommon.ArgumentOutOfBoundsError
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
OptionalteleportOptions: TeleportOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { system, world } from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe(({ sourceEntity, message }) => {
if (!sourceEntity) return;
if (message === "tp:nether") {
sourceEntity.teleport({ x: 0, y: 0, z: 0 }, { dimension: world.getDimension("nether") });
}
});
import { system, world } from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe(({ sourceEntity, message }) => {
if (!sourceEntity) return;
if (message === "tp:nether") {
sourceEntity.teleport(
{ x: 0, y: 0, z: 0 },
{
dimension: world.getDimension("nether"),
facingLocation: { x: 100, y: 100, z: 100 },
}
);
}
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
OptionalteleportOptions: TeleportOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
Throws
This property can throw errors.
minecraftcommon.EngineError
InvalidEntityError
World Ready
This property can't be read in early-execution mode.
Example: spawnItem.js