Jump to content

[1.7.10] Tile Entity Special Renderer Renders Model Too Dark


yoshiquest

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

"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.

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

    • Etumax Royal Honey Price In Pakistan - Get Free Delivery Shop Today Online With Online Shopping in Pakistan Etumax Royal Honey Available At Our Store Online Shopping in Pakistan, 
    • I want to make a tree decorator that will generate a beehive under branches of my tree. I have no idea how to check for branches and make beehives generate because TreeDecorator.Context.logs() is just a block pos and i dont understand how it works. i hope ill get an answer here.
    • Imagine this: you've painstakingly accumulated $97,000 worth of Bitcoin, only to see it vanish into the digital abyss at the hands of cunning scammers. It's a devastating blow, leaving you feeling helpless and betrayed. But fear not, for Lee Ultimate Hacker is here to turn the tide in your favor. After conducting extensive research on cryptocurrency recovery options, I stumbled upon Lee Ultimate Hacker, and it proved to be the most suitable choice for the daunting task at hand. Despite my initial skepticism, they shattered my doubts by successfully retrieving $92,000 of the lost Bitcoin—a feat I once deemed impossible. From the moment I reached out to Lee Ultimate Hacker and provided them with all the pertinent information about the fraudulent transaction, they sprang into action with unwavering determination. True to their word, they delivered on their promise to recover the lost Bitcoin within an impressive timeframe of 24 to 72 hours. Their professionalism, expertise, and commitment to their clients were truly commendable, transforming what seemed like an insurmountable ordeal into a resounding triumph. In my eyes, the investment of both time and money was more than justified by the remarkable outcome achieved by Lee Ultimate Hacker. So, if you've fallen victim to cryptocurrency scams and are grappling with the anguish of lost funds, don't despair. Reach out to Lee Ultimate Hacker and let them work their magic. Their track record of success speaks for itself, and with their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. Don't let the darkness of cybercrime overshadow your financial future. Take a stand against fraudsters with the help of Lee Ultimate Hacker, and witness the transformation from despair to triumph. Your journey to recovery starts here. LEEULTIMATEHACKER@ AOL. COM or Support @ leeultimatehacker . com. telegram:LEEULTIMATE or wh@tsapp +1  (715) 314  -  9248 https://leeultimatehacker.com Thank you.
    • There's a scheme I got into where they promised to trade Bitcoin for me and take a cut as a commission. Seemed like a good idea at the time. But then, things went south real fast. They ended up transferring   $190,000 worth of my Bitcoin. I was devastated and felt completely helpless. That's when I stumbled upon the Wizard Web Recovery Tool. It was like a beacon of hope amid chaos. With this tool, I could finally start digging into what went wrong and hopefully get my Bitcoin back. Using Wizard Web was surprisingly easy. I just had to plug in some details about my Bitcoin account and let it do its thing. It started scanning the internet, looking for any clues about what happened to my Bitcoin. It felt like having a detective on my side, searching for answers. And guess what? Wizard Web found some leads. It uncovered evidence of the scheme's shady dealings and helped me track down the people responsible for losing my Bitcoin. Armed with this information, I took the case to court. After a long and hard-fought legal battle, the court ruled in my favor. The perpetrators were held accountable for their actions and faced criminal charges for their involvement in the scheme. It was a victory not just for me, but for anyone who's been taken advantage of by these kinds of scams. Thanks to Wizard Web Recovery, I was able to get justice and reclaim what was rightfully mine. It showed me that even in the face of adversity, there's always a way to fight back. And with the right tools and determination, anything is possible.   The following is the contact information for Wizard Web Recovery.   Email: wizard web recovery((@))programmer . net
    • Hello, good morning. I know some programming and I'm interested in mod creation. That's why I've decided to follow a tutorial guide on YouTube by TurtyWurty. https://www.youtube.com/watch?v=DhoX9cmAZqA&t=160s&ab_channel=TurtyWurty I've followed the tutorial perfectly. The problem is that when checking the food, the texture doesn't load for me. However, everything seems fine no matter how much I check. I'm sure it's something trivial, the problem is that I can't find it. Could you help me solve it, please? I leave a zip of my file so you can edit it freely. forge-1.20-Civicraft.rar
  • Topics

×
×
  • Create New...

Important Information

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