Minecraft Data Packs / Game Mechanic

Player Action Detector - Boolean API Datapack

  • check_circle Functions
  • 526 views, 1 today
  • 7 downloads, 0 today
  • 5
  • 3
nzcsx avatar nzcsx
Level 22 : Expert Crafter

> Abstract

This data pack translates player actions into booleans. I chose to use scoreboard objectives to represent the booleans ({score=1} == True, {score=0} == False). These objective scores are read-only and should NOT be modified manually in-game. This datapack is written by "Squid Workshop", and was originally uploaded on GitHub.
  • How to Install/Uninstall
  • How to Use
  • How It Works
  • FAQ
  • Terms of Use
  • More About Squid Workshop

> How to Install/Uninstall

Load (Install)

  • Step 1 Download "Bools-Datapack-Squid-Workshop-1.16.5.zip".
  • Step 2 Go to minecraft saves directory, usually "C:/Users/youUserName/AppData/Roaming/.minecraft/saves".
  • Step 3 Choose the world folder in which you want to install the packs.
  • Step 4 Go to ../datapacks folder.
  • Step 5 Move "Bools-Datapack-Squid-Workshop-1.16.5.zip" into ../datapacks folder.
  • Step 6 Open Minecraft and open the world.
  • Step 7 Type '/reload" command then press enter.
  • Step 8 Enjoy

PS: If not working, check whether the datapack is enabled by:

/datapack list

Enable it by:
/datapack enable "datapackname"

Unload (Uninstall)

  • Step 1 Delete the zip file from ../datapacks folder.
  • Step 2 Use command:
/function app:unload/boolsThis automatically deletes all the scoreboard objectives created in this datapack.

> How to Use

You can use the selector or if-statement in command to check if players have the scores.
  • This command gives an apple to players that jumped:
/execute as @a[scores={jump_bool=1}] run give @s minecraft:apple 1
  • This command gives 1 second regeneration effect to players that start sleeping:
/execute as @a[scores={sleep_begin=1}] run effect give @s minecraft:regeneration 1 1 true
These boolean scores check two types of actions: Level and Edge.
Level action scores := (keep setting to 1 whenever) player is doing something
Edge action scores := (set to 1 for one tick if) player did something

The following is a list of all the scores:

walk_boollevelis walking
walk_beginedgestarts walking
walk_endedgestops walking
shift_boollevelis pressing shift
shift_beginedgestarts pressing shift
shift_endedgestops pressing shift
sprint_boollevelis sprinting
sprint_beginedgestarts sprinting
sprint_endedgestops sprinting
sleep_boollevelis sleeping
sleep_beginedgestarts sleeping
sleep_endedgestops sleeping
offGrnd_beginedgelifted offground
shield_boollevelhas shield in main or off hand
bow_booledgeused bow
crossbow_booledgeused crossbow
pearl_booledgeused ender pearl
snowball_booledgeused snowball
carotClik_booledgeright clicked using carrot stick
fungiClik_booledgeright clicked using fungus stick
fishrClik_booledgeright clicked using fishing rod
container_booledgeinteracted with a barrel/chest/enderchest/shulker_box/trap_chest//blast_furnace/furnace/smoker//dispenser/dropper/hopper

> How It Works

Key Idea

Suppose we have two variables: walk_helper and walk_bool:

/scoreboard objectives add walk_meter minecraft.custom:minecraft.walk_one_cm
/scoreboard objectives add walk_bool dummyThe key idea of a Boolean detector is that we keep resetting the helper every tick. If the helper stays zero, the player is not taking any action. If the counter rises above zero, the player is doing stuffs.

And here is a little piece of pseudo code to help us understand the logic:
Loop per tick:

# Game updates helper #

bool = 0
if ( helper > 0 ):
bool = 1
helper = 0

However, there are several tweaks on different objectives due some nuances of the game mechanism. For more detailed explanation. I strongly urge you to check out my GitHub page: >> Boolean Datapack - GitHub <<


Q: I don't know how to use GitHub. How can I download it?
A: On the GitHub page, you can see a Releases section on the right. Click it, which directs to the Releases page. Then click the Bools-Datapack-Squid-Workshop-1.16.5.zip file to download.

Q: What version of the game is it compatible with?
A: I wrote the pack in 1.16.5, and it is compatible upto at least 1.19.1 (and the foreseeable future versions). The syntax used are pretty basic, and I don't expect Mojang to make any big changes in the future.

Q: We created a lot of scoreboard objectives. Are they still there after I uninstall?
A: If we follow the instruction in the GitHub page, all of the objectives will be deleted. If we made a mistake while uninstalling, we can simply reinstall and uninstall it again.

Q: Why don't we use scoreboard tags instead of scoreboard objectives?
A: Because when we don't want to play with these scores anymore, we can just delete them. If we use tags, we cannot remove the tags on the players who are not online, which can cause trouble.

Q: What is the meaning of life?
A: You didn't know? It's just █̵̭̩̦͍̒͑█̵̳̝̃̚█̷̨̺̮͈̆̓͠█̷̙͑█

Q: What if I want more bools?
A: You can create "issues" on GitHub to make a suggestion, or just comment it here.

Q: Can I modify your pack to suit my need?
A: Yes you can. The datapack is under Mozilla Public License 2.0. However, please don't copy paste the code without acknowledging the source.

Q: What inspired you to make this datapack?
A: I was tired of writing same pieces of code for every datapack I made. Plus, I don't like adding a bunch of redundant scoreboard objectives for every datapack. So I decided to make an API datapack for everyone to use.

Q: I have more questions!
A: You can create "issues" on GitHub to make a suggestion, or just comment it here.

> Terms of Use

Feel free to play around with this datapack.
As developer, feel free to use this datapack as a module to develop free datapacks.
But you must add the link to this github page!


Mozilla Public License 2.0

> More About Squid Workshop

See more datapacks developed by us here
Watch our videos on bilibili here
Watch our videos on Youtube here
CompatibilityMinecraft 1.16
toMinecraft 1.19

Create an account or sign in to comment.

Planet Minecraft


© 2010 - 2022