Jump to content

Recommended Posts

Posted

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

 

Posted

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.

Posted

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?

Posted

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.

Posted

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

 

Posted

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.

 

 

Posted

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.

Posted

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

Posted

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?

Posted

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.

Posted

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:

Posted

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  :'(

Posted

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.

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

    • Hi! I'm trying to add my custom models/textures renderer like this: public class PonyPlayerWrapperRenderer extends EntityRenderer<Player> { // wrapper class under my LivingEntityRenderer class implementation private final PonyPlayerRenderer innerRenderer; private final PonyPlayerRenderer innerSlimRenderer; public PonyPlayerWrapperRenderer(final EntityRendererProvider.Context context) { super(context); System.out.println("creating new PonyPlayerWrapperRenderer"); this.innerRenderer = new PonyPlayerRenderer(context, false); this.innerSlimRenderer = new PonyPlayerRenderer(context, true); } @Override public void render(final Player entity, final float yaw, final float partialTicks, final PoseStack poseStack, final MultiBufferSource bufferSource, final int packedLight) { System.out.println("PonyPlayerWrapperRenderer render: " + entity.toString()); if (entity instanceof AbstractClientPlayer clientPlayer) { if (clientPlayer.getModelName().contains("slim")) { innerSlimRenderer.render(clientPlayer, yaw, partialTicks, poseStack, bufferSource, packedLight); } else { innerRenderer.render(clientPlayer, yaw, partialTicks, poseStack, bufferSource, packedLight); } } } @Override public ResourceLocation getTextureLocation(final Player player) { System.out.println("PonyPlayerWrapperRenderer getTextureLocation"); if (player instanceof AbstractClientPlayer clientPlayer) { return clientPlayer.getSkinTextureLocation(); } System.out.println("player instanceof AbstractClientPlayer is false"); return getDefaultSkin(player.getUUID()); } } public class PonyPlayerRenderer extends LivingEntityRenderer<AbstractClientPlayer, PlayerModel<AbstractClientPlayer>> { private final PlayerModel<AbstractClientPlayer> earthModel; private final PlayerModel<AbstractClientPlayer> pegasusModel; private final PlayerModel<AbstractClientPlayer> unicornModel; public PonyPlayerRenderer(final EntityRendererProvider.Context context, final boolean slim) { super( context, slim ? new PonyModelSlim(context.bakeLayer(PonyModelSlim.LAYER_LOCATION)) : new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)), 0.5f ); System.out.println("creating new PonyPlayerRenderer"); this.earthModel = slim ? new PonyModelSlim(context.bakeLayer(PonyModelSlim.LAYER_LOCATION)) : new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)); this.pegasusModel = new PegasusModel(context.bakeLayer(PegasusModel.LAYER_LOCATION)); this.unicornModel = new UnicornModel(context.bakeLayer(UnicornModel.LAYER_LOCATION)); } @Override public void render(final AbstractClientPlayer player, final float entityYaw, final float partialTicks, final PoseStack poseStack, final MultiBufferSource buffer, final int packedLight) { final PonyRace race = player.getCapability(PONY_DATA) .map(data -> ofNullable(data.getRace()).orElse(PonyRace.EARTH)) .orElse(PonyRace.EARTH); this.model = switch (race) { case PEGASUS -> pegasusModel; case UNICORN -> unicornModel; case EARTH -> earthModel; }; super.render(player, entityYaw, partialTicks, poseStack, buffer, packedLight); } @Override public ResourceLocation getTextureLocation(final AbstractClientPlayer player) { final PonyRace race = player.getCapability(PONY_DATA) .map(data -> ofNullable(data.getRace()).orElse(PonyRace.EARTH)) .orElse(PonyRace.EARTH); return switch (race) { case EARTH -> fromNamespaceAndPath(MODID, "textures/entity/earth_pony.png"); case PEGASUS -> fromNamespaceAndPath(MODID, "textures/entity/pegasus.png"); case UNICORN -> fromNamespaceAndPath(MODID, "textures/entity/unicorn.png"); }; } } @Mod.EventBusSubscriber(modid = MODID, bus = MOD, value = CLIENT) public class ClientRenderers { // mod bus render registration config @SubscribeEvent public static void onRegisterLayerDefinitions(final EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(PonyModel.LAYER_LOCATION, PonyModel::createBodyLayer); event.registerLayerDefinition(PonyModelSlim.LAYER_LOCATION, PonyModelSlim::createBodyLayer); event.registerLayerDefinition(PegasusModel.LAYER_LOCATION, PegasusModel::createBodyLayer); event.registerLayerDefinition(UnicornModel.LAYER_LOCATION, UnicornModel::createBodyLayer); event.registerLayerDefinition(InnerPonyArmorModel.LAYER_LOCATION, InnerPonyArmorModel::createBodyLayer); event.registerLayerDefinition(OuterPonyArmorModel.LAYER_LOCATION, OuterPonyArmorModel::createBodyLayer); } @SubscribeEvent public static void onRegisterRenderers(final EntityRenderersEvent.RegisterRenderers event) { event.registerEntityRenderer(EntityType.PLAYER, PonyPlayerWrapperRenderer::new); System.out.println("onRegisterRenderers end"); } } Method onRegisterRenderers() is called and I can see it being logged. But when I enter the world, my PonyWrapperRenderer render() method doesn't ever seem to be called. I also tried to put my renderer to EntityRenderDispatcher's playerRenderers via reflection: @Mod.EventBusSubscriber(modid = MODID, bus = MOD, value = CLIENT) public class ClientRenderers { @SubscribeEvent public static void onRegisterLayerDefinitions(final EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(PonyModel.LAYER_LOCATION, PonyModel::createBodyLayer); event.registerLayerDefinition(PonyModelSlim.LAYER_LOCATION, PonyModelSlim::createBodyLayer); event.registerLayerDefinition(PegasusModel.LAYER_LOCATION, PegasusModel::createBodyLayer); event.registerLayerDefinition(UnicornModel.LAYER_LOCATION, UnicornModel::createBodyLayer); event.registerLayerDefinition(InnerPonyArmorModel.LAYER_LOCATION, InnerPonyArmorModel::createBodyLayer); event.registerLayerDefinition(OuterPonyArmorModel.LAYER_LOCATION, OuterPonyArmorModel::createBodyLayer); } @SubscribeEvent public static void onClientSetup(final FMLClientSetupEvent event) { event.enqueueWork(() -> { try { final EntityRenderDispatcher dispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); final Field renderersField = getEntityRenderDispatcherField("playerRenderers"); final Field itemInHandRenderer = getEntityRenderDispatcherField("itemInHandRenderer"); @SuppressWarnings("unchecked") final Map<String, EntityRenderer<? extends Player>> playerRenderers = (Map<String, EntityRenderer<? extends Player>>)renderersField.get(dispatcher); final PonyPlayerWrapperRenderer renderer = new PonyPlayerWrapperRenderer( new EntityRendererProvider.Context( dispatcher, Minecraft.getInstance().getItemRenderer(), Minecraft.getInstance().getBlockRenderer(), (ItemInHandRenderer)itemInHandRenderer.get(dispatcher), Minecraft.getInstance().getResourceManager(), Minecraft.getInstance().getEntityModels(), Minecraft.getInstance().font ) ); playerRenderers.put("default", renderer); playerRenderers.put("slim", renderer); System.out.println("Player renderers replaced"); } catch (final Exception e) { throw new RuntimeException("Failed to replace player renderers", e); } }); } private static Field getEntityRenderDispatcherField(final String fieldName) throws NoSuchFieldException { final Field field = EntityRenderDispatcher.class.getDeclaredField(fieldName); field.setAccessible(true); return field; } } But I receive the error before Minecraft Client appears (RuntimeException: Failed to replace player renderers - from ClientRenderers onClientSetup() method - and its cause below): java.lang.IllegalArgumentException: No model for layer anotherlittlepony:earth_pony#main at net.minecraft.client.model.geom.EntityModelSet.bakeLayer(EntityModelSet.java:18) ~[forge-1.20.1-47.4.0_mapped_official_1.20.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.client.renderer.entity.EntityRendererProvider$Context.bakeLayer(EntityRendererProvider.java:69) ~[forge-1.20.1-47.4.0_mapped_official_1.20.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} at com.thuggeelya.anotherlittlepony.client.renderer.pony.PonyPlayerRenderer.<init>(PonyPlayerRenderer.java:32) ~[main/:?] {re:classloading} at com.thuggeelya.anotherlittlepony.client.renderer.pony.PonyPlayerWrapperRenderer.<init>(PonyPlayerWrapperRenderer.java:24) ~[main/:?] {re:classloading} at com.thuggeelya.anotherlittlepony.client.renderer.ClientRenderers.lambda$onClientSetup$0(ClientRenderers.java:79) ~[main/:?] {re:classloading} ... 33 more Problem appears when EntityRendererProvider context tries to bakeLayer with my model layer location: new PonyModel(context.bakeLayer(PonyModel.LAYER_LOCATION)); // PonyPlayerRenderer.java:32 public class PonyModel extends PlayerModel<AbstractClientPlayer> { // the model class itself public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation( ResourceLocation.fromNamespaceAndPath(MODID, "earth_pony"), "main" ); public PonyModel(final ModelPart root) { super(root, false); } public static LayerDefinition createBodyLayer() { // some CubeListBuilder stuff for model appearance } } Textures PNGs are placed at: resources/assets/[my mod id]/textures/entity. My forge version is 1.20.1. Would appreciate any help.
    • Well, a bit more information about what you're trying to do would be helpful. e.g. why you're trying to use "INVOKE_ASSIGN" instead of "INVOKE". "INVOKE_ASSIGN" calls your code after the "target" is called and its value is stored, if applicable. "INVOKE" calls your code before the target is called. "target" expects a fully qualified name, as per the SpongePowered docs, if that name is going to be remapped (which it will be if your injecting into Minecraft itself and not another mod). For more information on fully qualified names versus canonical names, see the Java specifications. Here's an example of a working "@At" from my own code that targets the "getClosestsVulnerablePlayerToEntity" call inside a mob's logic: @At(value = "INVOKE_ASSIGN", target = "net.minecraft.world.World.getClosestVulnerablePlayerToEntity(Lnet/minecraft/entity/Entity;D)Lnet/minecraft/entity/player/EntityPlayer;") Hope this helps!
    • Ran it one more time just to check, and there's no errors this time on the log??? Log : https://mclo.gs/LnuaAiu I tried allocating more memory to the modpack, around 8000MB and it's still the same; stopping at "LOAD_REGISTRIES". Are some of the mods clashing, maybe? I have no clue what to do LOL
    • Tried removing some biome generation mods and test ran it again, but it's still the same; still not responding as soon as it gets to "LOAD_REGISTRIES". This time with more errors though. Log : https://mclo.gs/uygZzD8 Is there too little memory allocated to the modpack maybe? Can someone help please.    (T.T)💔
    • This is sad. Over 3300 people have checked the thread and no one is able to help or give any ideas :(.
  • Topics

×
×
  • Create New...

Important Information

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