Jump to content

[Solved][1.12.2] How to register custom modeled TileEntity?


Recommended Posts

I'm trying to get a custom modeled block, in the same fashion as the enchanted book on the Enchanting Table, registered and rendered properly.

 

I thought this line was likely what I needed and have tried using it in the same place I register all the renders for my mobs:

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityXelNagaPylon.class, new TileEntityXelNagaPylonRenderer());

 

When you place the block, it displays and animates correctly. However, when you log into the game, the block is invisible unless you left or right click on it. Then the model displays and animates correctly. After playing with it for a while, I have a strong hunch that I should not be using the above line at all. What is the proper way to register a custom modeled block?

 

Here is how I handle the TileEntity registrations if needed:

	@SubscribeEvent
	public static void onBlockRegister(RegistryEvent.Register<Block> event)
	{	
		event.getRegistry().registerAll(KindredLegacyBlocks.BLOCKS.toArray(new Block[0]));

		TileEntityHandler.registerTileEntities();
	}
public static void registerTileEntities()
{
	GameRegistry.registerTileEntity(TileEntityXelNagaPylon.class, new ResourceLocation(ModInfo.MOD_ID, "xelnaga_pylon"));
	GameRegistry.registerTileEntity(TileEntityVespeneCondenser.class, new ResourceLocation(ModInfo.MOD_ID, "vespene_condenser"));
}

 

If it needs mentioning, these are not hybrid model blocks like the Enchanting Table is. Their appearances are entirely defined in their model classes.

Edited by FuzzyAcornIndustries
Problem is solved.
Link to comment
Share on other sites

public class BlockXelNagaPylon extends BlockBase
{
	public BlockXelNagaPylon()
	{
		super("xelnaga_pylon", Material.ROCK);
		
		this.setHardness(2.0F);
		this.setResistance(10.0F);
		this.setLightLevel(0.5F);
	}

	@Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
	
	@Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
	
	@Override
    public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
	{
		float xx = (float) pos.getX() + 0.5F, yy = (float) pos.getY() + rand.nextFloat() * 6.0F / 16.0F, zz = (float) pos.getZ() + 0.5F, xx2 = rand.nextFloat() * 0.3F - 0.2F, zz2 = 0.5F;
		
		worldIn.spawnParticle(EnumParticleTypes.SPELL_INSTANT, (double) (xx), (double) yy, (double) (zz), 0.0F, 0.0F, 0.0F);
	}
	
	@Override
    public boolean hasTileEntity(IBlockState state)
    {
    	return true;
    }
    
	@Override
    public TileEntity createTileEntity(World world, IBlockState state)
	{
		return new TileEntityXelNagaPylon();
	}
}

 

Link to comment
Share on other sites

Ah! That might be the problem. I don't know where or how to register the TE renderer. Unless you mean the .bindTileEntitySpecialRenderer() mentioned above. That would be in these locations:

 

RenderHandler:

public static void registerTileEntityRenders()
{
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityXelNagaPylon.class, new TileEntityXelNagaPylonRenderer());
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityVespeneCondenser.class, new TileEntityVespeneCondenserRenderer());
}

 

RegistryHandler:

public static void preInitRegistries()
{
	KindredLegacyEntities.registerEntityMob();
	KindredLegacyEntities.registerEntityAbilities();
	KindredLegacyEntities.registerEntityProjectiles();
	RenderHandler.registerEntityRenders();
	RenderHandler.registerTileEntityRenders();
}


Main class:

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	ConfigHandler.preInit(event);

	isBiomesOPlentyEnabled = Loader.isModLoaded("biomesoplenty");
	isGalacticraftEnabled = Loader.isModLoaded("galacticraftcore");

	networkHelper = new NetworkHelper(ModInfo.CHANNEL2, PoketamableNamePacket.class);

	RegistryHandler.preInitRegistries();
}

 

A TileEntityRenderer:

public class TileEntityXelNagaPylonRenderer extends TileEntitySpecialRenderer<TileEntityXelNagaPylon>
{
    private static final ResourceLocation TEXTURE_XELNAGA_PYLON = new ResourceLocation(ModInfo.MOD_ID + ":" +"textures/blocks/xelnaga_pylon.png");
    private static final ResourceLocation TEXTURE_XELNAGA_PYLON_GLOWS = new ResourceLocation(ModInfo.MOD_ID + ":" +"textures/blocks/xelnaga_pylon_glows.png");
    private final ModelXelNagaPylon modelXelNagaPylon = new ModelXelNagaPylon();
    private final ModelXelNagaPylon modelXelNagaPylonGlows = new ModelXelNagaPylon();

    @Override
    public void render(TileEntityXelNagaPylon tileEntity, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
    {
		GL11.glPushMatrix();
		GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
		GL11.glRotatef(180, 0F, 0F, 1F);

		this.bindTexture(TEXTURE_XELNAGA_PYLON);

		GL11.glPushMatrix();
		this.modelXelNagaPylon.renderModel(0.0625F, (TileEntityXelNagaPylon)tileEntity);
		GL11.glPopMatrix();
		GL11.glPopMatrix();

		/* ************ */

		GL11.glPushMatrix();
		GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
		GL11.glRotatef(180, 0F, 0F, 1F);

		this.bindTexture(TEXTURE_XELNAGA_PYLON_GLOWS);

		float f1 = 1.0F;
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glDisable(GL11.GL_ALPHA_TEST);
		GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
		GL11.glDisable(GL11.GL_LIGHTING);
		char c0 = 61680;
		int j = c0 % 65536;
		int k = c0 / 65536;
		OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F);
		GL11.glEnable(GL11.GL_LIGHTING);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, f1);

		GL11.glPushMatrix();
		this.modelXelNagaPylonGlows.renderModel(0.0625F, (TileEntityXelNagaPylon)tileEntity);
		GL11.glDisable(GL11.GL_BLEND);
		GL11.glPopMatrix();
		GL11.glPopMatrix();
    }
}

 

There are probably issues with the render() function as I still have a hard time understanding all that GL11 code.

Link to comment
Share on other sites

I tested if the code ran while it was invisible but didn't until it was visible.

 

I am embarrassed to admit but I think I found what happened. As I was changing the code, I left the blocks that were already placed as is. As I was playing around with the blocks in the loaded environment just a few moments ago, I accidentally destroyed one. When I placed a new one down, it no longer turned invisible on loading the game.

 

I deeply thank you for looking at my code and confirming that I did most of this right! It was very difficult to get this far.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.