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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • accidental duplicate mesage cuz lag
    • https://gnomebot.dev/paste/231527759279685634/1372324909073563730/1372324908629102716 https://gnomebot.dev/paste/231527759279685634/1372320454861262908/1372320454299090996 seems like theres a registry sync error, not sure what that means though, however in an old pack i played on, i actually had a registry sync error happen whenever the world tried too save and it would suddenly stop loading chunks, is there a mod fix for this or some way too bypass registry syncing? is this a server problem? i have no issues with the pack on pc, only on my server.
    • i think the problem is the player animator library but i need it for one of my main mods is there any way i can fix this? The game crashed: rendering overlay Error: java.lang.IllegalArgumentException: Failed to create player model for default heres the crash report: https://pastebin.com/U5Wp8ysb
    • I have been an enthusiastic investor in crypt0currencies for several years, and my digital assets have been integral to my financial strategy. A few months ago, I encountered a distressing predicament when I lost access to my primary cryptocurrency walleet after clicking on an airdrop link that inadvertently connected to my walleet. The dread of potentially losing all my hard-earned funds was overwhelming, leaving me uncertain about where to seek assistance. In my pursuit of solutions, I stumbled upon ChainDigger Retrievers. From our initial consultation to the triumphant recovery of my assets, the team exhibited exceptional expertise. They provided comprehensive explanations of the recovery process, ensuring I was informed at every stage and offering reassurance during this tumultuous time. Their approach was not only meticulous but also compassionate, which significantly alleviated my anxiety. ChainDigger Retrievers unwavering commitment to resolving my issue was evident throughout the process. Leveraging their profound understanding of crypt0currency technology and digital forensics, they initiated an exhaustive investigation to trace the transactions linked to my compromised wallet. Their meticulous analysis and relentless determination were apparent as they left no stone unturned in their quest to recover my funds. After several days of diligent investigation, the team successfully recovered everything I had lost. They uncovered that the link I had clicked contained malware, which scammeers had used to infiltrate my walleet. This revelation was both alarming and enlightening, underscoring the inherent risks associated with crypt0currency transactions when proper precautions are not taken.Thanks to ChainDigger Retrievers, I not only regained everything but also acquired invaluable knowledge about safeguarding my investments. Their expertise and steadfast support transformed a daunting situation into a manageable one, and I am profoundly grateful for their assistance. I can now continue my investment journey with renewed confidence, knowing that I have a trustworthy ally in ChainDigger Retrievers. Their client satisfaction is truly commendable, and I wholeheartedly recommend their services to anyone facing similar challenges in the crypt0currency realm. With their help, I was able to turn a distressing time into a positive outcome, and I will forever be grateful for their support.  
    • I didn’t even notice that side of the report, as I expected it was a bunch of client mods, thanks for the advice
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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