Skip to content

Instantly share code, notes, and snippets.

View ItsDoot's full-sized avatar

Christian Hughes ItsDoot

  • United States
  • 23:15 (UTC -05:00)
View GitHub Profile
public final class MinecraftConversions {
public static PistonMoveReaction fromMojang(final PushReaction reaction) {
switch (reaction) {
case NORMAL:
return PistonMoveReaction.MOVE;
case DESTROY:
return PistonMoveReaction.BREAK;
case BLOCK:
return PistonMoveReaction.BLOCK;
@ItsDoot
ItsDoot / CommandTownHere.kt
Created July 5, 2020 08:03
tasty command api
import com.expansemc.township.api.TownshipAPI
import com.expansemc.township.api.claim.Claim
import com.expansemc.township.plugin.util.Texts
import com.expansemc.township.plugin.util.extension.first
import com.expansemc.township.plugin.util.extension.unwrap
import org.spongepowered.api.command.Command
import org.spongepowered.api.command.CommandExecutor
import org.spongepowered.api.command.CommandResult
import org.spongepowered.api.command.exception.CommandException
import org.spongepowered.api.command.parameter.CommandContext
@ItsDoot
ItsDoot / Progressions.kt
Last active June 16, 2020 17:39
finally kotlin can have doubles in for loops
private fun mod(a: Double, b: Double): Double {
val mod = a % b
return if (mod >= 0) mod else mod + b
}
private fun differenceModulo(a: Double, b: Double, c: Double): Double {
return mod(mod(a, c) - mod(b, c), c)
}
private fun getProgressionLastElement(start: Double, end: Double, step: Double): Double = when {
@ItsDoot
ItsDoot / ZestGrammar.kt
Last active March 22, 2020 06:17
beautiful kotlin
/**
* Lexer and Parser for the Zest language.
*
* Some notes about the syntax below:
* - `A * B` is used to mean "A then B".
* - `-A` means to parse A and discard its output.
* - `A or B` means to try in order the listed parsers until one succeeds.
* - `!A` means A is optional.
* - `parser { A }` is used to lazily reference A for recursion.
*/
@ItsDoot
ItsDoot / Merchant.java
Created March 4, 2020 22:51
A merchant service
package org.spongepowered.api.service.merchant;
import org.spongepowered.api.CatalogType;
import org.spongepowered.api.service.economy.account.Account;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
public interface Merchant extends CatalogType {
@ItsDoot
ItsDoot / PermissionDescription.java
Last active November 21, 2019 01:38
Sponge Permission Presets API
package pw.dotdash.msh.test;
import org.spongepowered.api.text.Text;
import javax.annotation.Nullable;
import java.util.Optional;
/**
* A description object for permissions.
*
@ItsDoot
ItsDoot / RTuple.kt
Created August 23, 2019 00:33
recursively right-expanding kotlin tuple type
class RTuple<out A, out B>(val head: A, val tail: B) {
companion object {
operator fun <A, B, C> invoke(a: A, b: B, c: C): RTuple<A, RTuple<B, C>> =
RTuple(a, RTuple(b, c))
operator fun <A, B, C, D> invoke(a: A, b: B, c: C, d: D): RTuple<A, RTuple<B, RTuple<C, D>>> =
RTuple(a, RTuple(b, RTuple(c, d)))
operator fun <A, B, C, D, E> invoke(a: A, b: B, c: C, d: D, e: E): RTuple<A, RTuple<B, RTuple<C, RTuple<D, E>>>> =
@ItsDoot
ItsDoot / events.md
Last active February 9, 2020 18:42
Sponge InteractEvent Guide

Tested on

  • spongeforge-1.12.2-2838-7.1.7-RC3928
  • spongevanilla-1.12.2-7.1.7-RC297
  • spongeforge-1.12.2-2825-7.1.6
  • spongevanilla-1.12-2-7.1.6

Events are listed in the order that they are fired.

  • left click
    • no held item
@ItsDoot
ItsDoot / MyPlugin.java
Created July 11, 2019 06:00
Getting started with custom CatalogTypes in Sponge
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.GameRegistryEvent;
import org.spongepowered.api.event.game.state.GameConstructionEvent;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.plugin.Plugin;
@ItsDoot
ItsDoot / CommandTree.kt
Created June 17, 2019 05:55
g e n e r i c s
/**
* @param S The command source type
* @param V The command argument value type
* @param R The command result type
* @param E The command exception type
* @param Text The text type
*/
sealed class CommandTree<in S, in V, out R, E : Exception, Text>(
private val errorType: KClass<out E>,
private val errorFunc: CommandErrorFunction<S, V, R, out E, Text>,