Skip to content

Instantly share code, notes, and snippets.

View intsuc's full-sized avatar
🐧
⚡️

intsuc

🐧
⚡️
View GitHub Profile
@intsuc
intsuc / .mcfunction
Last active April 8, 2025 11:06
An example implementation of a resizable queue with a growable ring buffer
#> example
function init
tellraw @s {storage: "_", nbt: "{}"}
# ┌ #read
# ring_overflow: [ _ | ]
# #write ┘ │ └ #ring_overflow_size
# └ #ring_size
@intsuc
intsuc / snbt.ebnf
Last active February 27, 2025 16:45
[25w09b] SNBT grammar without rules
/* https://www.minecraft.net/en-us/article/minecraft-snapshot-25w09a */
simple_hex_literal =
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
unicode_name =
(
| '-'
| 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'
@intsuc
intsuc / .mcfunction
Last active February 27, 2025 12:48
[25w09b] Get the id of a given tag in constant time
# examples
data merge storage example: { \
1: 0b, \
2: 0s, \
3: 0, \
4: 0L, \
5: 0.0f, \
6: 0.0d, \
7: [B;], \
@intsuc
intsuc / .md
Last active August 11, 2024 03:01
素数積による疑似ビットベクトル表現とその演算

素数積による疑似ビットベクトル表現とその演算

コマンドには整数のビット演算が存在しないため、ビット演算を行いたい場合には1ビットずつ処理を行う必要があります。 素数積による疑似ビットベクトル表現を用いることで、ビットの密度を犠牲にして一部のビット演算を高速に行うことができます。

素数積による疑似ビットベクトル表現

以下のように、素数の積を用いて長さ8のビットベクトルを表現することができます。 下位 $i$ 番目のビットを $b_i$$3$ から数えて $i$ 番目の素数を $p_i$ とします。

@intsuc
intsuc / .example.mcfunction
Last active July 26, 2024 12:14
Convert a long tag into high and low 32-bit integers and vice versa
function init
# 1782934792843521910 = 0x18be41bf_691f6f76
# = (0x18be41bf, 0x691f6f76)
# = (415121855, 1763667830)
data modify storage _ source set value 1782934792843521910L
# 1782934792843521910 -> (415121855, 1763667830)
function split
@intsuc
intsuc / example.mcfunction
Last active July 13, 2024 12:52
Get the high 32 bits of a LongTag
function high32:init
data modify storage _ a set value -1145395493543608220L
# (0xf01abcde00000064)
function high32:get {source: "storage _ a"}
# Function high32:get returned -266683170
# (0xf01abcde)
@intsuc
intsuc / init.mcfunction
Created January 3, 2024 20:16
Approximate rigid motion by 2 approximate reflections
summon text_display ~ ~ ~ {text: '{"text": "a", "color": "black"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 10]}
summon text_display ~ ~ ~ {text: '{"text": "b", "color": "black"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 11]}
summon text_display ~ ~ ~ {text: '{"text": "c", "color": "black"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 12]}
summon text_display ~ ~ ~ {text: '{"text": "(b⋅a)b", "color": "black"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 0]}
summon text_display ~ ~ ~ {text: '{"text": "bab", "color": "black"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 1]}
summon text_display ~ ~ ~ {text: '{"text": "(c⋅bab)c", "color": "black"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 2]}
summon text_display ~ ~ ~ {text: '{"text": "c(bab)c", "color": "red"}', background: 0, billboard: "center", UUID: [I; 0, 0, 0, 3]}
@intsuc
intsuc / baseline.mcfunction
Last active May 21, 2023 08:05
1.20-pre1 vs 1.20-pre2
We couldn’t find that file to show.

1.20-pre1 vs 1.20-pre2

benchmark 1.20-pre1 1.20-pre2
baseline 263.479460184556 ± 55.44590623221055 [ns/op] 262.6772200457718 ± 55.05785493224197 [ns/op]
data_get_byte 433.98316762350913 ± 7.444825260824145 [ns/op] 391.87628185594724 ± 18.936628742014072 [ns/op]
data_get_byte_1 740.4393732769925 ± 20.93953249166631 [ns/op] 456.17101920010447 ± 8.630503299692144 [ns/op]
data_get_int 412.08435852317024 ± 4.056129450233465 [ns/op] 374.34500487014526 ± 2.435684193080521 [ns/op]
data_get_int_1 737.7503310023358 ± 13.85836437954026 [ns/op] 423.18244626398047 ± 1.329924149473285 [ns/op]
data_get_list_0 406.8077717359254 ± 13.273700931499596 [ns/op] 380.8705782109833 ± 18.39461975718555 [ns/op]
data remove storage _ _
data modify storage _ _[] set value 0