Jump to content

[1.7.10] Rendering block in inventory (has a custom render)


M4thG33k

Recommended Posts

Greetings! I have been Googling for a few hours now, but I haven't seemed to be able to find what I'm looking for here. I have a block/TE combination that has a custom render (via the TESR I created for it). I also have been able to render the Item when held by a player (by the use of a class which extends IItemRenderer), but nothing I've tried is able to render the block as an item in my inventory. (I don't have current code to show since I deleted everything that didn't work after multiple attempts). I don't necessarily need the 3D render of the block to show up in the inventory (that would be ideal), but I would like to get some sort of icon there so that the player know what they are holding. Does anyone know of any methods to accomplish this task? (Feel free to point me toward tutorials for this sort of thing that already exists if there are any.) Thanks in advance!

Able to differentiate the difference of a sum and an integral.

Link to comment
Share on other sites

What youll need is a class that can render a tileentity. For this i have written a GenericItemRender like this:

 

 

 

package de.ItsAMysterious.mods.reallifemod.core.rendering.items;

 

import static org.lwjgl.opengl.GL11.GL_LIGHTING;

import static org.lwjgl.opengl.GL11.glDisable;

import static org.lwjgl.opengl.GL11.glEnable;

import static org.lwjgl.opengl.GL11.glPopMatrix;

import static org.lwjgl.opengl.GL11.glPushMatrix;

import static org.lwjgl.opengl.GL11.glRotated;

import static org.lwjgl.opengl.GL11.glScaled;

import static org.lwjgl.opengl.GL11.glTranslated;

import static org.lwjgl.opengl.GL11.glTranslatef;

import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraftforge.client.IItemRenderer;

 

 

public class GenericBlockItemRenderer implements IItemRenderer {

TileEntitySpecialRenderer render;

 

private TileEntity entity;

 

public GenericBlockItemRenderer(TileEntitySpecialRenderer render,

TileEntity entity) {

this.entity = entity;

this.render = render;

}

 

@Override

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

return true;

}

 

@Override

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item,

ItemRendererHelper helper) {

return true;

}

 

@Override

public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

if (type == IItemRenderer.ItemRenderType.ENTITY)

glTranslatef(-0.5F, 0.0F, -0.5F);

                glPushMatrix();

              //Do if-clauses here when an item should be scaled up or down, translated or rotated while being rendered

 

TileEntityRendererDispatcher.instance.renderTileEntityAt(entity, 0.0D,0.0D, 0.0D, 0.0F);

glPopMatrix();

}

 

}

 

 

To use this simply do this in your ClientProxy:

MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(YourBlock),

new GenericBlockItemRenderer(new YourTileEntityRenderer(),

new YourTileEntity()));

Link to comment
Share on other sites

Well, that fixed the issue of the item rendering when dropped on the ground (which I expected since we were only using the new class to render the item if the render type was ENTITY), but I still don't have the item being shown in my inventory. (The inventory space still looks blank.) I don't see how to adapt this to fix my issue...

Able to differentiate the difference of a sum and an integral.

Link to comment
Share on other sites

Well, that fixed the issue of the item rendering when dropped on the ground (which I expected since we were only using the new class to render the item if the render type was ENTITY), but I still don't have the item being shown in my inventory. (The inventory space still looks blank.) I don't see how to adapt this to fix my issue...

It probably is rendered, but somewhere on other side of screen.

In debug mode, open inventory with item and in rendertype.inventory - try to play with gl11.translated and gl11.scaled...

Link to comment
Share on other sites

I have placed a break point in the if-statement in which I am supposedly rendering the item in my inventory, but it does not catch until after I have dropped the item on the ground.

 

 

 

@Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data)
    {
        if (type == ItemRenderType.ENTITY)
        {
            //breakpoint here
            GL11.glTranslatef(-0.5f,0.0f,-0.5f);
            GL11.glPushMatrix();
            //GL11.glScalef(1.0f,1.0f,1.0f);
            //GL11.glTranslatef(0.0f,0.0f,0.0f);
            TileEntityRendererDispatcher.instance.renderTileEntityAt(entity,0.0,0.0,0.0,0.0f);
            GL11.glPopMatrix();
        }
    }

 

 

Able to differentiate the difference of a sum and an integral.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you are using AMD/ATI, get the latest drivers from their website - do not update via system
    • So I don't have any other mods and I try to install my first mod. At first I tried turning on Forge but it didn't work for me. I entered into these logs and this is what debug I found.   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0. 9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   -------------------------------------------------------------   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.428] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [fmlclientdev,forgeclient,minecraft,forgegametestserverdev,fmlserveruserdev,fmlclient,fmldatauserdev,forgeserverdev,forgeserveruserdev,forgeclientdev,forgeclientuserdev,forgeserver,forgedatadev,fmlserver,fmlclientuserdev,fmlserverdev,forgedatauserdev,testharness,forgegametestserveruserdev] [05maj2024 19:29:16.448] [main/DEBUG] [cpw.mods.modlauncher.NameMappingServiceHandler/MODLAUNCHER]: Found naming services : [srgtomcp] [05maj2024 19:29:16.468] [main/DEBUG] [cpw.mods.modlauncher.LaunchPluginHandler/MODLAUNCHER]: Found launch plugins: [mixin,eventbus,slf4jfixer,object_holder_definalize,runtime_enum_extender,capability_token_subclass,accesstransformer,runtimedistcleaner] [05maj2024 19:29:16.485] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Discovering transformation services [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path GAMEDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path MODSDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft\mods [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path CONFIGDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft\config [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path FMLCONFIG is C:\Users\Tadeusz\AppData\Roaming\.minecraft\config\fml.toml [05maj2024 19:29:16.550] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Found additional transformation services from discovery services:  [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   Can you help me with this?
    • So I don't have any other mods and I try to install my first mod. At first I tried turning on Forge but it didn't work for me. I entered into these logs and this is what debug I found.   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0. 9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   Can you help me with this?  
    • Thank you so, so much for your help! I have implemented the code from the example you gave me and it has been excepted, the only downside currently being that the game crashes on launch, saying:  Caused by: java.lang.IllegalStateException: Cannot register new entries to DeferredRegister after RegisterEvent has been fired.  (Three times) and  Caused by: java.lang.ExceptionInInitializerError (Two times) With further scanning I have found this error: 2024-05-05T18:41:24.287+0100 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] I am not exactly sure what to do with these errors but I am sure I can resolve them. Once again, thank you for your help! It is much appreciated. 😁
  • Topics

×
×
  • Create New...

Important Information

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