Jump to content

Recommended Posts

Posted

Hi first post so please excuse any glaring noobness.

 

I have been trying to learn how to code mods mainly as a way of getting back in to Java (not done much since finishing my AI degree 10 years ago). I have purchased several books, watched loads of videos, read loads of your posts etc. and thus far I am really enjoying tinkering with Minecraft. I can genuinely see why you guys love it so much.

 

So far I have done all the standard stuff in 1.7.10 (blocks, items, recipes, textures) and I would now like to do some work with .obj files and rendering a 3D item. I won't lie, I have tried so many random things I am a bit lost and really need someone to point me in the right direction. I fully appreciate you guys are not here to write my code etc. and I am not asking for that but if someone could have a look over my code and give me a nudge it would be very much appreciated.

 

The issue is that although I have made a model, made a renderer etc. nothing different is happening. I still get the same black and purple square that I had before I started adding textures (which i edited out) :(

 

Here is my MainRegistry.java arghh Spoiler isn't working sorry.

 

package com.hammy.MainRegistry;

 

import com.hammy.item.LaserItem;

import com.hammy.item.LaserRender;

 

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraftforge.client.MinecraftForgeClient;

 

public class ClientProxy extends ServerProxy {

 

    public void registerRenderInfo(){

   

    MinecraftForgeClient.registerItemRenderer(MainRegistry.Laser, new LaserRender());   

    }

 

}

 

 

Here is my Item LaserItem.java

 

package com.hammy.item;

 

import com.google.common.collect.HashMultimap;

import com.google.common.collect.Multimap;

import com.hammy.lib.RefStrings;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.attributes.AttributeModifier;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

 

public class LaserItem extends Item {

 

  public LaserItem() {

      super();

      this.setUnlocalizedName(RefStrings.MODID + "_" + "trustLaser");

      this.setCreativeTab(CreativeTabs.tabCombat);

      //this.setTextureName("hammytest:LaserItem");

      setMaxStackSize(1);

  }

       

}

 

 

Here is my Item Renderer LaserRender.java

 

package com.hammy.item;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.inventory.GuiContainerCreative;

import net.minecraft.client.gui.inventory.GuiInventory;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.client.IItemRenderer;

import net.minecraftforge.client.model.AdvancedModelLoader;

import net.minecraftforge.client.model.IModelCustom;

import com.hammy.item.LaserItem;

 

import org.lwjgl.opengl.GL11;

 

import com.hammy.lib.RefStrings;

 

public class LaserRender implements IItemRenderer {

 

public final ResourceLocation modelResource = new ResourceLocation(RefStrings.MODID, "models/LaserItem.obj");

 

//public IModelCustom model = AdvancedModelLoader.loadModel(modelResource);

 

IModelCustom model;

 

public LaserRender(){

 

IModelCustom model = AdvancedModelLoader.loadModel(modelResource);

// public final ResourceLocation texture = new ResourceLocation("assets/textures/items/Laser-texture.jpg");

 

 

 

}

 

 

 

@Override

public boolean handleRenderType(ItemStack item, ItemRenderType type) {

// TODO Auto-generated method stub

switch(type){

case EQUIPPED:

case EQUIPPED_FIRST_PERSON:

return true;

default:

return false;

}

}

 

@Override

public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {

// TODO Auto-generated method stub

return false;

}

 

public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {

switch(type){

case EQUIPPED:

case EQUIPPED_FIRST_PERSON:

{

GL11.glPushMatrix();

//Minecraft.getMinecraft().renderEngine.bindTexture(texture); //Not 100% sure if I got this right, but you bing the texture here.

//Do all your GL11 rotations, scales, and translaters here...

//this.model.renderAll(); //Finally render the model

 

model.renderAll();

 

GL11.glPopMatrix();

}

default:

break;

}

}

 

}

 

 

Here is my ClientProxy.java

 

package com.hammy.MainRegistry;

 

import com.hammy.item.LaserItem;

import com.hammy.item.LaserRender;

 

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraftforge.client.MinecraftForgeClient;

 

public class ClientProxy extends ServerProxy {

 

    public void registerRenderInfo(){

   

    MinecraftForgeClient.registerItemRenderer(MainRegistry.Laser, new LaserRender());   

    }

 

}

 

 

And here is my really basic .obj file created during Blender (which I also have no idea how to use but it is a dumb pyramid). LaserItem.obj

 

# Blender v2.74 (sub 0) OBJ File: ''

# www.blender.org

o Cube

v 1.000000 0.000000 -1.000000

v 1.000000 0.000000 1.000000

v -1.000000 0.000000 1.000000

v -1.000000 0.000000 -1.000000

v -0.000000 1.500000 0.000000

vn 0.000000 -1.000000 0.000000

vn 0.832100 0.554700 0.000000

vn -0.000000 0.554700 0.832100

vn -0.832100 0.554700 -0.000000

vn 0.000000 0.554700 -0.832100

s off

f 2//1 3//1 4//1

f 1//2 5//2 2//2

f 2//3 5//3 3//3

f 3//4 5//4 4//4

f 5//5 1//5 4//5

f 1//1 2//1 4//1

 

I am really sorry for the wall of text and code.

 

Also, here is my file tree just incase..

 

http://gyazo.com/9fa0cae3bddc6e45e8257e289cd23060

 

Is this forum running on 2011 software? The WYSIWYG isn't really doing anything in Chrome.

 

Anyhow, many thanks for any help or insight you guys can shed.

 

Ham out!

 

 

Posted

Oh sorry, basically all I get is the default square (purple and black) when held, dropped and first person. Nothing seems to be different from when it was just an item with a standard texture on it.

Posted
  On 7/3/2015 at 9:31 PM, HammyD said:

Oh sorry, basically all I get is the default square (purple and black) when held, dropped and first person. Nothing seems to be different from when it was just an item with a standard texture on it.

 

I think this might be you're issue.

   IModelCustom model;
   
   public LaserRender(){
   
      IModelCustom model = AdvancedModelLoader.loadModel(modelResource);
      // public final ResourceLocation texture = new ResourceLocation("assets/textures/items/Laser-texture.jpg");

 

What you're doing is setting a variable but never actually defining it.

What you need to do is change  IModelCustom model to model alone. In java whenever you set a variable you do not need to declare it's type again.

Posted

Can you actually confirm that the model is being loaded? Check the console, it should give you a few errors if something isn't loading properly. Also I have noticed another issue.

   @Override
   public boolean handleRenderType(ItemStack item, ItemRenderType type) {
      // TODO Auto-generated method stub
      switch(type){
     [b] case EQUIPPED:
      case EQUIPPED_FIRST_PERSON:
         return true;
      default:
         return false;[/b]
      }
   }   

 

Whenever you return false you are telling it not to render it period. Also on case EQUIPPED you never told it to return anything. Try changing that, if you still need help afterwards let me know.

EDIT: You're code is riddled with mistakes. Give me 1 minute to go through and give you what should be a working example.

Posted

Change your render class to this, it should work fine afterwards. Also you really need to look up the basics of java, you don't seem to understand how switch statements work.

 

package com.hammy.item;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import com.hammy.item.LaserItem;

import org.lwjgl.opengl.GL11;

import com.hammy.lib.RefStrings;

public class LaserRender implements IItemRenderer {

public final ResourceLocation texture = new ResourceLocation(RefStrings.MODID, "models/LaserItem.png");
public IModelCustom model = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/LaserItem.obj"));

IModelCustom model;

public LaserRender(){}



@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	switch(type){
	case EQUIPPED:
		return true;	
	case EQUIPPED_FIRST_PERSON:
		return true;
	default:
		return false;
	}
}   

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return true;
}

public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
	switch(type){
	case EQUIPPED:
		GL11.glPushMatrix();
		Minecraft.getMinecraft().renderEngine.bindTexture(texture);
		//Do all your GL11 rotations, scales, and translaters here...
		model.renderAll();
		GL11.glPopMatrix();
		break;
	case EQUIPPED_FIRST_PERSON:{
		GL11.glPushMatrix();
		Minecraft.getMinecraft().renderEngine.bindTexture(texture);
		//Do all your GL11 rotations, scales, and translaters here...
		model.renderAll();
		GL11.glPopMatrix();
	}
	default:
		break;
	}
}

}

Posted

Hi deadrecon98,

 

Many thanks for this. I replaced my render class with the one you crafted and nothing seems to have changed. Your other query about whether the object actually renders / is being loaded got me thinking. I have read through the console outputs and there is some moaning about a missing texture but nothing else I can see as an issue. I have attached the .txt dump

 

 

 

  Reveal hidden contents

 

 

Regarding Java switch statements, how do you mean exactly? I'm pretty certain the stacking of cases is fine as it just groups them all so they all trigger the same functionality as the last in the grouping.

 

Thanks again for your help with this, it really is greatly appreciated.

 

 

Ham.

Posted

I think I may have found the issue. In your main class is the modid all lower-case? If not go into the render class and change all cases of where it grabs the modid to have .toLowerCase() after it. As for the switch statements you had a couple blank ones which immediately go onto the next statement.

Posted

For my modid I use a reference file called RefStrings.java which contains them all. My RefStrings.MODID is set to "hammytest" so is always consistent.

 

I did find out one thing today. I was unsure as to whether forge was reading my .obj file so I made a new one using Blender. I forgot to triangulate the faces and when I ran MC is crashed telling me there were too many points in my object faces which means it is having a go at using my object. I fixed this by re-exporting.

 

Alas though, I still get the default purple and black square  :-[

Posted

I am going to assume that the issue is in your render class and not the model. Try using this for the render class. If this doesn't fix it then you need to upload all of your code somewhere so that I can get a better look at it.

Render Class:http://bit.ly/1feyNWD

How to use Render http://bit.ly/1LMEjfs

Posted

Hi deadrecon98, I have got it working  ;D ;D ;D ;D

 

I took all the complexity out of my mainRegistry file and migrated it in to the Item class.

 

Here are all my final files just in case anyone else has a similar problem (loads of people just go "I fixed it" and don't show how).

 

 

MainRegistry.java

 

  Reveal hidden contents

 

 

RefStrings.java

 

  Reveal hidden contents

 

 

LaserItem.java

 

  Reveal hidden contents

 

 

LaserRender.java

 

  Reveal hidden contents

 

 

ServerProxy.java

 

  Reveal hidden contents

 

 

ClientProxy.java

 

  Reveal hidden contents

 

 

Massive thanks to you deadrecon98 for your support during this. Between us we got it done  :)

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.