Skip to content

Instantly share code, notes, and snippets.

View BomBardyGamer's full-sized avatar
👋
Hello there!

Callum Seabrook BomBardyGamer

👋
Hello there!
View GitHub Profile
@BomBardyGamer
BomBardyGamer / Main.java
Created August 27, 2023 13:30
MiniMessage vs text replacement parser
public final class Main {
private static final String PURE_MINI_MESSAGE = "<click:run_command:'/party join <username>'><color:#3db83d>You have been invited to join <green><username>'s</green> party. <b><gradient:light_purple:gold>Click to accept</gradient></b></click>";
private static final String MINI_AND_PARSE = "<click:run_command:'/party join {0}'><color:#3db83d>You have been invited to join <green>{0}'s</green> party. <b><gradient:light_purple:gold>Click to accept</gradient></b></click>";
private static final TagResolver PLACEHOLDER = Placeholder.parsed("username", "Bardy");
private static final List<Component> ARGS = List.of(Component.text("Bardy"));
public static void main(String[] ignored) {
// Try to pre-initialise everything so that doesn't affect the results
MiniMessage miniMessage = MiniMessage.miniMessage();
@BomBardyGamer
BomBardyGamer / BellPlacementRule.java
Created July 9, 2023 21:27
Bell Minestom placement rule
package dev.emortal.minestom.core.placement;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockFace;
import net.minestom.server.instance.block.rule.BlockPlacementRule;
import net.minestom.server.utils.Direction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
@BomBardyGamer
BomBardyGamer / krypton-changes.md
Last active April 20, 2022 09:56
Krypton proposed changes

API Changes:

  • Remove wrapped field from AdventureMessage.
  • Remove many methods from GameProfile - not required.
    • Possibly remove with - use toBuilder to convert to a builder and edit in bulk.
    • Remove withName - changing the name of a GameProfile is hardly ever going to be required.
    • Remove withUUID - changing the UUID of a GameProfile is hardly ever going to be required.
  • Remove ProfileCache and replace with ProfileProvider - removes dependency on modified vanilla names, and removes the requirement for implementations to need a cache for GameProfiles.
  • Remove many implementation details and unclear fields from Block.
    • Remove id and stateId - unstable network IDs, subject to change, huge implementation details.
@BomBardyGamer
BomBardyGamer / keybase.md
Created February 6, 2022 18:13
Proof for Keybase

Keybase proof

I hereby claim:

  • I am BomBardyGamer on github.
  • I am bombardydev (https://keybase.io/bombardydev) on keybase.
  • I have a public key whose fingerprint is B308 410E 6681 4C58 CBC4 8167 A3AC 563A 6E59 A4E8

To claim this, I am signing this object:

@BomBardyGamer
BomBardyGamer / gson.csv
Last active August 15, 2021 22:11
Adventure JSON component serializer benchmark results
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 7.
"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit"
"net.kyori.adventure.text.serializer.gson.ComponentDeserializationBenchmark.componentTreeWithEvents","sample",1,4510105,13.949098,0.021804,"us/op"
"net.kyori.adventure.text.serializer.gson.ComponentDeserializationBenchmark.componentTreeWithEvents:componentTreeWithEvents·p0.00","sample",1,1,12.608000,NaN,"us/op"
"net.kyori.adventure.text.serializer.gson.ComponentDeserializationBenchmark.componentTreeWithEvents:componentTreeWithEvents·p0.50","sample",1,1,13.600000,NaN,"us/op"
"net.kyori.adventure.text.serializer.gson.ComponentDeserializationBenchmark.componentTreeWithEvents:componentTreeWithEvents·p0.90","sample",1,1,14.112000,NaN,"us/op"
"net.kyori.adventure.text.serializer.gson.ComponentDeserializationBenchmark.componentTreeWithEvents:componentTreeWithEvents·p0.95","sample",1,1,14.592000,NaN,"us/op"
"net.kyori.adventure.text.serializer.gson.ComponentDeserializationBenchmark.componentTreeWithEvents:componentTreeWithEvents·p0.99","sampl
@BomBardyGamer
BomBardyGamer / varlong-madness.kt
Created July 11, 2021 23:19
Highly optimised Steinborn-style VarLong writing, with full support up to 10 bit var longs
fun ByteBuf.writeVarLong(value: Long) {
when {
value and (0xFFFFFFFF shl 7) == 0L -> writeByte(value.toInt())
value and (0xFFFFFFFF shl 14) == 0L -> writeShort((value and 0x7F or 0x80 shl 8 or (value ushr 7)).toInt())
value and (0xFFFFFFFF shl 21) == 0L -> writeMedium((value and 0x7F or 0x80 shl 16 or (value ushr 7 and 0x7F or 0x80 shl 8) or (value ushr 14)).toInt())
value and (0xFFFFFFFF shl 28) == 0L -> writeInt((value and 0x7F or 0x80 shl 24 or (value ushr 7 and 0x7F or 0x80 shl 16) or (value ushr 14 and 0x7F or 0x80 shl 8) or (value ushr 21)).toInt())
value and (0xFFFFFFFF shl 35) == 0L -> {
writeInt((value and 0x7F or 0x80 shl 24 or (value ushr 7 and 0x7F or 0x80 shl 16) or (value ushr 14 and 0x7F or 0x80 shl 8) or (value ushr 21 and 0x7F or 0x80)).toInt())
writeByte((value ushr 28).toInt())
}
@BomBardyGamer
BomBardyGamer / dimension_codec.snbt
Created June 10, 2021 10:07
The default dimension codec, as of 1.17, as SNBT
{
"minecraft:dimension_type": {
type: "minecraft:dimension_type",
value: [
{
name: "minecraft:overworld",
id: 0,
element: {
piglin_safe: 0b,
natural: 1b,
@BomBardyGamer
BomBardyGamer / spirals.kt
Created May 4, 2021 15:52
Algorithm to get a chunk position in a spiral in O(1)
/**
* Calculates a chunk position from a given [id] in a spiral pattern.
*
* This algorithm was previously part of Krypton (https://github.com/KryptonMC/Krypton), however it was removed after
* it was no longer used.
*
* **Algorithm:**
*
* Given n, an index in the squared spiral
* p, the sum of a point in the inner square
@BomBardyGamer
BomBardyGamer / style.md
Created April 16, 2021 18:56
Bardy's Kotlin style guide

Bardy's Kotlin style guide

Table of contents

  • Introduction
  • Styling
    • Source files
    • Formatting
    • Naming

Introduction

@BomBardyGamer
BomBardyGamer / collections.kt
Created March 31, 2021 15:44
Bardy's Kotlin collection extensions
// Takes a Map<K, V> and applies the given function to each one of its elements, returning a new
// Map<K1, V1> with the transformed key-value pairs
fun <K, V, K1, V1> Map<K, V>.transform(function: (Map.Entry<K, V>) -> Pair<K1, V1>): Map<K1, V1> {
val temp = mutableMapOf<K1, V1>()
for (entry in this) {
temp += function(entry)
}
return temp
}