Jump to content

How can I change the player model


BananaBlighter

Recommended Posts

So I'm making a parkour mod, with animations and all, similar to how it looks in mods like Animated Player or Mo' Bends. How would I change the player model to look like that, so that it has elbows and knees?

 

The only way I can think of doing such a thing would be to make the player invisible and replace it with another entity when in 3rd person view. There has to be a better way than this for sure.

Link to comment
Share on other sites

@SubscribeEvent to RenderPlayerEvent. Cancel rendering. Render your own (as in make new model and Render it).

 

Rendering is literally impossible to be compatible with anything so unless you provide API for others to use, you mod's rendering can't really be compatible with anything.

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

Link to comment
Share on other sites

Don't subscribe to

RenderPlayerEvent

itself, subscribe to

RenderPlayerEvent.Pre

. This is the actual event you want and the only sub-event of

RenderPlayerEvent

that can be cancelled.

 

Attempting to cancel a non-cancellable event will throw an

IllegalArgumentException

.

 

I suspect you didn't register your event handler, so your method was never being called.

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.

Link to comment
Share on other sites

Yes, that's the correct bus.

 

If it seems like it's not working, put a breakpoint in your event handler method and ensure it's actually being called.

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.

Link to comment
Share on other sites

Hmmm...I'm still not convinced this is the best way to do it.

 

Sorry I'm rather new to modding, but if I did stop the normal player model rendering, how would I replace it with my own model? Would making a whole new model mean I have to redo every animation? What about the skins and armour?

 

I also forgot to mention that preferably the model would only change when a certain boolean variable is true (that would make it more compatible too, wouldn't it?). How would I do this then?

 

If I only I could look at the Mo' Bends mod or something to see how it was done over there...

Link to comment
Share on other sites

1. Will this be client-only (visual) mod?

 

2. Will your boolean be per-player or global?

 

3.

Hmmm...I'm still not convinced this is the best way to do it.

I am convincing you. Feel convinced yet? :P

 

While for normal entities you can easily replace their Render class, for players it doesn't seem to be working in the same way (at least it didn't last time I replaced renderer in registry).

Anyway - no matter what - if you are going to apply changes as big as joints and some special animations - you will need to store additional per-player data (e.g to hold bend level of joints).

As to your questions about armours and such - those are called layers and again - if you plan on tounching stuff that pretty much builds whole base of player's model (because joints and all) - you can forget about using ANY part (aside from general ideas) of vanilla code.

 

You have to make your own models and render them on your own. Then recreate layers (for armours and such) that will also bend with said joints. So basically rewrite of whole vanilla animations.

 

 

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

Link to comment
Share on other sites

2) Per player. All I've done for my mod so far is make it so that as long as you hold down the middle click button with an empty hand you enter 'high profile mode' and the camera switches to 3rd person view. In high profile mode, when you walk forward the player sprints instead, entering 'free run mode'. I've also coded the new model and added a few little functionalities like making the scroll wheel ineffective while middle click is held down. What I want to do is replace the player model when in high profile.

 

1) No, it's not just visual like the Mo' Bends mod. It's a parkour mod taking inspiration from Assassin's Creed, so when you are in 'free run mode' you can do all sorts of things like climbing up walls. In fact all the controls sort of change in 'high profile mode'. When free running you're not meant to be able to jump, and pressing space will cause you to dive roll instead, while holding it as you run towards a wall will initiate a climb. With the middle click it was easy to change what it does (you can still pick block but that happens if you let go in under 20 ticks) because there is the cancelable MouseEvent. However I do not know of any keyboard equivalent.

 

3) No I don't think I am convinced. Does this mean that I'll have to make a new animation for even simple things like eating? If I can get the model to only change when the player is high profile, then I guess I wouldn't have to do animations like walking, and technically I could prevent the player from doing things like eating and sneaking.

 

Also, for animation, do I have to set the angles frame by frame for every tick or can I smoothly move a part from one point to another using maths?

Link to comment
Share on other sites

In order:

2.1. To store per-player data you need @Capability

http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

Example:

https://github.com/MinecraftForge/MinecraftForge/blob/1.9/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java

And recent posts on this forum (you could lookup my post history).

 

2.2. Input events are fired on client. What you need to do is send "state" packet to server when input happens and from server's handler change server side state.

 

1.1. I will just write "Smart Moving" (mod).

 

1.2. Again - input happens on client, server received packets and server does shit (also updates other clients with your actions - again, with packets).

 

1.3. For keyboard events look again. Also depending on what exacly you want you might want to use ClientTickEvent and check directly LWJGL Keyboard class (in this case, probably client tick is the way, but check out KeyBinding class/event) Examples can be found even in GuiScreen#handleInput() as well as other more fundamental classes.

 

3. If your animation/model changes only when you go into high profile mode then you can dynamically swap renders to be vanilla or yours when you need it. But if it will be possible to eat during your "special run" - then yeah, you have to animate on your own most likely.

 

4. ("Also, for animation..."). Well, not you dive into client/server data and interpolation.

First of all - there is tick and renderTick (FPS) - usually called "partialTick" which is float representing at what position between this tick and next tick current render Frame is placed. While data will always happen on logical tick, partialTicks allow you to make interpolations between previous and next data change, giving you smooth transition. Also note - if you want all clients to see same animation you will need that data to by synced (logical data, not interpolation data because that is per-client and different on every client - FPS).

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

Link to comment
Share on other sites

As I said, I'm new to modding, with this being my first 'real' mod in the sense that I didn't just copy a tutorial on how to add new items or something. I don't know much about packet handling or rendering for that matter. If you could give me some good tutorials that'd be great.

 

So far, to make the model I had copied this tutorial: http://jabelarminecraft.blogspot.co.uk/p/introduction-first-of-all-to-understand.html, but I couldn't really gather from it how I'd actually render the model instead of the existing player one.

 

2.1. To store player variables like whether they were in high or low profile, I used IExtendedEntityProperties. Not sure if it was a good idea but for what I've done so far it works fine.

 

1.1. Oh no I was talking about a different mod, the Mo' Bends mod, look it up. I don't think Smart Moving actually changes the model, only the animations iirc.

 

1.3. I see keyboard events but they are not cancelable. I tried checking each tick for whether the player had space pressed and was high profile and then setting the key bind state to false, and to my surprise it actually kinda works. Only problem is that every so often (1/20 times I enter high profile) the player will still jump when space is initially pressed but not continue when held.

 

3. I'm just not sure exactly how I would 'swap renders'.

 

4. The tutorial I linked above has the angles for each body part stored in an array, with columns being each part and rows being each frame. I was wondering if there was an easier way to do this.

Link to comment
Share on other sites

Here (http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2216984-solved-dorender-custom-player-model) it says you can do:

RenderingRegistry.registerEntityRenderingHandler(EntityPlayer.class, new CustomRender());

So can I simply call this at any point, say in a tick event if the player is high profile?

Link to comment
Share on other sites

Here (http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2216984-solved-dorender-custom-player-model) it says you can do:

RenderingRegistry.registerEntityRenderingHandler(EntityPlayer.class, new CustomRender());

So can I simply call this at any point, say in a tick event if the player is high profile?

 

This is exactly what I mentioned earlier about EntityPlayers working differently than other Entities.

As of 1.9 (I think) RenderRegistry#registerEntityRenderingHandler is deprecated in favor of factory system = RenderRegistry#registerEntityRenderingHandler (different params).

 

In pre 1.9 renders were held directly in map and could actually be replaced outside mod's init phases.

As of now - render classes are produced by factory classes which can only be registered in preInit and then those factory classes will produce render class internally (on init).

 

Said that - replacing Player's render class was still not working due to the fact that apparently player was rendered differently - what I am saying here that no matter if you are on old or new version - what you mentioned will (should) not work, unless there was change I don't know about.

 

Now let's just say that whole approach you mentioned is SIMPLY RETARDED!

RnderPlayerEvent is hooked DIRECTLY at the beggining (Pre) and end (Post) of Render#doRender() method. Replacing class in registry is literally equivalent to cancelling said event and rendering on your own.

 

EDIT:

While Render event gives you a bit of compatibility (since you can decide when you render or not), replacing render class in registry effectively kicks out all other rendering mods. Aside from that - you MOST CERTAINLY don't want to replace render on demand (one time this and one time other) because render object is generated for all entities of type and you would have to handle replacement for all currently spawned players.

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

Link to comment
Share on other sites

Well I do really want the model to change on demand, are you sure this is not feasible?

 

If the approach I mentioned doesn't work, how do I do it then? If I get the RenderPlayerEvent, I cancel it but then what do do exactly? How does the doRender() method work?

 

Also, for some reason the event isn't working for me. I just wrote:

@SubscribeEvent
public void onPlayerRender(RenderPlayerEvent.Pre event)
{
	System.out.println("Player rendered");
}

 

I'm sure I've also registered the class to the correct bus. I can't see the message appear however. When I tried canceling the event th eplayer did not turn invisible (as I assume would happen).

 

As I said, I'm pretty much clueless on what I am trying to do. I have never made any real mods before.

Link to comment
Share on other sites

Oh sorry, version 1.8, forge 11.14.1.1334. Though tbh I should update now.

 

Here's where I register the event handler:

 

@EventHandler
public void init(FMLInitializationEvent event)
{
	ParkourEventHandler eventHandler = new ParkourEventHandler();
	MinecraftForge.EVENT_BUS.register(eventHandler);
	FMLCommonHandler.instance().bus().register(eventHandler);
}

 

It's in the main mod class, which is how the tutorial I followed said it should be done. There are two other events in that class, they both work, but the RenderPlayerEvent doesn't.

Link to comment
Share on other sites

There was short time after Forge was being upgraded to 1.8 where RenderPlayerEvent was NOT fired (because it was WIP).

 

I am not sure if your version is in scope of said time, but:

1. You can find out in changelog - look for log saying that RenderPlayerEvent was reactivated.

2. You should update to 1.9+.

 

Aside from that - why the hell are you registering same event class for 2 buses? Separate your FML and Forge events in 2 classes - otherwise it's waste of resources (okay, well - micro optimization).

 

Next on plate: As of 1.9 (I think, maybe earlier) FML and Forge buses were merged into one - so basically no matter what you call - its same event bus - thus call it only once. Said that - update to 1.9+ and use one bus for all events (not mentioning decorator ones).

  • Like 1

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

Link to comment
Share on other sites

  • 3 years later...
10 minutes ago, Forfx said:

Soo what does the finished code look like?

pls I am a Noob when it comes to coding in Java. 

This thread is 4 YEARS OLD, don't post on old threads, make your own, and this thread is about a version that's no longer supported on this forum.

  • Haha 1

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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