GitLab's annual major release is around the corner. Along with a lot of new and exciting features, there will be a few breaking changes. Learn more here.

Verified Commit 72a20c17 authored by deftware's avatar deftware 💤
Browse files

Fix custom block registration

parent d3420642
Pipeline #264849136 passed with stages
in 6 minutes and 15 seconds
package me.deftware.mixin.mixins.game;
import me.deftware.mixin.shared.RegistryManagement;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = ForgeRegistry.class, remap = false)
public class MixinForgeRegistry<V extends IForgeRegistryEntry<V>> {
@Inject(method = "register", at = @At("HEAD"), remap = false)
private void register(V value, CallbackInfo ci) {
RegistryManagement.register(value, value.getRegistryName());
}
}
package me.deftware.mixin.mixins.game;
import me.deftware.client.framework.registry.BlockRegistry;
import me.deftware.client.framework.registry.ItemRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import me.deftware.mixin.shared.RegistryManagement;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Mixin;
......@@ -16,11 +13,7 @@ public class MixinRegistry {
@Inject(method = "register(Lnet/minecraft/util/registry/Registry;Lnet/minecraft/util/ResourceLocation;Ljava/lang/Object;)Ljava/lang/Object;", at = @At("HEAD"))
private static <V, T extends V> void register(Registry<V> registry, ResourceLocation id, T entry, CallbackInfoReturnable<T> cir) {
if (entry instanceof Block) {
BlockRegistry.INSTANCE.register(id.toString(), (Block) entry);
} else if (entry instanceof Item) {
ItemRegistry.INSTANCE.register(id.toString(), (Item) entry);
}
RegistryManagement.register(entry, id);
}
}
package me.deftware.mixin.shared;
import me.deftware.client.framework.registry.BlockRegistry;
import me.deftware.client.framework.registry.ItemRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
public class RegistryManagement {
public static <T> void register(T entry, ResourceLocation id) {
if (entry instanceof Block) {
BlockRegistry.INSTANCE.register(id.toString(), (Block) entry);
} else if (entry instanceof Item) {
ItemRegistry.INSTANCE.register(id.toString(), (Item) entry);
}
}
}
......@@ -28,6 +28,7 @@
"game.MixinMinecraft",
"game.MixinSoundSystem",
"game.MixinTimer",
"game.MixinForgeRegistry",
"gui.MixinChatSuggestion",
"gui.MixinCreativeInventoryScreen",
"gui.MixinDebugHud",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment