Skip to content

Instantly share code, notes, and snippets.

View TelepathicGrunt's full-sized avatar
🦎
Just chilling around!

TelepathicGrunt TelepathicGrunt

🦎
Just chilling around!
View GitHub Profile

NOTE: Gist contents is moved to this repo for easier maintaining and record-keeping: https://github.com/neoforged/.github/tree/main/changes/technical_changes

A small selection of changes that were done in NeoForge since it's creation. This is not all of them. Most changes can be seen in PRs and Commits on the NeoForged GitHub organization's repositories.


Mod Loader

  1. Multiple mod entry points allowed now. Can even specify an entry point to be client only for better client code separation.
    https://docs.neoforged.net/docs/concepts/sides#mod

  2. Capability refactor to split it into Data Attachment and Capabilities separately and cleaner.https://docs.neoforged.net/docs/datastorage/attachmentshttps://docs.neoforged.net/docs/datastorage/capabilities
public static List<BlockPos> matchingBlocksOfKindInRange(Level level, BlockPos centerPos, int radius, Predicate<BlockState> predicate) {
List<BlockPos> validPos = new ObjectArrayList<>();
// Figure out how many chunk radius we need to search outward to encompass the radius properly
ChunkPos maxChunkPos = new ChunkPos(
SectionPos.blockToSectionCoord(centerPos.getX() + radius),
SectionPos.blockToSectionCoord(centerPos.getZ() + radius)
);
ChunkPos minChunkPos = new ChunkPos(
@TelepathicGrunt
TelepathicGrunt / NetworkingComparison.md
Last active June 7, 2024 11:40
Forge 1.19.2 networking vs Fabric 1.19.2 networking

Forge

Packet class

public record CrystallineFlowerEnchantmentPacket(int containerId, List<EnchantmentSkeleton> enchantmentSkeletons) {
    public static Gson gson = new GsonBuilder().create();

    public static void sendToClient(ServerPlayer entity, int containerId, List<EnchantmentSkeleton> enchantmentSkeletons) {
        MessageHandler.DEFAULT_CHANNEL.send(PacketDistributor.PLAYER.with(() -> entity),

Biome Tags are awesome!

As a result of 1.18.2 changes, all worldgen registries can now have tags. Including biomes! As a result of this, Mojang has deprecated the biome category which means that sooner or later, this enum will be deleted. To better protect yourself and your mod/datapack from relying on these categories, you should instead, switch to using biome tags.

The existing biome tags from vanilla do not cover all usecases which means that many modders have started banding together to decide on common biome tags to use. These common biome tags are under the forge: namespace and the c: namespace.

For best compatibility with any mod or datapack, you should have a custom tag that pulls entries from minecraft:, forge:, and c: tags. Yes, datapacks too should be adding their biomes to the forge: and c: namespaced tags. And mods can "datagen" the tag json files automatically but that is outside the scope of this gist. See the Fabric wiki or [Forge Comm

// FORGE
@Mod(Test.MODID)
public class Test {
public static final String MODID = "test";
// A Feature + Config to say how the feature should generate.
public static ConfiguredFeature<?, ?> CUSTOM_ORE_CF;
// A ConfiguredFeature + 0 or more Placement Modifiers that tells the
// ConfiguredFeature where and how often it should generate in chunks.
public static PlacedFeature CUSTOM_ORE_PF;
@TelepathicGrunt
TelepathicGrunt / addNewBuildingsVillages.java
Last active September 12, 2024 13:05
How to add new buildings to villages and other jigsaw structures
// Note: Lithostitch mod allows you to add to template pools easily! No code needed.
// https://github.com/Apollounknowndev/lithostitched/wiki/Worldgen-Modifiers#add_template_pool_elements
// This gist code is public domain. Take it! Steal it! AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!
// 1.18.2 code at top. 1.16.5 version farther down
private static final ResourceKey<StructureProcessorList> EMPTY_PROCESSOR_LIST_KEY = ResourceKey.create(
Registry.PROCESSOR_LIST_REGISTRY, new ResourceLocation("minecraft", "empty"));
public ExampleMod() {

Forge PRs can be quite tricky to understand and get working but if you can get your new event or hook or fix into Forge, you benefit a ton of modders! Don't let the idea of a Forge PR scare you or seem too daunting! Just follow this gist and hopefully you'll get the hang of it!


The first step is check out gigaherz's gist for creating a PR:
https://gist.github.com/gigaherz/ca256fea517cb925dfc31d7cd48c487e


Forge's doc on making PRs with extra into and styling rules:
https://github.com/MinecraftForge/MinecraftForge/wiki/If-you-want-to-contribute-to-Forge

@TelepathicGrunt
TelepathicGrunt / outerclassinstance.md
Last active June 10, 2021 14:05
How-to-get outer class instance from inner class with mixin

When you mixin into a non-static inner class, the inner class has a hidden field that stores the instance of the outer class. It is a bit tricky to get it but it can be done.

Forge:

Step one, go to the Forge jar and find the class in question. Open it in Intellij

https://i.imgur.com/Dnrv3Kv.png

https://i.imgur.com/F1bPHRG.png

@TelepathicGrunt
TelepathicGrunt / addModdedCropsToVillageFarms.java
Last active September 26, 2024 16:17
how to add to village farms in a mod/datapack compatible way that can stack without overwriting each other.
// Note: Lithostitch mod allows you to add to processor lists easily! No code needed.
// https://github.com/Apollounknowndev/lithostitched/wiki/Worldgen-Modifier-Types#add_processor_list_processors
// This gist code is public domain. Take it! Steal it! AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!
// 1.18.2+
public ExampleMod() {
MinecraftForge.EVENT_BUS.addListener(this::addNewVillageCrop);
}

What are mixins?

Mixins are a way to inject code or change the minecraft source code directly and should be use with caution. If you can do a PR to Forge or use an event, try those first. If all else fails, then mixins may be a good option to look into. Here are some resources for mixins:

Now, I'll be honest, the official mixin doc is kind of terrible to learn from for most people. It's extremely dense and and really only helps people who already knows in-depth bytecode and stuff. But most modders aren't like that and just wants to do small stuff lol. But I'll give you the run-down here. There's a few kinds of mixins that you will encounter quite often.