Jump to content

Recommended Posts

Posted

Ok, for some odd reason my textures aren't loading on my tile entity custom renderer. It's just a black square that gets placed. The texture I'm using is 16x16, so that might be the issue (I'm not sure how these textures are formatted)? I am using vertex with uv, the texture is being bound with the bindTexture method, and minecraft doesn't say that the texture is missing.

Currently working on a mod to provide support for the Clojure programming language in Minecraft, check it out here.

Posted

Hard to help you without seeing any code - always post it with your question, if applicable.

 

Unfortunately, well, here I guess:

 

 

 

CODE GENERATOR CODE:

 

(defn vertex

  ([^Tessellator tessellator ^Double x ^Double y ^Double z]

  (.addVertex tessellator x y z))

  ([^Tessellator tessellator ^Double x ^Double y ^Double z ^Double u ^Double v]

  (.addVertexWithUV tessellator x y z u v)))

 

(defn resource-location [^String location]

  (ResourceLocation. location))

 

(defn make-call [v]

  `(apply vertex Tessellator/instance ~v))

 

(defmacro deftilerenderer [renderer-name & options]

  (let [options (apply hash-map options)

        vertices (get options :vertices [])

        texture (:texture options)

        options (dissoc options :vertices :texture)

        vertex-calls (map make-call vertices)

        render-tile-entity-at `(fn [~'entity ~'x ~'y ~'z ~'f]

                                (GL11/glPushMatrix)

                                (GL11/glTranslated ~'x ~'y ~'z)

                                ~(if texture

                                    `(call-method TileEntitySpecialRenderer (symbol "bindTexture") [ResourceLocation] ~'this (resource-location ~texture))

                                    `(GL11/glDisable GL11/GL_TEXTURE_2D))

                                (.startDrawingQuads Tessellator/instance)

                                ~@vertex-calls

                                (.draw Tessellator/instance)

                                ~(if (not texture)

                                    `(GL11/glEnable GL11/GL_TEXTURE_2D))

                                (GL11/glPopMatrix))

        options (assoc-in options [:override :render-tile-entity-at] render-tile-entity-at)]

    `(defobj TileEntitySpecialRenderer [] ~renderer-name ~options)))

 

(defn bind-tile-renderer [^Class tile-entity-class ^TileEntitySpecialRenderer renderer]

  (ClientRegistry/bindTileEntitySpecialRenderer tile-entity-class renderer))

 

USER CODE:

 

(deftileentity yoshiquest.testmod.tileentities render-block-entity)

 

(defn new-render-block-entity [& args]

  (.newInstance ^Class render-block-entity))

 

(defblock render-block

  :block-name "render-block"

  :container? true

  :override {:create-new-tile-entity new-render-block-entity

            :should-side-be-rendered (constantly false)

            :is-opaque-cube (constantly false)}

  :hardness 0.5

  :step-sound Block/soundTypeStone

  :creative-tab CreativeTabs/tabBlock

  :block-texture-name "test-mod:render-block")

 

(deftilerenderer render-block-renderer

  :vertices [[0 0 0 0 0]

            [0 1 0 0 1]

            [1 1 0 1 1]

            [1 0 0 1 0]]

  :texture "test-mod:textures/blocks/multiblock_5.png")

 

SAMPLE GENERATED CODE:

 

(def render-block-renderer (clojure.core/doto

                            (clojure.core/proxy [net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer] []

                                                (renderTileEntityAt [& args]

                                                                    (#object[clojure.core$apply 0x402edff clojure.core$apply@402edff]

                                                                            (clojure.core/fn [entity x y z f] (org.lwjgl.opengl.GL11/glPushMatrix)

                                                                                            (org.lwjgl.opengl.GL11/glTranslated x y z)

                                                                                            (forge-clj.core/call-method net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer (clojure.core/symbol bindTexture) [net.minecraft.util.ResourceLocation] this (forge-clj.core/resource-location test-mod:textures/blocks/multiblock_5.png)) (.startDrawingQuads net.minecraft.client.renderer.Tessellator/instance)

                                                                                            (clojure.core/apply forge-clj.core/vertex net.minecraft.client.renderer.Tessellator/instance [0 0 0 0 0])

                                                                                            (clojure.core/apply forge-clj.core/vertex net.minecraft.client.renderer.Tessellator/instance [0 1 0 0 1])

                                                                                            (clojure.core/apply forge-clj.core/vertex net.minecraft.client.renderer.Tessellator/instance [1 1 0 1 1])

                                                                                            (clojure.core/apply forge-clj.core/vertex net.minecraft.client.renderer.Tessellator/instance [1 0 0 1 0])

                                                                                            (.draw net.minecraft.client.renderer.Tessellator/instance)

                                                                                            nil

                                                                                            (org.lwjgl.opengl.GL11/glPopMatrix)) args)))))

 

 

 

Yup, it's Clojure code, so I don't think you'll understand it. Here it is anyways, just in case you somehow do understand it.

 

But yeah, normally I would have posted the code if it weren't for that fact.

Currently working on a mod to provide support for the Clojure programming language in Minecraft, check it out here.

Posted

Code is code - as long as you write it using intelligible naming, anyone with coding experience can probably figure out what it's doing, even if they couldn't write it themselves.

 

Anyway, assuming that your texture is the correct path and that your code is being called at the correct time (i.e. during block rendering), then I would say it may be that you the problem probably lies with your vertices - they are either out of order and/or the calls to addVertex are not using the correct values (as in all 0s and 1s is probably incorrect).

 

To see what I mean, take a look at RenderBlocks#renderStandardBlock and trace it down to the individual face rendering, and you will see the values passed to #addVertex are much more complex than one may at first imagine - it's not as straightforward as the .JSON description of the block would have one believe. Just my guess - it could very well be something completely banal that I'm overlooking.

 

As a further example, here is a custom model handled via ISBRH:

 

Tessellator tessellator = Tessellator.instance;
	block.setBlockBoundsForItemRender();
	renderer.setRenderBoundsFromBlock(block);
	GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
	GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, -1.0F, 0.0F);
	renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, 1.0F, 0.0F);
	renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, 0.0F, -1.0F);
	renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, 0.0F, 1.0F);
	renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(-1.0F, 0.0F, 0.0F);
	renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(1.0F, 0.0F, 0.0F);
	renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
	tessellator.draw();
	GL11.glTranslatef(0.5F, 0.5F, 0.5F);

 

Note that I'm not adding vertices directly, but calling the RenderBlock methods to do it for me using the registered block icons. I'm not sure if that is an option for you, but if so, it might be worth pursuing.

Posted

Code is code - as long as you write it using intelligible naming, anyone with coding experience can probably figure out what it's doing, even if they couldn't write it themselves.

 

Anyway, assuming that your texture is the correct path and that your code is being called at the correct time (i.e. during block rendering), then I would say it may be that you the problem probably lies with your vertices - they are either out of order and/or the calls to addVertex are not using the correct values (as in all 0s and 1s is probably incorrect).

 

To see what I mean, take a look at RenderBlocks#renderStandardBlock and trace it down to the individual face rendering, and you will see the values passed to #addVertex are much more complex than one may at first imagine - it's not as straightforward as the .JSON description of the block would have one believe. Just my guess - it could very well be something completely banal that I'm overlooking.

 

As a further example, here is a custom model handled via ISBRH:

 

Tessellator tessellator = Tessellator.instance;
	block.setBlockBoundsForItemRender();
	renderer.setRenderBoundsFromBlock(block);
	GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
	GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, -1.0F, 0.0F);
	renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, 1.0F, 0.0F);
	renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, 0.0F, -1.0F);
	renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(0.0F, 0.0F, 1.0F);
	renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(-1.0F, 0.0F, 0.0F);
	renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
	tessellator.draw();
	tessellator.startDrawingQuads();
	tessellator.setNormal(1.0F, 0.0F, 0.0F);
	renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
	tessellator.draw();
	GL11.glTranslatef(0.5F, 0.5F, 0.5F);

 

Note that I'm not adding vertices directly, but calling the RenderBlock methods to do it for me using the registered block icons. I'm not sure if that is an option for you, but if so, it might be worth pursuing.

 

Yeah, um, this is the first I've ever heard of this way of rendering every single other tutorial I checked used addVertex in some way. I think I understand it a little bit, but I'm not sure if I'm going to be able to use this technique anyways, since I'm trying to add custom rendering to forge-clj. And from what I read, this doesn't support techne models, something I'm going to have to make room for anyways. I think it might have something to do with the icons though. Maybe I should try using the icon instead of the u and v coordinates?

Currently working on a mod to provide support for the Clojure programming language in Minecraft, check it out here.

Posted

That's not code from a Techne model - it's just Tesselator / addVertex calls that form a shape.

 

And yes, if you have access to the icons, you can render each face using them:

// renderer is a RenderBlocks instance; lots of values set above basically copied from RenderBlocks
Tessellator tessellator = Tessellator.instance;
		tessellator.setColorOpaque_F(r, g, b);
		tessellator.setBrightness(983055);
		int brightness = block.getMixedBrightnessForBlock(world, x, y, z);
		if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y - 1, z, 0)) {
			tessellator.setBrightness(renderer.renderMinY > 0.0D ? brightness : block.getMixedBrightnessForBlock(world, x, y - 1, z));
			tessellator.setColorOpaque_F(f10, f13, f16);
			renderer.renderFaceYNeg(block, x, y, z, block.getIcon(0, meta));
			rendered = true;
		}
		if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y + 1, z, 1)) {
			tessellator.setBrightness(renderer.renderMaxY < 1.0D ? brightness : block.getMixedBrightnessForBlock(world, x, y + 1, z));
			tessellator.setColorOpaque_F(f7, f8, f9);
			renderer.renderFaceYPos(block, x, y, z, block.getIcon(1, meta));
			rendered = true;
		}
// etc for the rest of the faces

I would only do that if the block has different icons based on the metadata, though, or if you don't have access to an instance of the block. If it doesn't use metadata for rendering and you have a Block instance, you can render the block just by calling this:

renderer.renderBlockByRenderType(block, x, y, z);

There are all sorts of useful things to see in RenderBlocks, many of which are public methods you can use.

Posted

That's not code from a Techne model - it's just Tesselator / addVertex calls that form a shape.

 

And yes, if you have access to the icons, you can render each face using them:

// renderer is a RenderBlocks instance; lots of values set above basically copied from RenderBlocks
Tessellator tessellator = Tessellator.instance;
		tessellator.setColorOpaque_F(r, g, b);
		tessellator.setBrightness(983055);
		int brightness = block.getMixedBrightnessForBlock(world, x, y, z);
		if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y - 1, z, 0)) {
			tessellator.setBrightness(renderer.renderMinY > 0.0D ? brightness : block.getMixedBrightnessForBlock(world, x, y - 1, z));
			tessellator.setColorOpaque_F(f10, f13, f16);
			renderer.renderFaceYNeg(block, x, y, z, block.getIcon(0, meta));
			rendered = true;
		}
		if (renderer.renderAllFaces || block.shouldSideBeRendered(world, x, y + 1, z, 1)) {
			tessellator.setBrightness(renderer.renderMaxY < 1.0D ? brightness : block.getMixedBrightnessForBlock(world, x, y + 1, z));
			tessellator.setColorOpaque_F(f7, f8, f9);
			renderer.renderFaceYPos(block, x, y, z, block.getIcon(1, meta));
			rendered = true;
		}
// etc for the rest of the faces

I would only do that if the block has different icons based on the metadata, though, or if you don't have access to an instance of the block. If it doesn't use metadata for rendering and you have a Block instance, you can render the block just by calling this:

renderer.renderBlockByRenderType(block, x, y, z);

There are all sorts of useful things to see in RenderBlocks, many of which are public methods you can use.

 

Would this work for things other than, say, rendering a block side and stuff (because from what I can tell, you're just rendering a single face instead of all six faces, though I could be misinterpreting something)? The main reason I'm making this is NOT for personal use, but for a library adding support for Clojure code to it. As such, I need to make sure that whatever system I use can be used for multiple things (blocks, items, tile entities, actual entities, etc). Of course, all of those things probably won't be in the same function, but having a single system that can handle the actual rendering (vertices, etc) is what I need. Also, the system shown in my earlier post actually did work rather well when I didn't specify a texture, it's just that now it isn't working when I add a texture.

 

The reason I mentioned Techne earlier wasn't because I was thinking your code was implementing Techne. Rather, I need to make sure that the system I end up using is general enough that I'll be able to actually render Techne models (using a .java file is not an option for obvious reasons since this is a different language). In the end I want to be able to read in a Techne model (as a .json), and then use my code generators to generate what is needed underneath.

Currently working on a mod to provide support for the Clojure programming language in Minecraft, check it out here.

Posted

The first example renders a completely 3D block, all 6 faces. The second example showed rendering 2/6 faces of a Block and no, that will not work for anything other than a Block, a cube-shaped one at that.

 

Techne models typically use an actual ModelBase object on which one calls model#renderAll, with the model itself handling all of the vertex rendering.

 

Items, Blocks, and Entities are all rendered separately by Minecraft and have different methods of rendering; taking that and making a library that is general enough to handle any of them + models + animations (how do you plan on handling that, btw?) all with the same methods is going to be quite the feat.

 

I'm not saying it's impossible, but chances are you are going to have to provide at least 3 different rendering methods, one for each of Item, Block, and Entity, as each of them are very different from each other. Blocks and Entities are especially complex; again I urge you to look through the entire RenderBlocks class as well as each of the Render{Entity} classes, and even the ItemRenderer class is no walk in the park - you can see for yourself the beast you are waking.

 

Best of luck to you - you're going to need it ;)

Posted

When I was talking about generalizing things, I was mainly speaking about vertex rendering. So I took a closer look at the files Techne generates, as well as the respective Model classes, and I think I can get what I need there. From what I've seen, the model "pieces" are each composed of a single ModelRenderer. These pieces generally have a number of specific properties that get repeated with each one. In other words, generating these "pieces" should be rather easy. The same goes for the ModelBase, as implementing a default render method that just calls the underlying render methods should be easy as well.

 

Notice that right there I just said "default". I plan to, in order to add support for animation, allow the user to define their own render method, which they can use to properly modify each piece before it gets rendered (in order to support animation and the like). As for the actual implementation, it should also be easy, since it's really just some opened and closed open-gl calls from what I can tell, and the model seems to handle the rest.

 

Not sure if this is what I'll go with in the end though. I'm also considering a system for animation where multiple "parts" are created, and it just cycles between them. I'm not entirely sure how well this could work though, or if I'm missing anything.

Currently working on a mod to provide support for the Clojure programming language in Minecraft, check it out here.

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.