Skip to content

Instantly share code, notes, and snippets.

View JamiesWhiteShirt's full-sized avatar

Erlend Åmdal JamiesWhiteShirt

View GitHub Profile
@JamiesWhiteShirt
JamiesWhiteShirt / ModMidas.java
Last active November 11, 2016 22:17
Midas trait
package slimeknights.tconstruct.tools.modifiers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@JamiesWhiteShirt
JamiesWhiteShirt / Configuration.kt
Created May 17, 2017 22:28
Annotation based configuration with Kotlin
package com.jamieswhiteshirt.responsiveinventory
import net.minecraftforge.common.config.Config
@Config(modid = ResponsiveInventory.MODID)
object Configuration {
@JvmField
@Config.Comment("It's a test")
var test = 0
@JamiesWhiteShirt
JamiesWhiteShirt / BlockBase.java
Last active July 9, 2017 18:41
Common anti-patterns in Minecraft Modding
public class BlockBase extends Block {
public BlockBase(Material materialIn, ResourceLocation registryName) {
super(materialIn);
this.setRegistryName(registryName);
this.setUnlocalizedName(registryName.toString());
}
public void registerModel() {
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
}
@Override
public void registerModels() {
// ...
registerBlockModel(LWBlocks.SEALED_BARREL, "sealed_barrel");
// ...
}
private static void registerBlockModel(Block block, String name) {
registerItemModel(Item.getItemFromBlock(block), name);
}
@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>";
}
public class CommandPing extends CommandBase {
@Override
public String getCommandName() {
return "ping";
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "commands.ping.usage";
}
@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

@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.

[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.
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;