Skip to content

Instantly share code, notes, and snippets.

View clo4's full-sized avatar

Robert Clover clo4

View GitHub Profile
@clo4
clo4 / explanation.md
Last active November 21, 2024 01:22
Experiment for a Minecraft data pack to get the player's head rotation without using NBT.

I wanted to eliminate the single NBT check from my Minecraft data pack, Detect AFK Players. It uses the player's head rotation, and currently, there isn't a command like /rotate query to get that information without using NBT.

NBT is the save format, and requires the game to convert all the player data to that format from the in-memory data structures, serialize it, parse the lookup, and finally return the data. That's pretty slow! Naturally, the community's motto is to stay away from NBT unless you absolutely have to. I tried a few different things to detect activity, including:

  • Spawn a marker entity where the player is looking
    • Ties rotation to position, which is not good
  • Spawn an entity where the player is looking, "positioned at" a particular point
    • Requires either force loading chunks or using known loaded chunks
  • Use a predicate to detect input directly
  • Runs into edge cases such as player-operated farms where you use the mouse but not any keyboard inputs, and being a boat/camel passeng
@clo4
clo4 / force_unfocus.js
Last active May 13, 2024 07:43
Userscript that force-unfocusses the currently focused element when you press shift-escape.
// ==UserScript==
// @name Unfocus
// @namespace https://clo4.net
// @version 1.0.0
// @description Unfocuses the current element when you press shift+esc
// @author github.com/clo4
// @match *://*/*
// @icon https://upload.wikimedia.org/wikipedia/commons/d/dc/Escts.jpg
// @grant none
// ==/UserScript==
@clo4
clo4 / pinterest_domains.txt
Last active February 28, 2024 02:31
List of Pinterest domains I've blocked in Kagi because I'm tired of them ruining image search. Copy/Paste this list into the Kagi block list!
pinterest.at
pinterest.ca
pinterest.co.uk
pinterest.com
pinterest.com.au
pinterest.com.mx
pinterest.de
pinterest.dk
pinterest.es
pinterest.fr
defaults write -g NSWindowShouldDragOnGesture -bool true
@clo4
clo4 / optional_groups.ts
Created April 14, 2022 02:30
Create groups of properties that must be provided together
type OptionalGroup<T> = T | { [K in keyof T]?: undefined };
// deno-fmt-ignore
type OptionalGroups<Sets extends unknown[]> = Sets extends [infer Head, ...infer Rest]
? Rest extends []
? OptionalGroup<Head>
: OptionalGroup<Head> & OptionalGroups<Rest>
: Sets;
export type PropertySets<Base, Sets extends unknown[]> =
// Copyright 2021 SeparateRecords
//
// Permission to use, copy, modify, and/or distribute this software for any purpose
// with or without fee is hereby granted, provided that the above copyright notice
// and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
#!/usr/bin/env bash
# --- Variables and folder structure ---
: ${SCREENSHOT_LOCATION:="$HOME/Pictures/Screenshots"} && mkdir -p "$SCREENSHOT_LOCATION"
: ${ENV_MGR_LOCATION:="$HOME/.local/share"} && mkdir -p "$ENV_MGR_LOCATION"
: ${WORKSPACES_LOCATION:="$HOME/Workspaces"} && mkdir -p "$WORKSPACES_LOCATION"
: ${LISTS_LOCATION:="$HOME/Lists"} && mkdir -p "$LISTS_LOCATION"
@clo4
clo4 / abbreviable_group.py
Created October 10, 2019 02:03
Abbreviable group for Click, based on the example in the documentation. Flexible and subclassable implementation.
import click
class SuperGroup(click.Group):
@classmethod
def new(cls, name=None, **attrs):
"""Decorator to create a new group (use as `click.group()`)"""
attrs.setdefault('cls', cls)
return click.command(name, **attrs)