Jump to content

[1.8] IItemRenderer never called


coolAlias

Recommended Posts

IItemRenderer is deprecated in 1.8, but has not been entirely removed. Since this is the case, I would expect it to still be usable, but after trying it I found that my custom renderer is never called.

 

Opening up the call hierarchy for any method in MinecraftForgeClient reveals that none of them are ever called (except by me to register my IItemRenderer).

 

Is this an oversight, or should IItemRenderer, MinecraftForgeClient, and related classes (if any) be removed from the Forge code base?

 

If they will be removed, what is the alternative to IItemRenderer that gives access to the entity for which the item is being rendered as well as the current camera transform? ISmartItemModel#handleItemState gives only the ItemStack, which is not sufficient for my needs.

Link to comment
Share on other sites

That's what I thought, but I saw it was still in the Forge code and, it being there, assumed it would still work. That's what deprecation means - still works, but being phased out or not as preferred as some other method. It doesn't mean 'we left this artifact here for you to gaze upon, but it has no use.'

 

If it is not going to be implemented at all, it should be removed entirely so people do not think it still exists.

 

That aside, I've looked at IPerspectiveAwareModel, but I also need the ItemStack and the entity using the item to determine which model / transformation to return - IPAM only gives the camera transform type.

 

What I'm trying to do is render the currently selected arrow along with the bow currently in use. This was trivial to accomplish with IItemRenderer (much like many other things in the past... oh, nostalgia), but I cannot seem to find anything that provides that same level of flexibility in the new format.

 

I actually am coming to quite like the new systems, especially IBlockState, and even using JSON for models to some extent, but there I've run into several cases already where the model system seems very limiting. I'm sure it's just because I don't completely understand some part(s) of the process, but it has been the one thing about updating to 1.8 that has caused me the most grief.

Link to comment
Share on other sites

I think you would probably have to store that information in the ItemStack NBT, using some other event to pull the relevant entity info into the item.

 

Rainwarrior seems to be the driving force behind the development of the new rendering code; you could try reaching him.

 

DieSieben's suggestion is good for when the item is in use.

 

-TGG

Link to comment
Share on other sites

The method is also called when the Item is not in use at all.

Yeah that's true, what I meant was "in use by the player".  I'm pretty sure Entities holding the item don't call getModel.  If your item is only ever wielded by the player, or you only care about altering the model in first person (inventory + 3rd person can be the same) then that should work fine.

 

-TGG

Link to comment
Share on other sites

The problem is that getModel can only return ONE model. I want to render two models - the bow, in whatever pulling state it is at (this part is already working), and the arrow that is nocked in the bow, based on whatever current arrow is selected.

 

I'd prefer not to have to store a bunch of extra data in the NBT tag. I have done that before and it causes animation glitches any time it updates.

 

I guess I only really care about player's using the bow, in which case I can try using mc.thePlayer, but I suspect that will not work well in multiplayer because the renderer is called client-side, so whenever someone is looking at an entity using the bow, it will use the viewer's data rather than the actual entity being rendered.

 

With the current placement of ISmartItemModel's hook (@ItemModelMesher#getModel(ItemStack)), it's not possible to obtain the entity. I wonder why it wasn't also placed in RenderItem#renderItemModelForEntity which is where the lovely Item#getModel method is called? Or, rather, had an additional hook there, since ItemModelMesher is called from so many different places.

Link to comment
Share on other sites

You can use the ModelBakeEvent to register your own IModel for a ModelResourceLocation. That IModel then translates into the IFlexibleBakedModel which can also implement the other needed interfaces (ISmartItemModel for example).

Then from getModel in your Item you'd return the correct ModelResourceLocation.

Sorry, but I don't see how that allows me to return two models at a time - perhaps I just am not understanding the interface. I need both the bow AND the arrow model to render together, not just one or the other.

 

Or is there some way to dynamically merge the two models together and return them as one? I'm trying to make the bow compatible with possibly unknown (beforehand) arrow items, otherwise I could just make each of the 4 bow textures per arrow and return that model from getModel. Not very elegant, but it would work.

 

I understand the new model formats are there to allow greater flexibility for resource pack makers, but trying to do any sort of customization has been an extremely frustrating experience. It's getting to the point that I may just resort to hackery and see if I can render the arrow before returning the model from Item#getModel.

 

Thanks for the replies so far, and apologies again that I just don't seem to get it - rendering-related code has never been my strong suit.

Link to comment
Share on other sites

Or is there some way to dynamically merge the two models together and return them as one?

Yes, if you choose your models so they overlap nicely, you can merge them by concatenating together lists of quads.  The trickiest bit is if you need to rotate or translate (say) the arrow quads to match the orientation of the bow.

A bit similar to this:

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/mbe05_block_smartblockmodel2/CompositeModel.java

except that you use handleItemState() to choose the correct models to be combined, instead of handleBlockState().

 

Alternatively, your Item.getModel() could construct the CompositeModel giving it the appropriate arrow and bow models, and not use the ISmartItemModel at all.

 

-TGG

 

Link to comment
Share on other sites

Might be/not right place, but I am coding similar thing right now, so some questions might overlap.

 

The trickiest bit is if you need to rotate or translate (say) the arrow quads to match the orientation of the bow.

-TGG

 

My Item's SmartModel is putting together new model from other SmartModels which get their model from NBT.

Like a structure building up from parts.

 

Now the problem is that the transformation, doesn't matter if vanilla json's or forge's hook ForgeHooksClient#handleCameraTransforms happens only AFTER you are done creating model and start rendering it.

Basically - no matter what I do the partial models will be always the same and only the final model (the one which is created by putting together quads) will call for transformations, which will accordingly happen on all sub-parts (models).

 

Is there a way of performing transformations directly on model parts' BakedQuads - the moment when the model is being constructed?

 

If there is no util/hook for that - I would have to directly manipulate BakedQuads - how do I do that? BakedQuad vertex format is like magic to me (some int[28] from what I've seen) how to read it?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Now the problem is that the transformation, doesn't matter if vanilla json's or forge's hook ForgeHooksClient#handleCameraTransforms happens only AFTER you are done creating model and start rendering it.

Basically - no matter what I do the partial models will be always the same and only the final model (the one which is created by putting together quads) will call for transformations, which will accordingly happen on all sub-parts (models).

 

Is there a way of performing transformations directly on model parts' BakedQuads - the moment when the model is being constructed?

 

If there is no util/hook for that - I would have to directly manipulate BakedQuads - how do I do that? BakedQuad vertex format is like magic to me (some int[28] from what I've seen) how to read it?

 

The only way I can think of is to do the matrix calculations yourself on the vertices [x,y,z] of each quad.  Translation is easy, rotation a bit harder, but not too difficult if you know  a bit about matrix calculations or are willing to spend a couple of hours researching...

 

The format of the BakedQuad vertex might be a bit clearer if you look at the code fragment below (vertexToInts() )

 

 

 

  /**
   // Creates a baked quad for the given face.
   // When you are directly looking at the face, the quad is centred at [centreLR, centreUD]
   // The left<->right "width" of the face is width, the bottom<-->top "height" is height.
   // The amount that the quad is displaced towards the viewer i.e. (perpendicular to the flat face you can see) is forwardDisplacement
   //   - for example, for an EAST face, a value of 0.00 lies directly on the EAST face of the cube.  a value of 0.01 lies
   //     slightly to the east of the EAST face (at x=1.01).  a value of -0.01 lies slightly to the west of the EAST face (at x=0.99).
   // The orientation of the faces is as per the diagram on this page
   //   http://greyminecraftcoder.blogspot.com.au/2014/12/block-models-texturing-quads-faces.html
   // Read this page to learn more about how to draw a textured quad
   //   http://greyminecraftcoder.blogspot.co.at/2014/12/the-tessellator-and-worldrenderer-18.html
   * @param centreLR the centre point of the face left-right
   * @param width    width of the face
   * @param centreUD centre point of the face top-bottom
   * @param height height of the face from top to bottom
   * @param forwardDisplacement the displacement of the face (towards the front)
   * @param itemRenderLayer which item layer the quad is on
   * @param texture the texture to use for the quad
   * @param face the face to draw this quad on
   * @return
   */
  private BakedQuad createBakedQuadForFace(float centreLR, float width, float centreUD, float height, float forwardDisplacement,
                                           int itemRenderLayer,
                                           TextureAtlasSprite texture, EnumFacing face)
  {
    float x1, x2, x3, x4;
    float y1, y2, y3, y4;
    float z1, z2, z3, z4;
    final float CUBE_MIN = 0.0F;
    final float CUBE_MAX = 1.0F;

    switch (face) {
      case UP: {
        x1 = x2 = centreLR + width/2.0F;
        x3 = x4 = centreLR - width/2.0F;
        z1 = z4 = centreUD + height/2.0F;
        z2 = z3 = centreUD - height/2.0F;
        y1 = y2 = y3 = y4 = CUBE_MAX + forwardDisplacement;
        break;
      }
      case DOWN: {
        x1 = x2 = centreLR + width/2.0F;
        x3 = x4 = centreLR - width/2.0F;
        z1 = z4 = centreUD - height/2.0F;
        z2 = z3 = centreUD + height/2.0F;
        y1 = y2 = y3 = y4 = CUBE_MIN - forwardDisplacement;
        break;
      }
      case WEST: {
        z1 = z2 = centreLR + width/2.0F;
        z3 = z4 = centreLR - width/2.0F;
        y1 = y4 = centreUD - width/2.0F;
        y2 = y3 = centreUD + width/2.0F;
        x1 = x2 = x3 = x4 = CUBE_MIN - forwardDisplacement;
        break;
      }
      case EAST: {
        z1 = z2 = centreLR - width/2.0F;
        z3 = z4 = centreLR + width/2.0F;
        y1 = y4 = centreUD - width/2.0F;
        y2 = y3 = centreUD + width/2.0F;
        x1 = x2 = x3 = x4 = CUBE_MAX + forwardDisplacement;
        break;
      }
      case NORTH: {
        x1 = x2 = centreLR - width/2.0F;
        x3 = x4 = centreLR + width/2.0F;
        y1 = y4 = centreUD - width/2.0F;
        y2 = y3 = centreUD + width/2.0F;
        z1 = z2 = z3 = z4 = CUBE_MIN - forwardDisplacement;
        break;
      }
      case SOUTH: {
        x1 = x2 = centreLR + width/2.0F;
        x3 = x4 = centreLR - width/2.0F;
        y1 = y4 = centreUD - width/2.0F;
        y2 = y3 = centreUD + width/2.0F;
        z1 = z2 = z3 = z4 = CUBE_MAX + forwardDisplacement;
        break;
      }
      default: {
        assert false : "Unexpected facing in createBakedQuadForFace:" + face;
        return null;
      }
    }

    return new BakedQuad(Ints.concat(vertexToInts(x1, y1, z1, Color.WHITE.getRGB(), texture, 16, 16),
                                     vertexToInts(x2, y2, z2, Color.WHITE.getRGB(), texture, 16, 0),
                                     vertexToInts(x3, y3, z3, Color.WHITE.getRGB(), texture, 0, 0),
                                     vertexToInts(x4, y4, z4, Color.WHITE.getRGB(), texture, 0, 16)),
                         itemRenderLayer, face);
  }

  /**
   * Converts the vertex information to the int array format expected by BakedQuads.
   * @param x x coordinate
   * @param y y coordinate
   * @param z z coordinate
   * @param color RGBA colour format - white for no effect, non-white to tint the face with the specified colour
   * @param texture the texture to use for the face
   * @param u u-coordinate of the texture (0 - 16) corresponding to [x,y,z]
   * @param v v-coordinate of the texture (0 - 16) corresponding to [x,y,z]
   * @return
   */
  private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v)
  {
    return new int[] {
            Float.floatToRawIntBits(x),
            Float.floatToRawIntBits(y),
            Float.floatToRawIntBits(z),
            color,
            Float.floatToRawIntBits(texture.getInterpolatedU(u)),
            Float.floatToRawIntBits(texture.getInterpolatedV(v)),
            0
    };
  }

 

 

Link to comment
Share on other sites

I just realized that those formats are converted floats. Damn, that method (yours TGG) was useful, I actually shifted quads, now it's a matter of time till I write nice utility which will do that for me.

 

Thanks, hopefully it will be just matter of time :D

 

EDIT

Jesus christ, I thought (past) that every "pixel" (the minecraft square) was a quad... no wonder nothing worked. This format is actually pretty neat :D

 

RESULTS

Yes, guard and pommel are thicker.

25q3u3d.jpg

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Hm, I'm running into a couple of issues, and hopefully I'm just proving mentally deficient.

 

1) Item#getModel needs to return a ModelResourceLocation only, so it cannot (that I can figure out) return a combined baked model

2) If I do make a combined model, how can I return the correct texture atlas sprite for each component? It seems that I can only return one.

3) In the combined model, which method is suitable to go about rotating / translating a specific component?

 

In the meantime, I'm going to try rendering the arrow stack directly from within Item#getModel. I know that's terrible form, but at this point, I just want to get the damn thing working.

 

EDIT: Holy hell, it actually worked! Hahaha. Now I just have to get the rotations right, and f-you model system!!! Direct rendering, ftw!

 

In all seriousness, though, if anyone knows a proper way to accomplish this, please let me know. But at least I can move on to other things for now, and leave my hack as fodder for the code police.

Link to comment
Share on other sites

After looking through the panorama of classes involved for over an hour, that does seem to be like the way, but my lord, that is complicated, or at least appears that way when trying to figure it out for the first time.

 

For example, this is all it takes for me to have it working right now:

 

@Override
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int ticksRemaining) {
	if (!player.isUsingItem()) {
		return models.get(0);
	}
	int ticks = stack.getMaxItemUseDuration() - ticksRemaining;
	int i = (ticks > 17 ? 3 : ticks > 13 ? 2 : ticks > 0 ? 1 : 0);
	ItemStack arrowStack = ZSSPlayerInfo.get(player).getNockedArrow();
	if (i > 0 && arrowStack != null) {
		Minecraft mc = Minecraft.getMinecraft();
		GlStateManager.pushMatrix();
		boolean firstPerson = (player == mc.thePlayer && mc.getRenderManager().options.thirdPersonView == 0);
		if (firstPerson) {
			GlStateManager.rotate(45.0F, 0.0F, 1.0F, 0.0F);
			GlStateManager.rotate(-25.0F, 0.0F, 0.0F, 1.0F);
			GlStateManager.translate(-0.4D, 0.4D, 0.0D);
			GlStateManager.scale(1.325F, 1.325F, 1.325F);
		} else {
			GlStateManager.rotate(87.5F, 0.0F, 1.0F, 0.0F);
			GlStateManager.rotate(45F, 0.0F, 0.0F, 1.0F);
			GlStateManager.rotate(-10.0F, 1.0F, 0.0F, 0.0F);
			GlStateManager.translate(0.125D, 0.125D, 0.125D);
			GlStateManager.scale(0.625F, 0.625F, 0.625F);
		}
		GlStateManager.translate(-(-3F+i)/16F, -(-3F+i)/16F, 0.5F/16F);
		mc.getRenderItem().renderItemModel(arrowStack);
		GlStateManager.popMatrix();
	}
	return models.get(i);
}

 

Simple and effective. Converting that into a proper model format would likely take me hours of frustration (it already has, actually, and in the end I didn't get anywhere with it).

 

I think I'll stick with my hack for now, and give it another go when I have more time / patience. Perhaps by then TGG will have released a comprehensive guide on IModel.

 

Re: components vs quads - I realize it's about quads, I was just referencing them by the component models because that's where I'd be getting the quads from, and all of the quads within that component would undergo the same transformations.

 

Anyway, thanks for your efforts here. One of these days, I really will try to tackle this problem the correct way ;)

 

@Ernio That looks awesome, nice work!

Link to comment
Share on other sites

Minecraft uses OpenGL under the hood to do all of its rendering, so how is my code any slower or deprecated? What else are we supposed to use, such as for animation frames in TESR where there might not be a model, or if we have a model but want to move / rotate it?

 

My code is most certainly hard-coded, and I will change it (eventually) to use the model system, but even then I would be dynamically generating a new model each frame, because each arrow item could theoretically have a different model, so I couldn't bake every possible combination ahead of time, could I? Why would this be any faster than using GLStateWrapper directly on a pre-baked model?

 

I admit that my solution is not perfect and abstraction layers are certainly useful, but only if people can figure out how to use them; too many layers / too many pieces that must all be used in just the right combination at just the right time and registered in just the right way without any documentation makes it awfully difficult for people to get all their ducks in a row, especially when you step outside the standard model format.

 

Sorry, it's just a very unintuitive and frustrating system for me, and I've already spent more hours than I care to admit wrestling with it and getting nowhere.

 

Grammar Nazi alert: gets, not get's. Apostrophe + s is used for contractions and possessive nouns, not as a verb ending. Just FYI, in case you care :P

Link to comment
Share on other sites

So even using GlStateManager for the OpenGL calls uses the fixed pipeline? I would have expected it to queue them up along with the rest of Minecraft's rendering calls.

 

I do use the current system for the vast majority of my items and blocks, but those few cases that require special handling are really causing me a headache, which is why I end up resorting to hacks like the one above from time to time.

 

Your comments about the fixed pipeline are causing me to question some other things that I thought were perfectly fine, e.g.:

 

@SideOnly(Side.CLIENT)
public class RenderTileEntityPedestal extends TileEntitySpecialRenderer
{
private final RenderItem renderItem;

public RenderTileEntityPedestal() {
	this.renderItem = Minecraft.getMinecraft().getRenderItem();
}

@Override
public void renderTileEntityAt(TileEntity te, double dx, double dy, double dz, float partialTick, int blockDamageProgress) {
	renderPedestal((TileEntityPedestal) te, dx, dy, dz, partialTick);
}

private void renderPedestal(TileEntityPedestal pedestal, double dx, double dy, double dz, float partialTick) {
	ItemStack sword = pedestal.getSword();
	if (sword != null) {
		GlStateManager.pushMatrix();
		GlStateManager.translate(dx + 0.5D, dy + 0.9D, dz + 0.5D);
		GlStateManager.enableRescaleNormal();
		GlStateManager.scale(1F, 1F, 1F);
		GlStateManager.rotate(pedestal.getOrientation() == 0 ? 0F : 90F, 0.0F, 1.0F, 0.0F);
		GlStateManager.rotate(225.0F, 0.0F, 0.0F, 1.0F);
		bindTexture(TextureMap.locationBlocksTexture);
		renderItem.renderItemModel(sword);
		GlStateManager.disableRescaleNormal();
		GlStateManager.popMatrix();
	}
}
}

 

Should we not be using GlStateManager at all? If that's the case, I'm in for a very rough time. Me + rendering != happiness. Never has for me, and some parts have only gotten much more complicated with this update; others, though, like changing scale, rotation, and translation for a model, have become deliciously trivial thanks to the JSON formats. I really hope they don't change to that for entities, though...

Link to comment
Share on other sites

Well, I can at least say I've been making progress in understanding the model system.

 

Hilariously in an embarrassing sort of way, for whatever reason it took me a while to realize that I could return 'this' from ISmartItemModel#handleItemState or ISmartBlockModel#handleBlockState. I kept wondering why my methods weren't working properly, and it was because I was returning the model used to construct the smart model, rather than the smart model itself. Derp. Don't know what the hell was going on, but definitely feeling retarded :P

 

While I don't feel quite ready to tackle the bow + arrow thing yet, I did get my shields working:

First person:

SaxQPOf.png

Third person:

HdfeYh9.png

 

I registered two .json models for each shield, a standard one and one for when it is in use, both of which are swapped out to use the same ISmartItemModel class. In there, all I do is swap the last quad from the default model with the face quad for the 'back' model (which does have a .json for the texture, but none of its transformations / rotations are used).

 

@Override
public List<BakedQuad> getGeneralQuads() {
List<BakedQuad> quads = shieldFront.getGeneralQuads();
quads.set(quads.size() - 1, (BakedQuad) shieldBack.getGeneralQuads().get(1));
return quads;
}

Pretty simple, really, though it took me quite a bit of time to get the .json rotations correct for the blocking position due to the vanilla rotations throwing everything out of whack. Turned out pretty nicely, though, and not nearly as verbose as I was expecting.

 

Btw, TGG, your camera transform tool was extremely handy while working on this, even though it was unable to dynamically adjust the shield models. The json used for the 'blocking' version didn't even register when pressing 'reset', so I had to enter it in manually each time with a sword or some other item I could block with.

 

Still, very very helpful, so thanks for making that. Is there any way to adjust rotations by increments of 1 or less while using it? Or just type the value in directly? That would be handy if you feel like doing some more work ;)

Link to comment
Share on other sites

@coolAlias

Pretty simple, really, though it took me quite a bit of time to get the .json rotations correct for the blocking position due to the vanilla rotations throwing everything out of whack.

Are you sure you know about IPerspectiveAwareModel? I mean, I did most of rotations there, so just saying it might be useful.

 

Btw. you sure getGeneralQuads() isn't mutable? (Totally wild guess, I know that if you manipulate BakedQuads they will change forevah for given model).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Are you sure you know about IPerspectiveAwareModel? I mean, I did most of rotations there, so just saying it might be useful.

 

Btw. you sure getGeneralQuads() isn't mutable? (Totally wild guess, I know that if you manipulate BakedQuads they will change forevah for given model).

Yes, I know about IPerspectiveAwareModel, but I figure the more my model can use the vanilla system (i.e. .json files), the better. I mean, why do all the rotations manually when they can be included in the .json file? If you hard-code the rotations, it would be very difficult for someone to make a resource pack for your mod.

 

And what do you mean getGeneralQuads() is/isn't mutable? It's a method: methods can neither be mutable nor immutable. I haven't delved too deeply into model registration; are you saying that once a model is registered, getGeneralQuads() is never called again?

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



×
×
  • Create New...

Important Information

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