Skip to content

Instantly share code, notes, and snippets.

@grondag
grondag / CubeMesh.java
Created August 17, 2019 23:13
Mesh Builder example
public Mesh cubeMeshExample() {
final int baseColor = 0xFF50565D;
final Renderer renderer = (Renderer) RendererAccess.INSTANCE.getRenderer();
final MeshBuilder mb = renderer.meshBuilder();
final QuadEmitter qe = mb.getEmitter();
final RenderMaterial mat = renderer.materialFinder().blendMode(0, TRANSLUCENT).find();
SpriteAtlasTexture atlas = MinecraftClient.getInstance().getSpriteAtlas();
final Sprite spriteBase = atlas.getSprite(new Identifier(MODID, "block/your_sprite_name"));
@grondag
grondag / column_block.java
Created August 13, 2019 00:05
Lit column block example
final SimpleModelState defaultState = XmPrimitives.COLUMN_SQUARE.newState()
.paint(SquareColumnPrimitive.SURFACE_MAIN, XmPaint.finder()
.textureDepth(2)
.texture(0, XmTextures.BIGTEX_SANDSTONE)
.textureColor(0, 0xFF99BBAA)
.texture(1, XmTextures.BORDER_GRITTY_SINGLE_LINE)
.blendMode(1, BlockRenderLayer.TRANSLUCENT)
.textureColor(1, 0xFF709080)
.find())
.paint(SquareColumnPrimitive.SURFACE_CUT, XmPaint.finder()
@grondag
grondag / FluidVolume.java
Last active July 24, 2019 19:45
Fluid API Sketch: FluidVolume
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
fabric grondag$ ./gradlew genSources --stacktrace
> Configure project :
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
Fabric Loom: 0.2.3-SNAPSHOT Build(jenkins #4)
[07:34:01] [ForkJoinPool-1-worker-3/WARN]: Mod ID fabric uses outdated schema version: 0 < 1
[07:34:01] [main/INFO]: [FabricLoader] Loading 10 mods: fermion@0.4.2, canvas@0.5.9, smart_chest@${version}, roughlyenoughitems@2.7.11+build.97, modmenu@1.4.0-71, fabric@0.2.7+build.127, fabricloader@0.4.2+build.132, frex@0.4.1, cloth@0.3.1+build.23, cloth-config@0.2.0+build.12
[07:34:01] [main/WARN]: Mod `smart_chest` (${version}) does not respect SemVer - comparison support is limited.
[07:34:01] [main/INFO]: SpongePowered MIXIN Subsystem Version=0.7.11 Source=file:/Users/grondag/.gradle/caches/modules-2/files-2.1/net.fabricmc/sponge-mixin/0.7.11.23/1a4dddae0dbef2894a98187e891038097e1729c4/sponge-mixin-0.7.11.23.jar Service=Knot/Fabric Env=CLIENT
[07:34:01] [main/INFO]: Loaded Fabric development mappings for mixin remapper!
[07:34:01] [main/INFO]: Compatibility level set to JAVA_8
[07:34:01] [main/ERROR]: Mixin config canvas.client.json does not specify "minVersion" property
[07:34:01] [main/ERROR]: Mixin config net
@grondag
grondag / Server Tick API - Core Elements
Last active February 25, 2019 20:45
Server-Side Concurrency API - Sketch
public interface SimulationTickable
{
/**
* If true, then {@link #doOnTick(int)} will be called during
* world tick from server thread. Is generally only checked
* at setup so result should not be dynamic.
*/
public default boolean doesUpdateOnTick() { return false; }
/**
@grondag
grondag / Mesh transformer
Created February 19, 2019 21:47
Mesh transformer
static ThreadLocal<MeshTransformer> glowTransform = ThreadLocal.withInitial(GlowTransform::new);
static class BeTestTransform implements MeshTransformer {
static RenderMaterial matSolid = RendererAccess.INSTANCE.getRenderer().materialFinder()
.blendMode(0, SOLID).find();
static RenderMaterial matSolidGlow = RendererAccess.INSTANCE.getRenderer().materialFinder()
.blendMode(0, SOLID).disableDiffuse(0, true).disableAo(0, true).emissive(0, true).find();
@grondag
grondag / gist:c1aa6af7c0815c3b00771e73293b2f15
Created February 17, 2019 15:53
Benchmark: vertex attribute access patterns
Benchmark Mode Cnt Score Error Units
VertexAccess.testQuadIndexed thrpt 25 1792.170 ± 35.819 ops/s
VertexAccess.testVertexDirect thrpt 25 1854.714 ± 7.662 ops/s
VertexAccess.testVertexIndexed thrpt 25 1847.824 ± 26.582 ops/s
public class VertexAccess {
class Quad {
static final int VERTEX_STRIDE = 16;
static final int QUAD_STRIDE = VERTEX_STRIDE * 4;
vec4 diffuseColor()
{
#ifdef SOLID
float non_mipped = bitValue(v_flags, 3) * -4.0;
vec4 a = texture2D(u_textures, v_texcoord_0, non_mipped);
float cutout = bitValue(v_flags, 4);
if(cutout == 1.0 && a.a < 0.5)
discard;
#else
@grondag
grondag / interface_benchmark_result.txt
Created January 15, 2019 15:40
Performance impact of instanceof test for interfaces
===============================
BENCHMARK CODE
===============================
package grondag.benchmark;
import java.util.Random;
import org.openjdk.jmh.annotations.Benchmark;