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.

 

  Reveal hidden contents

 

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

 

  Reveal hidden contents

 

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

 

  Reveal hidden contents

 

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
  On 5/29/2015 at 6:02 AM, N247S said:

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
  On 5/29/2015 at 9:32 PM, Thornack said:

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.

  Quote

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Looking for unbeatable savings on Temu in 2025? Our exclusive Temu code [ald244107] is your key to unlocking a $100 OFF discount, plus much more! This verified promo code works for both new and existing customers, giving you up to 50% off your next order and even bigger savings on clearance items. With Temu coupon code [ald244107], you'll get a flat $100 discount on top of existing sales. First-time users can enjoy an extra 100% off select items, while returning shoppers automatically qualify for the $100 OFF when applying the code at checkout. Imagine saving up to 90% on your favorite products across the USA, Canada, UK, and many other countries! 🔥 Temu Coupon Highlights with Code [ald244107]:  * Temu New User Offer: Use ald244107 for 50% off your first order + $100 OFF.  * Temu Existing Customer Promo: Apply ald244107 to get an instant $100 OFF.  * Global Reach: Valid in the USA, UK, Canada, Germany, France, Japan, Chile, Colombia, Malaysia, Mexico, South Korea, Philippines, Saudi Arabia, Qatar, Pakistan, and more.  * Top 2025 Deal: Secure $200 OFF plus 100% bonus discounts with ald244107. Maximize Your Savings: Top Temu Deals for 2025 (Code: ald244107)  * ✅ Temu Memorial Day Sale: Save $100 with ald244107  * ✅ Temu First Order Special: Use ald244107 for 50% + $100 OFF  * ✅ Temu USA Exclusive: Get $100 off instantly with ald244107  * ✅ International Temu Codes: ald244107 works in Japan, Germany, Chile, and many others.  * ✅ Temu Reddit Discount: Enjoy $100 OFF for both new and old users.  * ✅ Temu Coupon Bundle 2025: Combine $100 OFF with up to 50% slash deals.  * ✅ 100% OFF Free Gift Code: Use ald244107 – no invitation needed!  * ✅ Temu Sign-Up Bonus: Instantly get a welcome $100 OFF.  * ✅ Free Temu Code for New Users: Apply ald244107 – no referral required.  * ✅ Temu Clearance Codes 2025: Use ald244107 for 85–100% discounts. This Temu code [ald244107] is more than just a discount; it's your ticket to free shipping, exclusive first-order deals, and stackable coupon bundles across electronics, fashion, home goods, and beauty products. You can truly unlock up to 90% OFF plus an additional $100 OFF on qualified orders. 💡 Pro Tip: Don't forget to apply ald244107 during checkout on the Temu app or website to activate your instant $100 discount, even if you’re a returning customer! Temu $100 OFF Code by Country (All Use ald244107):  * 🇺🇸 Temu USA – ald244107  * 🇯🇵 Temu Japan – ald244107  * 🇲🇽 Temu Mexico – ald244107  * 🇨🇱 Temu Chile – ald244107  * 🇨🇴 Temu Colombia – ald244107  * 🇲🇾 Temu Malaysia – ald244107  * 🇵🇭 Temu Philippines – ald244107  * 🇰🇷 Temu Korea – ald244107  * 🇵🇰 Temu Pakistan – ald244107  * 🇫🇮 Temu Finland – ald244107  * 🇸🇦 Temu Saudi Arabia – ald244107  * 🇶🇦 Temu Qatar – ald244107  * 🇫🇷 Temu France – ald244107  * 🇩🇪 Temu Germany – ald244107 Real Shoppers, Real Savings: User Reviews We love hearing about your experiences! Here’s what some happy shoppers are saying about using the Temu code [ald244107]:  * Alice W., USA ⭐️⭐️⭐️⭐️⭐️ (5/5) "Great experience! Temu's promo code {ald244107} saved me a lot on my first order. Highly recommend this offer!"  * James T., UK ⭐️⭐️⭐️⭐️ (4/5) "Very happy with the quality and prices on Temu. The $100 credits offer was a nice bonus using {ald244107}. Will shop again."  * Sara M., Canada ⭐️⭐️⭐️ (3/5) "Got some decent deals with the {ald244107} code, though shipping took a bit longer than expected. Overall satisfied with the credits."
    • Thank you so much! I didnt see it in the log😭😭  
    • So im completely new to modding in general, i have some experience in Behavior packs in minecraft bedrock and i would like to modify entities stats and attributes like in a behavior pack (health, damage, speed, xp drop...). The problem is that i cant find any information online on how to do that, and I have no clue on what to do and where to start. I am currently modding in 1.20.4 with IntelliJ if that helps. My final objective is to buff mobs health and damage (double it for exemple), but since there is no entity file anywhere i don't know how to change it... 😢
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
  • Topics

×
×
  • Create New...

Important Information

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