Skip to content

Instantly share code, notes, and snippets.

@MichalGniadek
Created November 28, 2021 20:49
Show Gist options
  • Save MichalGniadek/b778e0d43435c2f127d7ebacc1483932 to your computer and use it in GitHub Desktop.
Save MichalGniadek/b778e0d43435c2f127d7ebacc1483932 to your computer and use it in GitHub Desktop.
Beet plugin for autoreloading datapacks
from beet import Context, Function
import time
import os
import shutil
import datetime
def beet_default(ctx: Context):
if delete_from_link(ctx):
time.sleep(0.2)
ctx.data["autoreload:load"] = Function(
["scoreboard objectives add _beet_autoreload dummy"], tags=["minecraft:load"]
)
ctx.data["autoreload:tick"] = Function(
["execute if score .delta _beet_autoreload matches 1.. run reload",
"execute if score .delta _beet_autoreload matches 1.. run tellraw @a {\"text\":\"[" +
str(datetime.datetime.now()) +
"] /reload\",\"bold\":true,\"color\":\"gold\"}",
"execute store result score .pack_count _beet_autoreload run datapack list available",
"scoreboard players operation .delta _beet_autoreload = .pack_count _beet_autoreload",
"scoreboard players operation .delta _beet_autoreload -= .old_pack_count _beet_autoreload",
"scoreboard players operation .old_pack_count _beet_autoreload = .pack_count _beet_autoreload", ],
tags=["minecraft:tick"]
)
def delete_from_link(ctx: Context):
if path := ctx.cache["link"].json.get("data_pack"):
if os.path.split(path)[1] != "datapacks":
return False
path = os.path.join(path, ctx.project_id + "_data_pack")
exists = os.path.exists(path)
if exists:
shutil.rmtree(path)
return exists
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment