Jump to content

Having difficulty writing a rendering class


VulcanForge

Recommended Posts

Hello all, I'm new to entities, modelling, and rendering (though I do know how to mod blocks and items and have a good knowledge of Java). I read about five different tutorials on how to mod custom entities in 1.7 (I'm not going with 1.8 because it's too much hassle for me), but for some reason I simply can't get my entity to render properly. My entity has its own class, it's registered, and it even appeared as a white block before I wrote the rendering class. I made a model in Techne, exported it as Java and a texturemap, put the texturemap under src/main/resources/assets/rendertestmod/textures/entity/drill.png, and fixed up the Java file the way other tutorials said to do it. Then I wrote the rendering class the way the tutorials said, but whenever I summon my entity, I now get an extremely strange pattern of textures floating in the air, that seem to follow me, and definitely don't conform to the shape of the model I made. I'll put the code below.

package com.example.rendertestmod;

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

public class ModelDrill extends ModelBase
{
    ModelRenderer Base;
    ModelRenderer Bit;
  
  public ModelDrill()
  {
    textureWidth = 64;
    textureHeight = 64;
    
      Base = new ModelRenderer(this, 0, 0);
      Base.addBox(0F, 0F, 0F, 16, 8, ;
      Base.setRotationPoint(-8F, 0F, -4F);
      Base.setTextureSize(64, 64);
      Base.mirror = true;
      setRotation(Base, 0F, 0F, 0F);
      Bit = new ModelRenderer(this, 0, 16);
      Bit.addBox(-8F, -2F, -2F, 8, 4, 4);
      Bit.setRotationPoint(-8F, 4F, 0F);
      Bit.setTextureSize(64, 64);
      Bit.mirror = true;
      setRotation(Bit, 0F, 0F, 0F);
  }
  
  public void render(float f5)
  {
Base.render(f5);
    Bit.render(f5);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
  }

}

package com.example.rendertestmod;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;

public class RenderDrill extends Render {

static ModelDrill drill = new ModelDrill();

public RenderDrill() {
	// TODO Auto-generated constructor stub
}

@Override
public void doRender(Entity e, double f1,
		double f2, double f3, float f4,
		float f5) {
	GL11.glPushMatrix();
	drill.render(.0625F);
                GL11.glPopMatrix();
}

@Override
protected ResourceLocation getEntityTexture(Entity p_110775_1_) {
	// TODO Auto-generated method stub
	return new ResourceLocation("rendertestmod:textures/entity/drill.png");
}

}

package com.example.rendertestmod;

import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

public class EntityDrill extends Entity {

public EntityDrill(World w) {
	super(w);
	// TODO Auto-generated constructor stub
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {
	// TODO Auto-generated method stub

}

@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {
	// TODO Auto-generated method stub

}

}

 

About the rendering class: I used render(.0625F) because that's what I saw in another code file in another mod. I have no idea what that float argument means. Also, there were no errors during startup even when I changed the texture name to gibberish, so I feel like I might be doing something wrong about the location of the texture, but I don't know what. Sorry if this sounds like a noobish question, and sorry if I wasn't supposed to ask questions about such basic topics on this forum, but the tutorials are not very helpful. I'll post screenshots of my Eclipse setup if you need to see those.

 

Also, bear in mind that this is just an experiment for me to find out the basics of rendering entities. That's why the entity does nothing except sit there and display its textures to me.  :)

Link to comment
Share on other sites

Calling the GL translate method with the 2nd, 3rd, and 4th parameters (x, y, and z) is also very important - if you don't, you very likely will not see anything at all.

 

Yes, now I can see the entity the way I intended. I also discovered that the argument to the render(float) method is the scale. However, the entity vanishes when being viewed from certain angles. I can see it from some angles and not from others. Anyone have any insights? Maybe a call to glEnable() and glDisable() with one of the filter constants?

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

    • Whether you are a fan of Hypixel Bedwars, SkyWars and PvP gamemodes like that, well you would enjoy this server! We have a very fun and unique style of PvP that a lot of our players really enjoy and we want to bring this server to more players like you! Yes you reading this post haha. Introducing, the Minezone Network, home of SUPER CRAFT BLOCKS. We've been working on this server for over 4 years now. Here is what we have to offer: SUPER CRAFT BLOCKS: This has 3 different gamemodes you can play, Classic, Duels and Frenzy. Each mode offers over 60 kits to choose from, along with a total of over 60 maps, allowing for various different playstyles on each map. There are also random powerups that spawn on the map which can include Health Pots, Bazookas, Nukes, Extra Lives and way way more! There is also double jump in this gamemode as well, which makes PvP a lot more fun & unique. You only need a minimum of 2 players to start any mode! Classic: Choose a kit, 5 lives for each player, fight it out and claim the #1 spot! Look out for lightning as they can spawn powerups to really give you an advantage in the game! Duels: Fight against another random player or one of your friends and see who is the best! Frenzy: Your kit is randomly selected for you, each life you will have a different kit. You can fight with up to 100 players in this mode and lets see who will be the best out of that 100! All the other stuff from Classic/Duels apply to this mode as well like powerups. We have 2 ranks on this server too, VIP and CAPTAIN which has a bunch of different perks for SCB and other things like Cosmetics and more.   SERVER IP: If this server has caught your interest in any way, please consider joining and you will NOT regret it! Bring some of your friends online for an even better experience and join in on the fun at: IP: minezone.club Hope to see you online!   SERVER TRAILER: https://www.youtube.com/watch?v=0phpMgu1mH0
    • The mod give new blocks  
    • I will a Mode for 1.21 in this Mod give new block, items and dimensions   
    • Remove Optifine For shader support and similar, use Embeddium + Oculus
  • Topics

×
×
  • Create New...

Important Information

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