Jump to content

[1.7.10] Tile Entity Special Renderer Renders Model Too Dark


Recommended Posts

Posted

Ok, I'm stumped now. For some odd reason, the lighting doesn't seem to apply property to my model, making the bright yellow color I'm using to test it a dark, puke-yellow color. Before you ask, yes I made sure that isOpaqueCube returns false, and I also tried using the Tessellator to fix it with no results.

 

Here's the code for those that can actually read Clojure code (or willing to interpret it):

 

 

 

 

Code Generator Code:

 

(defn model-renderer [^ModelBase base property-map]

  (let [texture-offset (get property-map :texture-offset {})

        renderer (ModelRenderer. base (int (get texture-offset :x 0)) (int (get texture-offset :y 0)))

        box (get property-map :box {})

        rotation-point (get property-map :rotation-point {})

        texture-size (get property-map :texture-size {})

        mirror? (get property-map :mirror? false)

        rotation (get property-map :rotation {})

        renderer (doto renderer

                  (.addBox (float (get box :x 0)) (float (get box :y 0)) (float (get box :y 0)) (int (get box :width 1)) (int (get box :height 1)) (int (get box :depth 1)))

                  (.setRotationPoint (float (get rotation-point :x 0)) (float (get rotation-point :y 0)) (float (get rotation-point :z 0)))

                  (.setTextureSize (int (get texture-size :x 16)) (int (get texture-size :y 16)))

                  (#(set! (.-mirror ^ModelRenderer %1) mirror?))

                  (#(set! (.-rotateAngleX ^ModelRenderer %1) (float (get rotation :x 0))))

                  (#(set! (.-rotateAngleY ^ModelRenderer %1) (float (get rotation :y 0))))

                  (#(set! (.-rotateAngleZ ^ModelRenderer %1) (float (get rotation :z 0)))))]

    renderer))

 

(defn render-renderer [^ModelRenderer renderer f]

  (.render renderer f))

 

(defmacro defmodel [name-ns class-name & args]

  (let [classdata (apply hash-map args)

        classdata (assoc classdata :fields (get classdata :renderers (get classdata :fields {})))

        classdata (assoc-in classdata [:expose 'render] 'superRender)

        classdata (dissoc classdata :renderers)

        prefix (str class-name "-")

        fullname (symbol (str (string/replace name-ns #"-" "_") "." (gen-classname class-name)))

        this-sym (with-meta 'this {:tag fullname})]

    `(do

      (defassocclass ModelBase ~name-ns ~class-name ~classdata)

      (defn ~(symbol (str prefix "render")) [~'this ~'entity ~'f ~'f1 ~'f2 ~'f3 ~'f4 ~'f5]

        (~'.superRender ~this-sym ~'entity ~'f ~'f1 ~'f2 ~'f3 ~'f4 ~'f5)

        (doall (map #(render-renderer %1 ~'f5) (map (partial model-renderer ~this-sym) (vals (deref (~'.-data ~this-sym))))))))))

 

(defn resource-location [location]

  (ResourceLocation. (str location)))

 

(defn bind-texture [texture-location]

  (let [resource (resource-location (str texture-location))]

    (.bindTexture ^net.minecraft.client.renderer.texture.TextureManager (.getTextureManager ^Minecraft (Minecraft/getMinecraft)) resource)))

 

(defn fix-lighting [^World world x y z]

  (let [tessellator Tessellator/instance

        ^Block block (.getBlock world x y z)

        brightness (.getMixedBrightnessForBlock block world x y z)]

    (.setBrightness tessellator brightness)

    (.setColorOpaque_F tessellator (float 1.0) (float 1.0) (float 1.0))))

 

(defmacro deftilerenderer [renderer-name model & options]

  (let [options (apply hash-map options)

        texture (:texture options)

        render-args (:render-args options)

        color (get options :color {})

        options (dissoc options :texture :render-args :color)

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

                                (GL11/glPushMatrix)

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

                                ~(if texture

                                    `(bind-texture ~texture)

                                    `(GL11/glDisable GL11/GL_TEXTURE_2D))

                                (GL11/glColor3f (float (get ~color :r 1)) (float (get ~color :g 1)) (float (get ~color :b 1)))

                                (fix-lighting (.getWorldObj ~(with-meta 'entity `{:tag TileEntity})) ~'x ~'y ~'z)

                                (~'.render ~(with-meta model `{:tag net.minecraft.client.model.ModelBase}) nil 0 0 -0.1 0 0 0.0625)

                                ~(if (not texture)

                                    `(GL11/glEnable GL11/GL_TEXTURE_2D))

                                (GL11/glPopMatrix))

        options (if (not (get-in options [:override :render-tile-entity-at]))

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

                  options)]

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

 

Sample 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

            :is-opaque-cube (constantly false)

            :render-as-normal-block (constantly false)

            :get-render-type (constantly -1)}

  :hardness 0.5

  :step-sound Block/soundTypeStone

  :creative-tab CreativeTabs/tabBlock

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

 

(defmodel yoshiquest.testmod render-block-model

  :renderers {:simple-render {:box {:x 0 :y 0 :z 0 :width 16 :height 16 :depth 16}}})

 

(def model-instance (.newInstance ^Class render-block-model))

 

(deftilerenderer render-block-renderer model-instance :texture "test-mod:textures/blocks/multiblock_4.png")

 

Sample Generated Code (for the TileEntitySpecialRenderer, also you might wanna copy-paste it to somewhere with more room):

 

(def render-block-renderer

  (forge-clj.core/genobj net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer [] {:override {:render-tile-entity-at (clojure.core/fn [entity x y z f]

                                                                                                                                                  (org.lwjgl.opengl.GL11/glPushMatrix)

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

                                                                                                                                                  (forge-clj.core/bind-texture test-mod:textures/blocks/multiblock_4.png)

                                                                                                                                                  (org.lwjgl.opengl.GL11/glColor3f (clojure.core/float (clojure.core/get {} :r 1)) (clojure.core/float (clojure.core/get {} :g 1)) (clojure.core/float (clojure.core/get {} :b 1)))

                                                                                                                                                  (forge-clj.core/fix-lighting (.getWorldObj entity) x y z)

                                                                                                                                                  (.render model-instance nil 0 0 -0.1 0 0 0.0625)

                                                                                                                                                  nil

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

 

 

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

Posted

Ok, since it's been a day and no one has replied to this yet, I thought I'd translate my renderTileEntityAt method into java real quick. Note that this is more or less pseudocode, it's not actually written this way (aka I won't include the type stuff):

 

 

 

public void renderTileEntityAt (x, y, z)

{

      GL11.pushMatrix();

      GL11.translated(x, y, z);

      forge_clj.bindTexture("test-mod:textures/blocks/multiblock_4.png");//function I made to bind the texture string location.

      GL11/glColor3f(1F, 1F, 1F);                                                                                                                   

      //here I used to call a function to fix lighting, it didn't work so I removed the call in this pseudocode. It's the same code found

      //in the adjustLightFixture method

      //here

 

      //This line renders the model. Not entirely sure what the numbers mean.

    modelInstance.render(null, 0, 0, -0.1, 0, 0, 0.0625);

    GL11.popMatrix();

 

 

 

And that's it. Now someone please help me figure this out, I have no idea what the heck is wrong.

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

Posted

You appear to be getting only sky light. My renderer has this in its fixLightLevel method:

 

    int l = this.renderManager.worldObj.getCombinedLight (new BlockPos (i, j, k), 0);
    int i1 = l % 65536;
    int j1 = l / 65536;
    OpenGlHelper.setLightmapTextureCoords (OpenGlHelper.lightmapTexUnit, (float) i1, (float) j1);
    GL11.glColor3f (1.0F, 1.0F, 1.0F);

 

"Combined" light works for me.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

You appear to be getting only sky light. My renderer has this in its fixLightLevel method:

 

    int l = this.renderManager.worldObj.getCombinedLight (new BlockPos (i, j, k), 0);
    int i1 = l % 65536;
    int j1 = l / 65536;
    OpenGlHelper.setLightmapTextureCoords (OpenGlHelper.lightmapTexUnit, (float) i1, (float) j1);
    GL11.glColor3f (1.0F, 1.0F, 1.0F);

 

"Combined" light works for me.

 

I'm using 1.7.10, not 1.8, so getCombinedLight and BlockPos aren't defined. What's the equivalent call in 1.7.10?

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

Posted

Ok, I think I found something.

 

Looking at some of minecraft's rendering methods, they seem to use getLightBrightnessForSkyBlocks(). Originally, I was calling it with the wrong coordinates. However, even after I fixed this bug and the proper coordinates print out, getLightBrightnessForSkyBlocks() still constantly returns 0 every time. Any ideas?

 

EDIT: I've tested it with multiple values. The X, Y, and Z values seem to be correct, or at least it is the same as the coordinates in the f3 screen. The 4th argument seems to be the block light in this instance. If artificially set higher, the texture suddenly becomes normal due to actually receiving light. However, getLightValue at that location also returns 0. Maybe my coordinates or actually off, or something is wrong with the client world?

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

Posted

Ok, I finally figured it out, and it was stupidity on my part.

 

In the first post I did say that I had overriden isOpaqueCube, right? Well, as it turns out, the thing that determines opacity is when the Block class's constructer is invoked, by calling isOpaqueCube and setting lightOpacity to 255 if true or 0 if false.

 

So apparantly, with the way I implemented clojure java inter-op things, the constructor was called FIRST, BEFORE the new overrides were created. Because of that, even though the methods were overriden, and isOpaqueCube did return false, this happened after the constructor was called, and lightOpacity was already set to 255.

 

So yeah, I solved it. That was kinda stupid though.

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

Posted

"Combined" light works for me.

 

I'm using 1.7.10, not 1.8, so getCombinedLight and BlockPos aren't defined. What's the equivalent call in 1.7.10?

Ooops, sorry I forgot about version difference. Hold my suggestion for when you make your v1.8 edition of your mod. Glad you found your execution order bug and could fix it.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.