Jump to content

Recommended Posts

Posted

Hi Everyone,

 

I have figured out how to change the Player model and how to update it dynamically so that when a player changes his/her model other players see the change occur also. I now want to change my custom entities model (this entity is not the player) to simulate a player - entity swap.

 

Basically I want to swap the player with the entity, so the player becomes the entity and the entity becomes the player (where each stores the others stats, has the others model, and everything that the other had before the swap occurred. I want this to occur on the command of the player and I want it reversible). I have a pretty good idea how to do the command part (have that mostly figured out since I can change the players model to the model of the Entity I want) but I have no idea how to change the model of my custom entity. Anyone have any ideas how to accomplish this?

 

The Entity I want to change the model for (so that its model is changed to a model of Steve) is a custom entity that the player "finds" using the following method inside my WorldHelper class.

 

 

public static Entity getMob(World world, EntityPlayer player) {
	PlayerIEEP pieep = PlayerIEEP.get(player);
	for (Object object : world.getLoadedEntityList()) {
		if (object instanceof EntityCustom) {
			EntityCustomentity = (EntityCustom) object;
			long uuidMost = pieep .getEntityCustomNBTFromSlot(ppp.getSpawnedSlot()).getLong("UUIDMost");
			long uuidLeast =pieep .getEntityCustomNBTFromSlot(ppp.getSpawnedSlot()).getLong("UUIDLeast");
			if (entity.getUniqueID().getMostSignificantBits() == uuidMost && entity.getUniqueID().getLeastSignificantBits() == uuidLeast) {
				System.out.println("Found Entity: "+entity);
				return entity;
			}
		}
	}
	System.out.println("DID NOT FIND ENTITY: Entity is Null");
	return null;
}

 

 

its model is registered in my ClientProxy class in the following way

 

 

public void registerRenderInformation(){
addCustomEntityRenderer(EntityCustom.class, new ModelCustom(), "Custom.png", 0.4f);
}

public void addCustomEntityRenderer(Class<? extends EntityCustomType> entityClass, ModelBase model, String textureFileName, float shadowRadius ){
	RenderingRegistry.registerEntityRenderingHandler(entityClass, new RenderCustomType(model, textureFileName, shadowRadius));

	int entityId = EntityCustomRegistry.getentityID(entityClass);
	PlayerRenderingRegistry.addRenderer(entityId , new EntityCustomAsPlayer(model, textureFileName, shadowRadius));
}

 

 

and here is my RenderCustomType class Note* EntityCustomRegistry is a class that contains a hash map that maps my entities names to ids and has a custom collection of such methods

 

 

@SideOnly(Side.CLIENT)
public class RenderCustomType extends RenderLiving // if I extend RendererLivingEntity the Exp bar always renders and we don't want this
{
private ResourceLocation texture;


public RenderCustomType(ModelBase model, String textureName, float shadowRadius)
{
	super(model, shadowRadius);
	this.texture = new ResourceLocation("custommod:textures/mob/" + textureName);

}

public void drawExpBar(EntityLiving entityLiving, double d, double d1, double d2, float unused, float f1) {
	float f2 = 1.6F;
	float f3 = 0.01666667F * f2;
	if ((float) entityLiving
			.getDistanceToEntity(renderManager.livingPlayer) < 28F
			&& Minecraft.isGuiEnabled()) {
		GL11.glPushMatrix();
		GL11.glTranslatef((float) d + 0.0F, (float) d1 + 1.1F, (float) d2);
		GL11.glNormal3f(0.0F, 1.0F, 0.0F);
		GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
		GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
		GL11.glScalef(-f3, -f3, f3);
		GL11.glDisable(2896 /* GL_LIGHTING */);
		GL11.glDepthMask(false);
		GL11.glDisable(2929 /* GL_DEPTH_TEST */);
		GL11.glEnable(3042 /* GL_BLEND */);
		GL11.glBlendFunc(770, 771);
		Tessellator tessellator = Tessellator.instance;
		byte byte0 = -20;
		GL11.glDisable(3553 /* GL_TEXTURE_2D */);
		tessellator.startDrawingQuads();
		float f5 = 5;
		float f6 = 1;
		if (f5 >= f6)
			f5 = 56;
		float f8 = 50F * (f5 / f6);
		tessellator.setColorRGBA_F(0.0039F, 0.03137F, 0.4196F, 1.0F);
		tessellator.addVertex(-25F + f8, -7 + byte0, 0.0D);
		tessellator.addVertex(-25F + f8, -6 + byte0, 0.0D);
		tessellator.addVertex(25D, -6 + byte0, 0.0D);
		tessellator.addVertex(25D, -7 + byte0, 0.0D);
		tessellator.setColorRGBA_F(0.0F, 0.8901F, 0.8901F, 1.0F);
		tessellator.addVertex(-25D, -7 + byte0, 0.0D);
		tessellator.addVertex(-25D, -6 + byte0, 0.0D);
		tessellator.addVertex(f8 - 25F, -6 + byte0, 0.0D);
		tessellator.addVertex(f8 - 25F, -7 + byte0, 0.0D);
		tessellator.draw();
		GL11.glEnable(3553 /* GL_TEXTURE_2D */);
		GL11.glEnable(2929 /* GL_DEPTH_TEST */);
		GL11.glDepthMask(true);
		GL11.glEnable(2896 /* GL_LIGHTING */);
		GL11.glDisable(3042 /* GL_BLEND */);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glPopMatrix();
	}
}



/**
 * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
 * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
 * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
 * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
 */
public void doRender(Entity entity, double x, double y, double z, float par8, float par9){
	super.doRender(entity, x, y, z, par8, par9);
		}

/**
 * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
 */
protected ResourceLocation getEntityTexture(Entity entity){
	return this.texture;
}
}

 

 

Posted

Make your own (another) renderer which uses multiple models,

and substitute alternative model into the RenderLivingEntity#mainModel, It is protected field.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

I already have a custom renderer, My issue is that the constructor is called once and thus sets the model and the texture. I need to be able to somehow change these to be whatever I want after it has already been set. I dont know how to do that. How do you change a private field, I tried using reflection in the past but I dont really get how to use it properly.

@SideOnly(Side.CLIENT)
public class RenderCustomType extends RenderLiving // if I extend RendererLivingEntity the Exp bar always renders and we don't want this
{
private ResourceLocation texture;


public RenderCustomType(ModelBase model, String textureName, float shadowRadius)
{
	super(model, shadowRadius);
	this.texture = new ResourceLocation("custommod:textures/mob/" + textureName);

}

public void drawExpBar(EntityLiving entityLiving, double d, double d1, double d2, float unused, float f1) {
	float f2 = 1.6F;
	float f3 = 0.01666667F * f2;
	if ((float) entityLiving
			.getDistanceToEntity(renderManager.livingPlayer) < 28F
			&& Minecraft.isGuiEnabled()) {
		GL11.glPushMatrix();
		GL11.glTranslatef((float) d + 0.0F, (float) d1 + 1.1F, (float) d2);
		GL11.glNormal3f(0.0F, 1.0F, 0.0F);
		GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
		GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
		GL11.glScalef(-f3, -f3, f3);
		GL11.glDisable(2896 /* GL_LIGHTING */);
		GL11.glDepthMask(false);
		GL11.glDisable(2929 /* GL_DEPTH_TEST */);
		GL11.glEnable(3042 /* GL_BLEND */);
		GL11.glBlendFunc(770, 771);
		Tessellator tessellator = Tessellator.instance;
		byte byte0 = -20;
		GL11.glDisable(3553 /* GL_TEXTURE_2D */);
		tessellator.startDrawingQuads();
		float f5 = 5;
		float f6 = 1;
		if (f5 >= f6)
			f5 = 56;
		float f8 = 50F * (f5 / f6);
		tessellator.setColorRGBA_F(0.0039F, 0.03137F, 0.4196F, 1.0F);
		tessellator.addVertex(-25F + f8, -7 + byte0, 0.0D);
		tessellator.addVertex(-25F + f8, -6 + byte0, 0.0D);
		tessellator.addVertex(25D, -6 + byte0, 0.0D);
		tessellator.addVertex(25D, -7 + byte0, 0.0D);
		tessellator.setColorRGBA_F(0.0F, 0.8901F, 0.8901F, 1.0F);
		tessellator.addVertex(-25D, -7 + byte0, 0.0D);
		tessellator.addVertex(-25D, -6 + byte0, 0.0D);
		tessellator.addVertex(f8 - 25F, -6 + byte0, 0.0D);
		tessellator.addVertex(f8 - 25F, -7 + byte0, 0.0D);
		tessellator.draw();
		GL11.glEnable(3553 /* GL_TEXTURE_2D */);
		GL11.glEnable(2929 /* GL_DEPTH_TEST */);
		GL11.glDepthMask(true);
		GL11.glEnable(2896 /* GL_LIGHTING */);
		GL11.glDisable(3042 /* GL_BLEND */);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glPopMatrix();
	}
}



/**
 * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
 * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
 * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
 * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
 */
public void doRender(Entity entity, double x, double y, double z, float par8, float par9){
	super.doRender(entity, x, y, z, par8, par9);
		}

/**
 * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
 */
protected ResourceLocation getEntityTexture(Entity entity){
	return this.texture;
}
}

Posted

You can change it on doRender, Vanilla bat also do this.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Models are entirely dynamic. I mean that it is really just a hook for the the render calls. So you can do anything you want there. In many of my models I have alternate models that I render based on fields in the entity. For example, I have an eagle that has wings when flying but not when perched, or I have an elephant that has a multi-part trunk when adult but a one-piece trunk when a child.

 

So if you want to swap with player model, just copy the biped model stuff and put that also into your custom entity model. Then in the render function just render the one that you need at the time.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Jabelar I see what you mean, although my mod has quite a few models it would be pretty tedious to have to include the model of the player in each one, I think I need a better way.

 

Abastro - thanks for the tip ill look at the bat class

Posted

Would there be a way to change the model from inside my custom Entities class. For example if my custom mob had some superclass like EntitySuperclass could I do something inside this Entity class of the sort (psuedo code) ->

 

if(this.isInParty && this.hasOwnerChangedModel== true) {Change the model to be a ModelCreeper lets say}

 

where all of the entities that extend this class will have the ability to change their model to be a creeper if the player changes their model.

 

My entities all extend a super class and I want all of my custom mobs that extend this class to have the ability to change their model when the player calls my changeModel method so that when the player becomes the mob that is part of his party then the mob can become the player to simulate player the player swap functionality i mentioned earlier.

Posted

You can use models and ResourceLocations as Fields as wel. That way you can easly switch between different textures/models.

 

Im not really sure what you mean since the constructor is called only once which sets the model with its registered renderer, I have no idea how to then change the existing model once it has already been set. I can put the fields in like this but changing them wont do anything since they aren't used in the actual rendering.

 

        public ResourceLocation texture;
public ModelBase model;

public RenderCustomType(ModelBase model, String textureName, float shadowRadius)
{
	super(model, shadowRadius);
	this.model = model;
	this.texture = new ResourceLocation("custommod:textures/mob/" + textureName);

}

Posted

the constructor is called only once which sets the model with its registered renderer, I have no idea how to then change the existing model once it has already been set.

 

Thorny, seriously?

 

#doRender is called everytime, on beginning of rendering of given entity. It doesn't matter what you did before, it matters what you do inside.

You have entity parameter inside, you can use it to e.g entity.getModelName() which would e.g return String which you could then use in HashMap.get(StringYouGot) -> and return some model. Then you simply do this.model = modelYouGot.

All that in doRender, Map of models should be kept as static field initialized on mod startup.

 

Bam, your models are per-entity, same can be done for textures or whatever, Just keep in mind that you have to do proper casting.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Haha I guess I had a brain fart :P ive been coding for a good number of hours guess I need a break but ya that totally makes sense I should have come to that myself thanks everybody

Posted

Thanks to Ernio I have managed to get this solved, Basically  I use a data watcher to get the owner's name of the entity and inside my doRender method I get the model from the owners string. This is all triggered by calling the setMorphedIntoPlayer method that is located inside my entity class when the player morphs. However I have a problem with the texture, the pink/black missing texture texture is overlaid onto the modelBiped rather than the players texture. Anyone know why? I suspect it is because when in my development environment I am in offline mode and the player doesn't have a skin but I am not sure how to test this.

 


@SideOnly(Side.CLIENT)
public class RenderCustomType extends RenderLiving // if I extend RendererLivingEntity the Exp bar always renders and we don't want this
{
private ModelBase playerModel = new ModelBiped();

private ModelBase consistentModel;
private ResourceLocation consistentTexture;

private ResourceLocation currentTexture;


public RenderCustomType(ModelBase model, String textureName, float shadowRadius)
{
	super(model, shadowRadius);
	this.consistentTexture = new ResourceLocation("custommod:textures/mob/" + textureName);
	this.consistentModel = model;
}

public void drawExpBar(EntityLiving entityLiving, double d, double d1, double d2, float unused, float f1)
{
	float f2 = 1.6F;
	float f3 = 0.01666667F * f2;
	if ((float) entityLiving
			.getDistanceToEntity(renderManager.livingPlayer) < 28F
			&& Minecraft.isGuiEnabled()) {
		GL11.glPushMatrix();
		GL11.glTranslatef((float) d + 0.0F, (float) d1 + 1.1F, (float) d2);
		GL11.glNormal3f(0.0F, 1.0F, 0.0F);
		GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
		GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
		GL11.glScalef(-f3, -f3, f3);
		GL11.glDisable(2896 /* GL_LIGHTING */);
		GL11.glDepthMask(false);
		GL11.glDisable(2929 /* GL_DEPTH_TEST */);
		GL11.glEnable(3042 /* GL_BLEND */);
		GL11.glBlendFunc(770, 771);
		Tessellator tessellator = Tessellator.instance;
		byte byte0 = -20;
		GL11.glDisable(3553 /* GL_TEXTURE_2D */);
		tessellator.startDrawingQuads();
		float f5 = 5;
		float f6 = 1;
		if (f5 >= f6)
			f5 = 56;
		float f8 = 50F * (f5 / f6);
		tessellator.setColorRGBA_F(0.0039F, 0.03137F, 0.4196F, 1.0F);
		tessellator.addVertex(-25F + f8, -7 + byte0, 0.0D);
		tessellator.addVertex(-25F + f8, -6 + byte0, 0.0D);
		tessellator.addVertex(25D, -6 + byte0, 0.0D);
		tessellator.addVertex(25D, -7 + byte0, 0.0D);
		tessellator.setColorRGBA_F(0.0F, 0.8901F, 0.8901F, 1.0F);
		tessellator.addVertex(-25D, -7 + byte0, 0.0D);
		tessellator.addVertex(-25D, -6 + byte0, 0.0D);
		tessellator.addVertex(f8 - 25F, -6 + byte0, 0.0D);
		tessellator.addVertex(f8 - 25F, -7 + byte0, 0.0D);
		tessellator.draw();
		GL11.glEnable(3553 /* GL_TEXTURE_2D */);
		GL11.glEnable(2929 /* GL_DEPTH_TEST */);
		GL11.glDepthMask(true);
		GL11.glEnable(2896 /* GL_LIGHTING */);
		GL11.glDisable(3042 /* GL_BLEND */);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glPopMatrix();
	}
}
@Override
public void doRender(Entity entity, double x, double y, double z, float f, float F)
{
	if (entity instanceof EntityCustomType)
	{
		EntityCustomType ent = (EntityCustomType) entity;

		String playerName = ent.getIsMorphedToPlayer();
		if (playerName != null && !playerName.equals(""))
		{
			this.currentTexture = AbstractClientPlayer.getLocationSkin(playerName);
			this.mainModel = this.playerModel;
		}
		else
		{
			this.currentTexture = this.consistentTexture;
			this.mainModel = this.consistentModel;
		}
	}

	super.doRender(entity, x, y, z, f, F);
}

 

in my Entity class

public String getIsMorphedToPlayer()
{
	return this.dataWatcher.getWatchableObjectString(MORPHED_PLAYER_NAME);
}

public void setMorphedIntoPlayer(boolean shouldBeMorphed)
{
	if (shouldBeMorphed){
		this.dataWatcher.updateObject(MORPHED_PLAYER_NAME, this.getPlayerName());
	}
	else {
		this.dataWatcher.updateObject(MORPHED_PLAYER_NAME, "");
	}
}

Posted

You posted only part of the render code, please post the full RenderCustomType code.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.