Skip to content

Instantly share code, notes, and snippets.

View jarcode-foss's full-sized avatar

Levi Webb jarcode-foss

  • Canada, BC
View GitHub Profile
@jarcode-foss
jarcode-foss / JavaMacros
Created January 7, 2015 02:23
Simple Java Macros (with examples for POE)
import com.sun.jna.Library;
import com.sun.jna.Native;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.jnativehook.mouse.NativeMouseEvent;
import org.jnativehook.mouse.NativeMouseInputListener;
import java.awt.*;
package jarcode.consoles;
import net.minecraft.server.v1_8_R2.*;
import java.lang.reflect.Field;
import java.util.Arrays;
public class CommandBlockListenerWrapper extends CommandBlockListenerAbstract {
private static final Field COMMAND_RESULT, CHAT_COMPONENT;
package jarcode.consoles;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import jarcode.consoles.bungee.ConsoleBungeeHook;
import jarcode.consoles.computer.ComputerHandler;
import jarcode.consoles.util.LocalPosition;
import jarcode.consoles.util.PacketUtils;
import jarcode.consoles.util.Region;
import net.minecraft.server.v1_8_R2.*;
boolean updated = false;
int i = 1 << scale;
int l = MathHelper.floor(updateX - (double) centerX) / i + 64;
int i1 = MathHelper.floor(updateZ - (double) centerZ) / i + 64;
int j1 = 128 / i;
if(world.worldProvider.o()) {
j1 /= 2;
}
gson = new GsonBuilder()
.registerTypeAdapter(ConsoleMeta.class, new JsonSerializer<ConsoleMeta>() {
@Override
public JsonElement serialize(ConsoleMeta consoleMeta, Type type,
JsonSerializationContext jsonSerializationContext) {
JsonObject object = new JsonObject();
object.add("location",
locationTypeAdapter.serialize(consoleMeta.location, null, jsonSerializationContext));
object.add("face", new JsonPrimitive(consoleMeta.face.name()));
package ca.jarcode.consoles.util.gson;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import com.google.gson.*;
import java.lang.reflect.Type;
public class LocationTypeAdapter implements JsonSerializer<Location>, JsonDeserializer<Location> {
@jarcode-foss
jarcode-foss / luaF.c
Created December 20, 2015 14:01
fast split function for Lua
// Faster split method, the only alternative within lua is using gsub, which
// is insanely slower. This function will actually return strings on the stack,
// so {str:split(d)} can be used to collect the return values in a table
//
// A more memory effecient use would be to use string.fsplit rather than using
// a table construct
//
// this avoids extra memory bloat and will keep the resulting strings on the stack
static int luaF_split(lua_State* state) {
if (lua_isstring(state, 1) && lua_isstring(state, 2)) {
@jarcode-foss
jarcode-foss / jmp_stack.h
Created January 9, 2016 00:10
setjmp stack utility
/*
An extremely simple set of macros for jumping and setting jmp_buf's in a stack to simulate very
basic exception handling
*/
#ifndef LUAB_JMP_H_
#define LUAB_JMP_H_
private final Object WAIT_LOCK = new Object();
private int taskCount = 0;
@FunctionalInterface
public interface SafeAsyncTask<E extends Throwable> {
public void run() throws E;
}
public void safeAsyncTask(final SafeAsyncTask task) {
/* 'eye' is the location of */
double yaw = eye.getYaw() > 0 ? eye.getYaw() : 360 - Math.abs(eye.getYaw()); // remove negative degrees
yaw += 90; // rotate +90 degrees
if (yaw > 360)
yaw -= 360;
yaw = (yaw * Math.PI) / 180;
double pitch = ((eye.getPitch() + 90) * Math.PI) / 180;
// player-space