Jump to content

Recommended Posts

Posted

This is probably answered somewhere, if so a link to it will suffice, I did a few quick searches and found nothing. Basically in 1.7.10 we used IItemRenderer to make custom models render in the inventory, these are models that are just java files (Like the chest) and not json, is there still a way to get these to render in the inventory?

MinecraftForgeClient.registerItemRenderer(item, IItemRenderer) still exists however it doesn't seem to work.

Posted

Hi

 

I would recommend converting your obj model to the json blockmodel format.  With an ISmartItemModel you can return whatever list of Quads you want for rendering.

 

Otherwise -

IItemRenderer has been abandoned; Forge doesn't support using models for item rendering (yet?) so you will need to use Reflection to insert your rendering code into the right place. 

 

If it were me, I would probably create a custom class extending RenderItem, override the    public void renderItemIntoGUI(ItemStack stack, int x, int y) to call my custom rendering code if stack==myItem.  Use reflection to insert your custom class into the vanilla code, either right at creation in Minecraft.startGame() if possible, or otherwise overwriting the various fields that it is stored in.

 

No guarantee it will work, and it's not terribly compatible with any other mods who think to do the same, but it's the only way I can think of.  Stick with ISmartItemModel if you can...

 

-TGG

 

 

Posted

I have no idea how ISmartItemModel works, I know there's a few tutorials but I just can't wrap my head around any of them. I don't jave a .obj model as I said it is a java file, like ModelChest and ModelBanner things like that. If there's a tool to convert those into the json block model format a link would be great.

 

package com.sixonethree.randomutilities.client.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelMagicChest extends ModelBase {
public ModelRenderer shape1;
public ModelRenderer shape1_1;
public ModelRenderer shape1_2;
public ModelRenderer shape1_3;
public ModelRenderer shape1_4;
public ModelRenderer shape1_5;
public ModelRenderer shape1_6;
public ModelRenderer shape1_7;

public ModelMagicChest() {
	this.textureWidth = 64;
	this.textureHeight = 64;
	this.shape1 = new ModelRenderer(this, 0, 17);
	this.shape1.setRotationPoint(-7.0F, 9.0F, -7.0F);
	this.shape1.addBox(0.0F, 0.0F, 0.0F, 14, 1, 14, 0.0F);
	this.shape1_6 = new ModelRenderer(this, 0, 0);
	this.shape1_6.setRotationPoint(-8.0F, 23.0F, -8.0F);
	this.shape1_6.addBox(0.0F, 0.0F, 0.0F, 16, 1, 16, 0.0F);
	this.shape1_5 = new ModelRenderer(this, 0, 48);
	this.shape1_5.setRotationPoint(-8.0F, 9.0F, -8.0F);
	this.shape1_5.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
	this.shape1_7 = new ModelRenderer(this, 0, 17);
	this.shape1_7.setRotationPoint(-7.0F, 22.0F, -7.0F);
	this.shape1_7.addBox(0.0F, 0.0F, 0.0F, 14, 1, 14, 0.0F);
	this.shape1_2 = new ModelRenderer(this, 0, 0);
	this.shape1_2.setRotationPoint(-8.0F, 8.0F, -8.0F);
	this.shape1_2.addBox(0.0F, 0.0F, 0.0F, 16, 1, 16, 0.0F);
	this.shape1_4 = new ModelRenderer(this, 0, 48);
	this.shape1_4.setRotationPoint(7.0F, 9.0F, 7.0F);
	this.shape1_4.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
	this.shape1_3 = new ModelRenderer(this, 0, 48);
	this.shape1_3.setRotationPoint(7.0F, 9.0F, -8.0F);
	this.shape1_3.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
	this.shape1_1 = new ModelRenderer(this, 0, 48);
	this.shape1_1.setRotationPoint(-8.0F, 9.0F, 7.0F);
	this.shape1_1.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
}

@Override public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
	this.shape1.render(f5);
	this.shape1_6.render(f5);
	this.shape1_5.render(f5);
	this.shape1_7.render(f5);
	this.shape1_2.render(f5);
	this.shape1_4.render(f5);
	this.shape1_3.render(f5);
	this.shape1_1.render(f5);
}

/** This is a helper function from Tabula to set the rotation of model parts */
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
	modelRenderer.rotateAngleX = x;
	modelRenderer.rotateAngleY = y;
	modelRenderer.rotateAngleZ = z;
}
}

 

That's what I use for the actual block, I use a TESR for it and it works fine, however rendering in the inventory it does not.

Posted

Hi

 

There's no tool I know of that will convert that automatically.

 

You could perhaps fiddle with the model renderer to (eg) pull out the ModelBox quad lists and convert them to a BlockModel quad list; your ISmartItemModel.handleItemState() could update the animation settings and generate the new quadlist.

 

So it would look something like

 

ISmartItemModel.handleItemState(): set up the ModelRenderer as per your code, and copy the model quads into a format suitable for BlockModel, so that IBlockModel.getGeneralQuads() returns the list of quads that would normally be rendered by the ModelRenderer.render().

 

I think that would be hard work to implement even for a rather experience modder.  But it might be useful to a lot of people if you could crack it.

 

-TGG

 

 

Posted

As I said though I can't seem to wrap my head around the ISmartItemModel, IBakedModel, anything like that. I'm sure it's possible to convert

 

public class ModelMagicChest extends ModelBase {
public ModelRenderer shape1;
public ModelRenderer shape1_1;
public ModelRenderer shape1_2;
public ModelRenderer shape1_3;
public ModelRenderer shape1_4;
public ModelRenderer shape1_5;
public ModelRenderer shape1_6;
public ModelRenderer shape1_7;

public ModelMagicChest() {
	this.textureWidth = 64;
	this.textureHeight = 64;
	this.shape1 = new ModelRenderer(this, 0, 17);
	this.shape1.setRotationPoint(-7.0F, 9.0F, -7.0F);
	this.shape1.addBox(0.0F, 0.0F, 0.0F, 14, 1, 14, 0.0F);
	this.shape1_6 = new ModelRenderer(this, 0, 0);
	this.shape1_6.setRotationPoint(-8.0F, 23.0F, -8.0F);
	this.shape1_6.addBox(0.0F, 0.0F, 0.0F, 16, 1, 16, 0.0F);
	this.shape1_5 = new ModelRenderer(this, 0, 48);
	this.shape1_5.setRotationPoint(-8.0F, 9.0F, -8.0F);
	this.shape1_5.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
	this.shape1_7 = new ModelRenderer(this, 0, 17);
	this.shape1_7.setRotationPoint(-7.0F, 22.0F, -7.0F);
	this.shape1_7.addBox(0.0F, 0.0F, 0.0F, 14, 1, 14, 0.0F);
	this.shape1_2 = new ModelRenderer(this, 0, 0);
	this.shape1_2.setRotationPoint(-8.0F, 8.0F, -8.0F);
	this.shape1_2.addBox(0.0F, 0.0F, 0.0F, 16, 1, 16, 0.0F);
	this.shape1_4 = new ModelRenderer(this, 0, 48);
	this.shape1_4.setRotationPoint(7.0F, 9.0F, 7.0F);
	this.shape1_4.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
	this.shape1_3 = new ModelRenderer(this, 0, 48);
	this.shape1_3.setRotationPoint(7.0F, 9.0F, -8.0F);
	this.shape1_3.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
	this.shape1_1 = new ModelRenderer(this, 0, 48);
	this.shape1_1.setRotationPoint(-8.0F, 9.0F, 7.0F);
	this.shape1_1.addBox(0.0F, 0.0F, 0.0F, 1, 14, 1, 0.0F);
}

@Override public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
	this.shape1.render(f5);
	this.shape1_6.render(f5);
	this.shape1_5.render(f5);
	this.shape1_7.render(f5);
	this.shape1_2.render(f5);
	this.shape1_4.render(f5);
	this.shape1_3.render(f5);
	this.shape1_1.render(f5);
}

/** This is a helper function from Tabula to set the rotation of model parts */
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
	modelRenderer.rotateAngleX = x;
	modelRenderer.rotateAngleY = y;
	modelRenderer.rotateAngleZ = z;
}
}

 

to

 

public class ModelMagicChestRefactor implements ISmartItemModel {
@Override public List getFaceQuads(EnumFacing facing) {
	return null;
}

@Override public List getGeneralQuads() {
	return null;
}

@Override public boolean isAmbientOcclusion() {
	return false;
}

@Override public boolean isGui3d() {
	return false;
}

@Override public boolean isBuiltInRenderer() {
	return false;
}

@Override public TextureAtlasSprite getTexture() {
	return null;
}

@Override public ItemCameraTransforms getItemCameraTransforms() {
	return null;
}

@Override public IBakedModel handleItemState(ItemStack stack) {
	return null;
}
}

 

However I don't understand how any of that works :( If there's a tutorial specifically for this that explains it in detail I'd love that.

Posted

To render a TESR you need to have a class extending TileEntityItemStackRenderer

and example would be.

//From a mod I'm currently writting
public class CrystalMagicRenderHelper extends TileEntityItemStackRenderer {
//the Tile enitty you want to render
    private TileFlare flareRender = new TileFlare();
    @Override
    public void renderByItem(ItemStack itemStack) {
        Block block = Block.getBlockFromItem(itemStack.getItem());
//Your custom block
        if (block == CMBlocks.flare) {
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.flareRender, 0.0D, 0.0D, 0.0D, 0.0F);
        }else {
//for minecraft to render its own tile entities such as the chest
            super.renderByItem(itemStack);
        }
    }
}

in your client proxy you need to have the call which is

TileEntityItemStackRenderer.instance = new CrystalMagicRenderHelper();

best to also remove minecraft looking for the blockstate file with

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().registerBuiltInBlocks(block);

and finally your item json needs to be

{
  "parent": "builtin/entity"
}

and that should make the TESR render as an item

EDIT:Unless I've forgotten something

Did you really need to know?

Posted

In client proxy:

@Override public void registerRenderInformation() {
	TileEntitySpecialRenderer mcr = new MagicChestRenderer(Minecraft.getMinecraft().getRenderManager());
	ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMagicChest.class, mcr);
	LogHelper.warn("A");
	TileEntityItemStackRenderer.instance = new MagicChestInventoryRenderer();
	// MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.magicChest), new MagicChestInventoryRenderer(mcr, new TileEntityMagicChest()));
}

 

"A" is put into the log

 

public class MagicChestInventoryRenderer extends TileEntityItemStackRenderer {
private Map<Integer, TileEntityMagicChest> itemRenders = Maps.newHashMap();

public MagicChestInventoryRenderer() {
	LogHelper.warn("B");
	itemRenders.put(0, (TileEntityMagicChest) new TileEntityMagicChest());
}

@Override public void renderByItem(ItemStack itemStack) {
	Block block = Block.getBlockFromItem(itemStack.getItem());
	LogHelper.warn("C");
	if (block == ModBlocks.magicChest) {
		LogHelper.warn("D");
		TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(0), 0.0D, 0.0D, 0.0D, 0.0F);
	} else {
		super.renderByItem(itemStack);
	}
}
}

 

"B" is put into the logs

"C" and "D" is not put into the logs

 

I do have everything you told me to put

Posted

Right below it:

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMagicChest.class, mcr);

I made it a variable because in 1.7 I needed to use it for the inventory renderer too, however now it doesn't really need to be a variable. The RenderManager is because in the actual block when placed down it renders items. I probably could just use Minecraft.getMinecraft().getRenderManager() in the constructor for it.

Posted

Going through a bit of my backend code i realized that i forgot to mention that you still have to register the item render to the inventory using

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item,metadata,new ModelResourceLocation(itemname,"inventory"));

Edit:Maybe should read my ModelHelper

Did you really need to know?

Posted

IMO My naming conventions are fine. I don't get what you mean by "nothing was linking to each other" I didn't push my build.gradle so the mappings used were wrong, but on my end all the names are correct. You commented out important stuff like the PacketHandler, Config, etc. So I didn't want to copy it exactly, I copied what I thought was relevant, yet it still does not work.

 

Changed getRenderType to 2

Set the unlocalized name and copied the "BlockRU" class (Although I really don't think having block. instead of tile. would make a difference)

Got rid of unlocalized name stuff in ItemBlock

Switched from IProxy to CommonProxy and set up the methods seperately (bindTileEntitySpecialRenderers, registerRenderInformation, registerItemRenderers) All this is called in the init portion of the mod.

 

The things you pushed other than that were irrelevant to the rendering in the inventory, so unless for some reason my workspace is broken in some way, I don't understand why it doesn't work.

 

Edit: I forgot to refresh the resources folder >_> I should not be up this late. It works.

Posted

tile is so it follows naming conventions cause every block in minecraft starts with tile most of it was just my sorting through the code and making it readable for me and somethings were just to make it work in my environment cause somethings didn't work and were giving me errors. Pretty much eliminate everything that wasn't needed to solve the problem so that the actual problem identified itself.

Did you really need to know?

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

    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
  • Topics

×
×
  • Create New...

Important Information

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