Skip to content

Instantly share code, notes, and snippets.

View JamiesWhiteShirt's full-sized avatar

Erlend Åmdal JamiesWhiteShirt

View GitHub Profile
@JamiesWhiteShirt
JamiesWhiteShirt / ParticleFactoryRegistry.java
Last active March 17, 2020 23:41
Particle factory registry
public class ParticleFactoryRegistry {
private static final Constructor<? extends SpriteProvider> SIMPLE_SPRITE_PROVIDER_CONSTRUCTOR;
static {
try {
String intermediaryClassName = "net.minecraft.class_702$class_4090";
String currentClassName = FabricLoader.getInstance().getMappingResolver().mapClassName("intermediary", intermediaryClassName);
@SuppressWarnings("unchecked")
Class<? extends SpriteProvider> clazz = (Class<? extends SpriteProvider>) Class.forName(currentClassName);
SIMPLE_SPRITE_PROVIDER_CONSTRUCTOR = clazz.getDeclaredConstructor(ParticleManager.class);
SIMPLE_SPRITE_PROVIDER_CONSTRUCTOR.setAccessible(true);
@JamiesWhiteShirt
JamiesWhiteShirt / ItemImageExporter.java
Created September 13, 2019 13:35
ItemImageExporter
package com.jamieswhiteshirt.developermode.client;
import com.mojang.blaze3d.platform.GLX;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.GlFramebuffer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.GuiLighting;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import React from 'react';
import PropTypes from 'prop-types';
import KsPropTypes from 'ks/components/KsPropTypes';
const statusTypes = {
none: 'none',
pending: 'pending',
rejected: 'rejected',
resolved: 'resolved',
};
package com.jamieswhiteshirt.redox.common;
import com.jamieswhiteshirt.redox.common.block.RedoxFluidBlock;
import com.jamieswhiteshirt.redox.common.fluid.RedoxFluid;
import com.jamieswhiteshirt.redox.common.fluid.RedoxFluids;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
[12:42:49] [Server thread/FATAL]: Error executing task on Server
java.lang.ClassCastException: net.minecraft.class_3898$class_3208 cannot be cast to net.fabricmc.fabric.impl.server.EntityTrackerStreamAccessor
at net.minecraft.class_3898.fabric_getTrackingPlayers(class_3898.java:1044) ~[intermediary-fabric-loader-0.4.2+build.130-1.14%20Pre-Release%205+build.4.jar:?]
at net.fabricmc.fabric.api.server.PlayerStream.watching(PlayerStream.java:86) ~[fabric-0.2.7+build.126.jar:?]
at com.jamieswhiteshirt.clotheslinefabric.common.item.ConnectorItem.applyConnectorState(ConnectorItem.java:76) ~[clothesline-fabric-0.0.14-all.jar:?]
at com.jamieswhiteshirt.clotheslinefabric.common.item.ConnectorItem.method_7840(ConnectorItem.java:45) ~[clothesline-fabric-0.0.14-all.jar:?]
at net.minecraft.class_1799.method_7930(class_1799.java:458) ~[intermediary-fabric-loader-0.4.2+build.130-1.14%20Pre-Release%205+build.4.jar:?]
at net.minecraft.class_1309.method_6075(class_1309.java:2655) ~[intermediary-fabric-loader-0.4.2+build.
@JamiesWhiteShirt
JamiesWhiteShirt / cursegradle.md
Last active October 18, 2021 15:59
How to publish your Fabric mod with CurseGradle

How to publish your Fabric mod with CurseGradle

CurseGradle is a Gradle plugin that lets you publish artifacts to CurseForge. Consult the CurseGradle wiki for the full details. It works out of the box for ForgeGradle projects, but requires a bit of configuration for Fabric projects, which is the subject of this gist.

CurseGradle will assume the environment is a ForgeGradle environment, so its integration has to be manually switched off. Without ForgeGradle, CurseGradle doesn't know which Minecraft version you are working with, so it has to be specified manually. The correct main artifact is the output of the remapJar task.

@JamiesWhiteShirt
JamiesWhiteShirt / GlStateManager.md
Last active July 7, 2024 02:26
Why you should never use OpenGL directly or GlStateManager.pushAttrib/popAttrib

OpenGL calls, OpenGL state, and state leaks

Making OpenGL calls has a performance cost. It is therefore desirable to reduce the amount of calls.

OpenGL has global state. The state is modified by enabling/disabling blending/culling/alpha testing/etc, specifying the blend function, changing the cull face, etc.

A state leak happens when a method leaves OpenGL in a different state after being called. This is generally undesirable as it often breaks expectations about the OpenGL state in other methods.

Modifying the OpenGL state requires OpenGL calls. Minecraft is not particularly optimized for reducing the amount of OpenGL calls, but makes an attempt using GlStateManager.

GlStateManager

public class CommandPing extends CommandBase {
@Override
public String getCommandName() {
return "ping";
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "commands.ping.usage";
}
@JamiesWhiteShirt
JamiesWhiteShirt / CommandPing.java
Last active July 16, 2017 16:38
Incorrect command
public class CommandPing extends CommandBase {
@Override
public String getCommandName() {
return "ping";
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "/ping <something>";
}
@Override
public void registerModels() {
// ...
registerBlockModel(LWBlocks.SEALED_BARREL, "sealed_barrel");
// ...
}
private static void registerBlockModel(Block block, String name) {
registerItemModel(Item.getItemFromBlock(block), name);
}