Three Block Types and the Execution Chain
Command blocks come in three types: impulse (runs once per redstone pulse), repeating (runs every tick while always active), and chain (runs after the block behind it, must be adjacent and facing the same way). Activation is either 'needs redstone' or 'always active' — pick always active for loops, needs redstone for manual switches. Before building, run /gamerule commandBlockOutput false or chat drowns in execution logs. The single most valuable habit: put logic in functions, keep blocks as triggers. Write the lines into a .mcfunction and call it with one function command — easier to maintain, easier to edit, and immune to a broken chain cascade.
Teleport Pads and Shops: The Two Workhorses
A teleport pad runs a repeating block that checks the block under each player: execute as @a at @s if block ~ ~-1 ~ minecraft:lime_stained_glass run tp @s 100 70 200. Swap coordinates for your destination. Use stained glass rather than pressure plates — it cannot be stepped off or accidentally triggered. A shop's core is charge-verify-refund to prevent double charging under concurrency: deduct first, check the balance is still non-negative, only then deliver, and add the money back if it went negative. Never hardcode prices; store them on a virtual player such as #price and change one number. Deduct with scoreboard players remove and deliver with give, with no delay in between, or players find a free-goods hole.
Scoreboard Trio: Leaderboard, Timer, Boss Bar
Leaderboard: scoreboard objectives add kills dummy, then setdisplay sidebar kills — descending by default. Timer: store seconds on a virtual player, subtract 1 every 20 ticks from a repeating block, show the remainder via title actionbar, fire an event at 0. Boss bar: bossbar add creates the bar, bossbar set players chooses the audience, and a scoreboard holds current health, syncing value and max each tick. All three share a principle: state lives in the scoreboard, display is delegated to vanilla UI — never store state inside the block itself. And always scope high-frequency selectors with distance or coordinates; a global @e scan will tank your TPS.
Protection, Cleanup, Welcome: Server Daily Three
Welcoming new players is cleanest with tags: execute as @a[tag=!welcomed] run tellraw to greet, then tag @a add welcomed to mark everyone — tidier than a scoreboard. Scheduled item cleanup: execute as @e[type=item,tag=!keep] run kill @s, tagging valuables with keep first and removing the tag afterward to reset. Region protection with command blocks only works as a small-scale backstop, such as refilling a block the instant it turns to air; real protection belongs to datapack break criteria or server plugins — that is the capability boundary, and forcing command blocks to do it only buys lag and holes. Fall protection can use Slow Falling as a safety net, but high-speed falls can evade detection — tell players honestly.
Functions, Performance and Classic Traps
Writing logic as functions buys readability, reuse and multiple call sites. Put files under data/<namespace>/function/, one command per line, and call them with function namespace:file. Three performance rules: scope selectors inside repeating blocks, avoid tick-by-tick large fills, and use schedule instead of polling when timing is enough. Classic traps: chain blocks facing different directions so the chain never runs; a repeating block retriggered by its own redstone; malformed JSON text components in tellraw failing silently; and editing a function without /reload. Debug by running each command alone to read the error, then reconnecting them — don't start by doubting the logic.
Comments
Powered by GitHub Discussions — sign in with GitHub to comment.