Replace BlockError mixin with event handler (#671)

* Replace BlockError mixin with event handler

Something is calling TextureMap.registerIcons before preInit() sets up
the BlockError reference. While adding a null check to the mixin would
also fix this, a mixin isn't needed here since forge exposes an event
for this purpose.

* Add client sideonly for texture stitch event

---------

Co-authored-by: Darren Eberly <[email protected]>
This commit is contained in:
RecursivePineappleandDarren Eberly authored and GitHub committed 2024-10-22 16:33:11 -04:00
1 parent 88936d3713
commit bd5cd350c3
3 files changed
+14 -30

No files matched your search

@@ -2,17 +2,17 @@ package com.gtnewhorizons.angelica.common;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
/**
* This Block is not actually getting registered. A static instance is created in AngelicaMod.
* In order to register the texture for it, there is a mixin to TextureMap which injects a call
* to this instance's registerBlocKIcons method. Actually registering the block on the client but
* not the server can cause block IDs to different between client/server, which is not good.
* Actually registering the block on the client but not the server can cause block IDs to
* different between client/server, which is not good.
* We're essentially injecting the block's texture, so that we may use this block as if it were
* any normal block for rendering purposes with RenderBlocks and such, but not have to actually
@@ -25,21 +25,24 @@ public class BlockError extends Block {
public BlockError() {
super(Material.rock);
MinecraftForge.EVENT_BUS.register(this);
}
@Override
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister reg)
{
for (int i = 0; i < icons.length; i++) {
icons[i] = reg.registerIcon("angelica:error_block_" + i);
public void onTextureStitch(TextureStitchEvent.Pre event) {
if (event.map.getTextureType() == 0) {
for (int i = 0; i < icons.length; i++) {
icons[i] = event.map.registerIcon("angelica:error_block_" + i);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
return icons[meta];
return meta >= 0 && meta < icons.length ? icons[meta] : null;
}
}
@@ -29,7 +29,6 @@ public enum Mixins {
,"angelica.MixinMinecraft"
,"angelica.optimizations.MixinRendererLivingEntity"
,"angelica.MixinFMLClientHandler"
,"angelica.MixinTextureMap"
)
),
ANGELICA_VBO(