Posted July 23, 20169 yr I want to start updating my mod (http://minecraft.curseforge.com/projects/techguns) to 1.10, but the biggest problem is item Rendering. There are many 3D gun models which all extend ModelBase (Techne models exported to java), They are alle rendered with IItemRender. So, what is the best way to even get 3D models for items in 1.10 and get the same features as in 1.7? It's really hard to find informations on that topic. I have read something about ItemOverrideList? but i can't find any proper documentation/tutorial on it? Also I would like to reuse the Models and not have to convert them to some other format, since this would be a lot of work. The Features I need: Render Item as 3D, Transform differenty depending on RenderType (Inventory, 1st Person, 3rd Person, Entity) and only render specific sub-parts (so I can apply different transformations on them, or hide a part in some cases). Just for Reference, this is the base gun renderer: package techguns.client.renderer.item; import net.minecraft.client.Minecraft; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import org.lwjgl.opengl.GL11; import techguns.client.ClientProxy; import techguns.client.models.ModelMultipart; import techguns.entities.npc.GenericNPC; import techguns.entities.npc.NPCTurret; import techguns.items.armors.ICamoChangeable; import techguns.items.guns.GenericGun; import techguns.items.guns.GenericGunCharge; public abstract class RenderGunBase implements IItemRenderer { ResourceLocation texture; ModelMultipart model; float scale; //uniform scale float x; //offset float y; //offset float z; //offset boolean handleDamageValue=false; boolean handleProgress=false; boolean hasZoom=false; int parts; public RenderGunBase(ModelMultipart model, ResourceLocation texture, float scale, float x, float y, float z, boolean handledamage, boolean handleprogress, int parts,boolean hasZoom) { this.parts = parts; this.model = model; this.texture = texture; this.scale = scale; this.x = x; this.y = y; this.z = z; handleDamageValue=handledamage; handleProgress=handleprogress; this.hasZoom=hasZoom; } private boolean isZooming(){ return this.hasZoom && ClientProxy.get().player_zoom!=1.0f; } public abstract void renderScope(); /** * @param part - part to be rendered, only interesting for multipart models * @param prog - progress, [0.0f-1.0f] * @param attackType */ protected abstract void GL_Transform_FirstPerson(int part,float prog, byte attackType); /** * @param part - part to be rendered, only interesting for multipart models * @param prog - progress, [0.0f-1.0f] * @param attackType */ protected abstract void GL_Transform_Equipped(int part,float prog, byte attackType); /** * @param part - part to be rendered, only interesting for multipart models */ protected abstract void GL_Transform_Ground(int part); /** * @param part - part to be rendered, only interesting for multipart models */ protected abstract void GL_Transform_Icon(int part); /** * @param part - part to be rendered, only interesting for multipart models * @param prog - progress, [0.0f-1.0f] * @param attackType */ protected abstract void GL_Transform_reloading(int part,float prog, byte attackType); /** * @param part - part to be rendered, only interesting for multipart models */ //protected abstract void GL_Transform_reload_done(int part); /** * @param part - part to be rendered, only interesting for multipart models * @param attackType */ protected abstract void GL_Transform_firing(int part, float prog, byte attackType); /** * @param part - part to be rendered, only interesting for multipart models */ protected abstract void GL_Transform_Translate(int part); /** * @param prog - progress, [0.0f-1.0f] */ protected abstract void drawMuzzleFX(float prog); /** * @param part - part to be rendered, only interesting for multipart models * @param prog - progress, [0.0f-1.0f] * @param attackType TODO */ protected void GL_TransformRecoil_Equipped(int part, float prog, byte attackType){ if(prog<0.3f){ GL11.glRotatef(prog/0.3f*-30, 0, 0, 1); } } /** * @param part - part to be rendered, only interesting for multipart models * @param prog - progress, [0.0f-1.0f] * @param attackType TODO */ protected abstract void GL_TransformReload_Equipped(int part, float prog, byte attackType); /** * @param part TODO * @param part - part to be rendered, only interesting for multipart models */ //protected abstract void GL_Transform_reload_done_Equipped(int part); protected void transformEquippedAimedRotation(int part){ //GL11.glRotated(90.0f-21.0f, 1, 0, 0); //GL11.glRotated(90.0f-21.0f, 1, 0, 0); GL11.glRotated(-45, 1, 0, 0); GL11.glRotated(-18, 0, 1, 0); GL11.glRotated(45, 0, 0, 1); //GL11.glTranslated(0,0,-0.45f); GL11.glRotatef(45, 0, 1, 0); this.transformEquippedAimed(part); GL11.glRotatef(-45, 0, 1, 0); //GL11.glRotated(Keybinds.Z, 0, 0, 1); } protected void transformEquippedAimed(int part){ GL11.glTranslatef(0f, -1.3f, -0.4f); //GL11.glTranslated(Keybinds.X, Keybinds.Y, Keybinds.Z); } /*protected void transformRotateAimed(int part){ GL11.glRotated(90.0f-21.0f, 1, 0, 0); }*/ @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { //muzzleflash boolean showMuzzleFX = false; float muzzleFXprogress = 0; boolean renderScope=false; boolean reloading=false; ClientProxy cp = ClientProxy.get(); float prog =0.0f; //fire progress byte attackType=0; for (int i=0; i<this.parts; i++){ prog=0.0f; attackType=0; GL11.glPushMatrix(); float reloadProgress =10.0f; // A VALUE > 1.0f and outside of [0-1] if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) { attackType = cp.getplayerAttackType((EntityLivingBase) data[1]); if (this.handleProgress && Minecraft.getMinecraft().thePlayer.getItemInUse()!=null){ int dur = Minecraft.getMinecraft().thePlayer.getItemInUseDuration(); //System.out.println("dur:"+dur+" maxDur:"+maxdur); //System.out.println("X:"+(maxdur-dur)); if(item.getItem() instanceof GenericGunCharge){ prog = dur / ((GenericGunCharge)item.getItem()).fullChargeTime; } else { prog = dur / (20*1.0f); } if (prog < 0.0f) { prog = 0.0f; } else if (prog > 1.0f) { prog = 1.0f; } // } else if(!((GenericGun)item.getItem()).isShootWithLeftClick()){ // long swingdiff = cp.getplayerRecoiltime(ClientProxy.get().getPlayerClient()) - System.currentTimeMillis(); // if(swingdiff<0){ // prog =0.0f; // } else if(cp.getplayerRecoiltimeTotal()!=0) { // prog=(swingdiff*1.0f)/(cp.getplayerRecoiltimeTotal()*1.0f); // if(prog>1.0f){ // prog=1.0f; // } // } // //System.out.println("prog:"+prog); } this.GL_Transform_FirstPerson(i,prog, attackType); //Reloading if (cp.getplayerReloadtime(ClientProxy.get().getPlayerClient()) >0) { long diff = cp.getplayerReloadtime(ClientProxy.get().getPlayerClient()) - System.currentTimeMillis(); if (diff <= 0) { //ClientProxy.setplayerReloadtime(0); //ClientProxy.setplayerReloadtimeTotal(0); cp.setplayerReloadtime(ClientProxy.get().getPlayerClient(),0, 0, (byte)0); //this.GL_Transform_reload_done(i); this.GL_Transform_Translate(i); }else { long reloadtimeTotal = cp.getplayerReloadtimeTotal(); reloadProgress = 1.0f-((float)diff / (float)reloadtimeTotal); this.GL_Transform_reloading(i,reloadProgress, attackType); } }else if (cp.getplayerRecoiltime(ClientProxy.get().getPlayerClient()) > 0) { if (!isZooming()){ long diff = cp.getplayerRecoiltime(ClientProxy.get().getPlayerClient()) - System.currentTimeMillis(); //System.out.println("firing: "+diff); if (diff <= 0 || diff > cp.getplayerRecoiltimeTotal()) { //System.out.println("firing done"); //ClientProxy.setplayerRecoiltime(0); //ClientProxy.setplayerRecoiltimeTotal(0); cp.setplayerRecoiltime(ClientProxy.get().getPlayerClient(), 0, 0, (byte)0); this.GL_Transform_Translate(i); }else{ float fireProgress = 1.0f-((float)diff / (float)cp.getplayerRecoiltimeTotal()); this.GL_Transform_firing(i,fireProgress, attackType); prog=fireProgress; } } else { renderScope=true; } }else { if(!isZooming()){ this.GL_Transform_Translate(i); showMuzzleFX = false; } else { renderScope=true; } //GL11.glTranslatef(0.1f, 0, -0.5f); } if (cp.player_muzzleFlashtime > 0) { long diff = cp.player_muzzleFlashtime - System.currentTimeMillis(); if (diff <= 0 || diff > cp.player_muzzleFlashtime_total) { cp.player_muzzleFlashtime = 0; cp.player_muzzleFlashtime_total = 0; }else{ showMuzzleFX = true; muzzleFXprogress = 1.0f-((float)diff / (float)cp.player_muzzleFlashtime_total); } } } else if (type == ItemRenderType.EQUIPPED){ EntityLivingBase shooter = (EntityLivingBase) data[1]; attackType = cp.getplayerAttackType(shooter); //float progress=0.0f; prog=0.0f; if (cp.getplayerReloadtime(shooter) > 0){ long diff = cp.getplayerReloadtime(shooter) - System.currentTimeMillis(); if (diff <= 0) { //ClientProxy.setplayerReloadtime(shooter,0); //ClientProxy.setplayerReloadtimeTotal(shooter,0); cp.setplayerReloadtime(shooter, 0, 0,(byte)0); //this.GL_Transform_Translate(i); }else { long reloadtimeTotal = cp.getplayerReloadtimeTotal(shooter); reloadProgress = 1.0f-((float)diff / (float)reloadtimeTotal); reloading=true; //this.GL_TransformReload_Equipped(i,reloadProgress); } } else if( cp.getplayerRecoiltime(shooter) > 0) { long diff = cp.getplayerRecoiltime(shooter) - System.currentTimeMillis(); //System.out.println("firing: "+diff); if (diff <= 0 || diff > cp.getplayerRecoiltimeTotal(shooter)) { //System.out.println("firing done"); //ClientProxy.setplayerRecoiltime(shooter, 0); //ClientProxy.setplayerRecoiltimeTotal(shooter, 0); cp.setplayerRecoiltime(shooter, 0, 0, (byte)0); //this.GL_Transform_Translate(i); }else{ prog = 1.0f-((float)diff / (float)cp.getplayerRecoiltimeTotal(shooter)); //System.out.println("FireProgress"+prog); //this.GL_Transform_firing(i,fireProgress); } } boolean aimed = shooter instanceof EntityPlayer || (shooter instanceof GenericNPC && ((GenericNPC)shooter).getHasAimedBowAnim() ) ; if(aimed){ this.transformEquippedAimedRotation(i); } this.GL_Transform_Equipped(i,prog, attackType); /*if(aimed){ this.transformRotateAimed(i); }*/ //no recoil for turrets if ((shooter instanceof NPCTurret)){ prog=0.0f; } if(reloading){ this.GL_TransformReload_Equipped(i,reloadProgress, attackType); } else { this.GL_TransformRecoil_Equipped(i,prog, attackType); } } else if (type == ItemRenderType.ENTITY){ this.GL_Transform_Ground(i); } else if (type == ItemRenderType.INVENTORY){ this.GL_Transform_Icon(i); } if (!renderScope){ byte camo=0; if(item.getItem() instanceof ICamoChangeable){ ICamoChangeable camoitem = (ICamoChangeable) item.getItem(); camo=(byte) camoitem.getCurrentCamoIndex(item); } ResourceLocation tex= ((GenericGun) item.getItem()).textures.get(camo); //System.out.println("texture->:"+tex); Minecraft.getMinecraft().getTextureManager().bindTexture(tex); if (this.handleDamageValue){ model.render(null, 0, 0, 0, 0, 0, 0.0625F,((GenericGun)item.getItem()).getCurrentAmmo(item),reloadProgress, type,i, prog); } else { model.render(null, 0, 0, 0, 0, 0, 0.0625F ); } GL11.glPopMatrix(); if(i==this.parts-1){ if (showMuzzleFX) { GL11.glPushMatrix(); GL11.glRotatef(45, 0, 1.0f, 0); GL11.glRotatef(90, 0, 0, 1.0f); //GL11.glTranslatef(1.7f, 0f, -0.7f); GL11.glTranslatef(1.5f, -1.0f, -0.5f); drawMuzzleFX(muzzleFXprogress); GL11.glPopMatrix(); } if (type == ItemRenderType.EQUIPPED_FIRST_PERSON) { //Show Additional effects (first person): GL11.glPushMatrix(); GL11.glRotatef(45, 0, 1.0f, 0); GL11.glRotatef(90, 0, 0, 1.0f); GL11.glTranslatef(1.5f, -1.0f, -0.5f); drawExtraEffects(); GL11.glPopMatrix(); } } } else { GL11.glPopMatrix(); //SCOPE ONLY RENDERED ONCE if (i==0){ GL11.glPushMatrix(); GL11.glRotatef(45, 0, 1.0f, 0); GL11.glRotatef(90, 0, 0, 1.0f); //GL11.glTranslatef(1.7f, 0f, -0.7f); //up/down, ? , ? if (cp.getplayerRecoiltime(ClientProxy.get().getPlayerClient()) > 0) { long diff = cp.getplayerRecoiltime(ClientProxy.get().getPlayerClient()) - System.currentTimeMillis(); //System.out.println("firing: "+diff); if (diff <= 0 || diff > cp.getplayerRecoiltimeTotal()) { //System.out.println("firing done"); //ClientProxy.setplayerRecoiltime(0); //ClientProxy.setplayerRecoiltimeTotal(0); //cp.setplayerRecoiltime(ClientProxy.get().getPlayerClient(), 0, 0, (byte)0); //this.GL_Transform_Translate(i); }else{ float fireProgress = 1.0f-((float)diff / (float)cp.getplayerRecoiltimeTotal()); //this.GL_Transform_firing(i,fireProgress); float recoil; if (fireProgress<0.2f){ recoil = fireProgress*5f; } else { recoil = 1-(fireProgress-0.2f)*1.25f; } //X -> up/down, Y-> back/front, z = right/left //System.out.println("Recoiling:"+recoil); this.translateScopeRecoil(recoil); } } //GL11.glTranslatef(1.80f, 0f, -0.72f); //ScreenEffect.muzzleFlash.doRender(0.0f, 0, 0, 0, 1.0f); //ScreenEffect.sniperScope.doRender(0.0f, 0,0,0, 2.25f); renderScope(); GL11.glPopMatrix(); } } /*Minecraft.getMinecraft().getTextureManager().bindTexture(texture); model.render(null, 0, 0, 0, 0, 0, 0.0625F, item.getMaxDamage()-item.getItemDamage(),reloadProgress, type,i ); */ //GL11.glPopMatrix(); } } public void translateScopeRecoil(float recoil){ GL11.glTranslatef(0.2f*recoil, 0.25f*recoil, 0.10f*recoil); } @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { return true; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { return true; } protected void drawExtraEffects() { //null } } PS: are there some good documentations about the new capability system? Especially in what cases to use it? Edit: typos
July 23, 20169 yr The only way to render a ModelBase for an Item is with a TESR , but this is deprecated and will be removed as soon as possible. You will need to convert your models to JSON, OBJ or B3D or write your own model loader for some other format. This program converts Techne models to JSON. You can apply transformations to and hide model parts using AnimationProperty and IModelState . Forge has an example of hiding model parts here. You can apply transformations to the whole model depending on the transform type ( thirdperson_righthand , thirdperson_lefthand , firstperson_righthand , firstperson_lefthand , head , gui , ground , fixed ) using Forge's blockstates format. Forge has an example here, but it's slightly outdated because it doesn't account for the left-/right-hand transform types added in 1.9 (though Forge will use the thirdperson transformation as thirdperson_righthand , the same applies to firstperson and firstperson_righthand ). Forge's documentation has a section on capabilities here. The main use case is to implement an API (your own or someone else's) and allow other mods to interact with your things, e.g. IItemHandler to allow automated item storage access, IFluidHandler to allow automated fluid storage access. Another use case is to store data in an ItemStack (e.g. an IItemHandler inventory) without having to read from/write to NBT every time you interact with it. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 24, 20169 yr Author Thanks, that's definitely helpful, but this seems to be for Blocks only? I can't find an example what is needed to load an .obj for an item. How must the .json for the item look like? Do I need a blockstate definition for an model for a pure item (no ItemBlock, an item, that only has an item form)? This is quite confusing and all the examples are Blocks only?
July 24, 20169 yr Thanks, that's definitely helpful, but this seems to be for Blocks only? I can't find an example what is needed to load an .obj for an item. How must the .json for the item look like? Do I need a blockstate definition for an model for a pure item (no ItemBlock, an item, that only has an item form)? This is quite confusing and all the examples are Blocks only? Currently, yes, you need blockstate definitions for items too. It works well for items just like blocks, if you specify 'inventory' type correctly. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
July 24, 20169 yr Author I got the model loaded, but I can't get the Texture to work, how do I set the Texture for a .obj? Preferable I could change the texture from withing code (I had custom textures dependent on NBT tags).
July 24, 20169 yr Author I think I'm hitting the wall with 1.10. Is it even possible to rotate/translate the model around like in IItemRenderer, not during initialization but during rendering? Example: Player fires gun. Client saves timestamp. In ItemRenderer the timestamp is used to calculate the recoilprogress, and then the model gets additionally rotated back a bit and then forward again. So, every Frame I need do calculate the rotations/translations the model has.
July 24, 20169 yr Thanks, that's definitely helpful, but this seems to be for Blocks only? I can't find an example what is needed to load an .obj for an item. How must the .json for the item look like? Do I need a blockstate definition for an model for a pure item (no ItemBlock, an item, that only has an item form)? This is quite confusing and all the examples are Blocks only? The ModelResourceLocation you set for an Item using ModelLoader.setCustomModelResourceLocation / setCustomMeshDefinition can point to a model in any supported format or a variant of a blockstates file. I explain the model loading process and how ModelResourceLocation s are mapped to models here. To use an OBJ model, you must call OBJLoader#addDomain with your resource domain (lowercase mod ID) in preInit and then specify the OBJ model the same way you'd specify a JSON model, but include the .obj extension in the path. OBJ textures are specified in the material library (.mtl) file with the same name as the model. You can see some examples from Forge here. To hide item model parts dynamically, you'll probably need to create your own IModel , ICustomModelLoader and ItemOverrideList . There's not much documentation, but again there are examples in Forge (though not of this specific thing) like ModelDynBucket . Forge now has an animation system for baked models, which you'll probably want to use for the recoil. You can see an example from Forge here: code, assets. This page explains the grammar of the Animation State Machine files. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 24, 20169 yr Author I got the model including texture working by manually writing the mtl definitions in the .obj file. At the beginning: mtllib <name_of_ml>.mtl usemtl <name_of_material_defined_in.mtl> I also had to resize the texture to quadratic and mirror it vertically. I was very close to saying "Fuck it, I'm staying on 1.7.10". I can understand anybody who has not updated yet. Let's see how the Transformations work out, I have a bad feeling about this...
July 24, 20169 yr Author I give up, that's just hopeless. Staying with 1.7.10 it is then. Maybe there will be a solution at a later point. Edit: Is there really no way to get ModelBase rendered for items in 1.10?
July 24, 20169 yr I give up, that's just hopeless. Staying with 1.7.10 it is then. Maybe there will be a solution at a later point. Edit: Is there really no way to get ModelBase rendered for items in 1.10? As I said in my first post, you can use a TESR ; though this is deprecated and marked for removal. You can register this TESR with ForgeHooksClient.registerTESRItemStack . There is no other way, the baked model and animation systems are the replacement for direct OpenGL rendering. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 24, 20169 yr Author I give up, that's just hopeless. Staying with 1.7.10 it is then. Maybe there will be a solution at a later point. Edit: Is there really no way to get ModelBase rendered for items in 1.10? As I said in my first post, you can use a TESR ; though this is deprecated and marked for removal. You can register this TESR with ForgeHooksClient.registerTESRItemStack . There is no other way, the baked model and animation systems are the replacement for direct OpenGL rendering. A solution that will be removed soon is not really something I want, the moment this is gone I have an new problem :-/. The biggest problem with the new system is that there is very little documentation. I could not find a single example where a custom item with an .obj model is rendered. I got it to render the item as obj, but I have no Idea how all that animation stuff works. I have read everything you linked and looked at the forge interfaces, but the documentation is so minimal and the methods are all totally confusing. It can't be nobody uses 3d models for items. Edit: Ok, I can handle transformations in json, so I need to see how the animation system works. At least I can hold a m4 in my hand now:
July 25, 20169 yr Author I tried now to create an animation with the animation system, but that's pretty much not understandable. The whole example from forge has no comments and doesn't really explain much. Is there any proper explanation on how the animation system is used? What it can do, and what not? How to I "play" an animation on an item? I want IItemRenderer back :'(
July 25, 20169 yr Unfortunately I can't really help you with the animation system myself. Looking at the example I linked, it seems you use IAnimationStateMachine#transition to transition to a new state and play the corresponding clip. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.