Hi, I was wondering if their was some sort of code I could use to... grow or shrink a model, completely while keeping's its scale... as the game is running... in real time... I don't think I can add any more info here than I did in the title. Well thanks for an answers I get
Oh I guess I can say that the model in this case belongs to a mob.
If I could clarify or add something, I would like the mob to grow or shrink a little at a time, like inflating or deflating a balloon.
You said you had a model. So that would mean you should have a model class. In that class there should be some render methods that are called by your renderer class. The renderer, the model, and the entity class are all associated with each other when you register the renderer for your entity in your client proxy.
So your model class should have a render method. In that method you can do the GL11 scaling mentioned above.
Note also that for mobs you need to first do a GL11 translate to get the center of the model to the ground level, and then scale, then translate back up. Otherwise when you scale bigger the feet will go into the ground and if you scale smaller the feet won't touch the ground.
also if any ones still looking at this post do they know some code that works like a clock? to start or stop something after blank seconds? I'm assuming it's ticks and am about to Google it and if that goes no were make a new post for the question but since this post seems s active today just though I'd try my luck!
For timing, it is just a matter of programming where some class has an integer field that you set to a value and then decrement every tick. When the counter goes to <= 0 then you do what you want. There are 20 ticks per second so if you want 5 seconds you'd set the field to 100.
So you just need a class that makes sense that also has a method that is called every tick. The entity classes and tile entity classes have such methods, as do items and armor. You could also potentially do it in a tick event, as long as you also can reference what you want to affect from that class.
The Meaning of Life, the Universe, and Everything.
Location:
^^^Up There^^^
Join Date:
6/11/2015
Posts:
44
Member Details
I made a tileEntity with the ability to grow right before your eyes. Perhaps add something like a variable called size and put size++ in the onUpdate function of your entity. Chances are you will need a data watcher to keep track of this. Here is a snippet of code from the tile entity renderer
I have a mod I'm making were I want Entity A to grow, Then be replaced by a small and different texture version of Entity B, the THAT entity B to grow until it was big enough that a transition to the normal sized and textured Entity B wasn't out of the question.
So first I needed to make it grow and shrink, the answer was the line of code.
[pre]GL11.glScalef(scaleX, scaleY, scaleZ);
The way it works is it takes the width, Hieght, and length of a model and multiples it.
so if:
<width> <length>
|||||| ^ ||||^
||||||h ||||h
||||||e ||||e
ight ight
normally, and then you add the code
Gl11.glScalef(2, 1, 2);
then:
[/pre]
[pre]
<width> <length>
|||||||||||| ^ ||||||||^
||||||||||||h ||||||||h
||||||||||||e ||||||||e
ight ight
(NOTE: I'm only assuming X=width, Y=height, and Z=Length. I have noe idea. I don't even know if those would be what height width and length are on my pretend cube. I'm not super good with shape)
with math I guess it's
width = 6
Height= 3
Length= 4
and the cod makes it
width, 6 * 2 =12
Height 3 * 1 = 3
length 4 * 2 = 8
[/pre]
[pre]
But it wasn't enough to have it, I had to figure out were to put it.
I learned that this code, for my purposes at least, Goes in
The Model Class of witchever mob your trying to effect:
Under the code: public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { or something like this.
and it effects the lines of code that look like. head.renderWithRotation(f5); Their could be a couple of these for on mob (and probably are) but you put the code Above the ones you want it to effect. ones above the GL11 code line will not be affected.
However for the code to work you also need this:
GL11.glPushMatrix();
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(1.0F / 7, 1.0F / 7, 1.0F / 7);
GL11.glTranslatef(0.0F, 8.0F, 0.0F);
And this below all the renderwithrotation entries:
GL11.glPopMatrix();
Not the Extra GLscale that IS what we added but I needed all this other code to get it to work too. I have no idea why or how much of it is actually required.
and using that code you can grow and shrink a mob in mincraft! however when you do that they just Poof appear that size in game. I needed them to grow gradually. Luckily purebee gave me this code that works perfectly!
It's located here: http://hastebin.com/itozasaviq.java
and basically how it works is, you place it in you Entity class and the first line of code Starts everything,
The identifier entity after EntitLivingBase doesn't be to be changed since it's just giving an ID to something, not actually trying to point out an entity class. the float MAY need to be changed. it refers to the last float in the
line of code we discuss earlier. So I had to change mine to f5
The next line creates the numbers used in the GL11 scale code.
It works such as: scalefactor is and ID used to represent a number. that number is used three times in the gl11Scallef code as [/pre]
[pre](scaleX, scaleY, scaleZ)
numbers. It is equal to 1, meaning that the model doesn't change, But it's is added to by the math function (equation?)[/pre]
(entity.ticksExisted / 100.0f)
What this means is that the game keeps tracks of how many time increments or "Ticks" have happened since the entity your trying to make grow has been alive, or in the game at least. I COULD have said every second it's been alive but that wouldn't be true because a tick happens 5 times every second. (once every .25 milliseconds? IDK) Then that number is divided by 100.
THIS 100.0f number is the only number in the whole code that makes sense to edit if sometinhgs not wrong, this number decides how fast the mob actually grows! (ok ALSO changing the + to a - in[/pre]
1 + (entity.ticksExisted / 100.0f)
Will make the mob shrink. so two things)
What's happeneing with this math function is, every Tick your mobs been in the game it adds to the number. every tick equals 1. That number is then divided by 100. the result is add (or subtracted if you want it to shrink) to that 1 outside the parenthesis that represents our scale factor or "how much bigger the mob is when we start" and since 0/100 = 0 it will be normal size when you start (not mine but that's because I did something else I will explain later) as the number grows that's added to 1 so does the monster. that's why the number 100 decides how fast the mob grows or shrinks.
SO! I could make my mob grow in real time (thanks pbee) now I needed it to stop. I was introduced to Ticks just no in Pb's code so i thought I could try to use them to keep track of the growing time that it took my ob to get to a decent height. then jebelar came by and told me I could instead just set a value, and make a line of code that decreased that value every tick so I didn't have to learn a bunch of tick logic and write a bunch of tick code. I tried that but then learned my basic Java code skills were a litttllllleee lacking.
That's when I had a terrific idea!
I didn't know how to mess with ticks or subtract values. but I DID have a working understanding of my code and realized their was ALREADY a number being affected by Ticks.
THE SCALE FACTOR NUMBER!
At that point I realized the genius of this code.
Using the scale factor number I didn't have to wait an arbitrary amount of seconds until it looked bout the same size as the normal model. I could use the scale factors numbers to decide when the change happened EXACTLY wen the model WAS THE EXACT SAME HEIGHT AS NORMAL!
and I know I was busy patting myself on the back instead of explaining what the code actually does but... HEY LEMME DO THAT! DX
any way the way I could do this was I did use the GL11 code to make my mob smaller in the model class using an if else statement.
if soemthing was set to 1 then appear smaller if not appear normal.
I was trying to learn ticks to turn that "something set to 1" to 0.
and instead of straight up ticks I used something else.
PB's code makes it so the scale factor rises or lowers every tick, the scale factor IS a number and I made a code that turns the "Something set to 1" to 0 when that reaches a certain number! the number 7, because I made it so my mob is 7 times smaller then normal when growing using the Gl11 scale code.
FULL CIRCLE!
So sorry if things got a little confusing their but That's How to make you mobs grow and shrink gradually over time
Thanks for all your help and I guess my question is answered now!
Sees yah!
[/pre]
Width and length can be in any direction as long as it is horizontal, x & z refer to the x and z axes in the game or on the model, which are fixed in place.
Rollback Post to RevisionRollBack
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
Hi, I was wondering if their was some sort of code I could use to... grow or shrink a model, completely while keeping's its scale... as the game is running... in real time... I don't think I can add any more info here than I did in the title. Well thanks for an answers I get
Oh I guess I can say that the model in this case belongs to a mob.
If I could clarify or add something, I would like the mob to grow or shrink a little at a time, like inflating or deflating a balloon.
To scale a model, use this in your render method:
If you want it to keep it's scale, scaleX, scaleY and scaleZ should have the exact same value.Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
Whats a render method, does that refer to any were in the renderMODELNAME.java or a specific code in that .java, or some were completely different.
and in case it matters the MODELNAME is chicken, Because Giants chicken is obliviously the best way to test this.
also thanks for the answer.
You said you had a model. So that would mean you should have a model class. In that class there should be some render methods that are called by your renderer class. The renderer, the model, and the entity class are all associated with each other when you register the renderer for your entity in your client proxy.
So your model class should have a render method. In that method you can do the GL11 scaling mentioned above.
Note also that for mobs you need to first do a GL11 translate to get the center of the model to the ground level, and then scale, then translate back up. Otherwise when you scale bigger the feet will go into the ground and if you scale smaller the feet won't touch the ground.
OK, I still can't get it to work, but I haven't even BEGUN to fiddle with it.
However this sounds like the mob will just BE bigger. Are their any tricks to make it like grow in front of your eyes?
You could investigate CreeperSwellAI.
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
This is not the signature you are looking for.
Banners and such things
GL11.glScalef() is the right method, it's the same one used in RenderCreeper to make the Creeper swell up.
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
This is not the signature you are looking for.
Banners and such things
Just stick this in your Render class and you'll make the model slowly grow over time. You can then fiddle with it to achieve the desired effect.
This is YOUTUBE
O_O...
(I love you soo much)
XD YES! Thanks, I HAVE A LEAD! something to go investigate! Thank you for the information!
Also COOl! thanks you
This looks perfect! I'll do what you and that cool velocarpator said and see what I can cook up
Thanks
My avatar is called an Ancyliax(An-silly-axe).
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
This is not the signature you are looking for.
Banners and such things
noted.
also if any ones still looking at this post do they know some code that works like a clock? to start or stop something after blank seconds? I'm assuming it's ticks and am about to Google it and if that goes no were make a new post for the question but since this post seems s active today just though I'd try my luck!
thanks.
For timing, it is just a matter of programming where some class has an integer field that you set to a value and then decrement every tick. When the counter goes to <= 0 then you do what you want. There are 20 ticks per second so if you want 5 seconds you'd set the field to 100.
So you just need a class that makes sense that also has a method that is called every tick. The entity classes and tile entity classes have such methods, as do items and armor. You could also potentially do it in a tick event, as long as you also can reference what you want to affect from that class.
O_O I think by complete and utter happenstance that just might be perfect...
Thank you!
Although do you have any hints on how exactly to write (parse?) this?
I've got,
Their are values being called from the Entity class, but the code takes place in the render class.
public static int Grow = 1;
public static int Growtime = 100;
first code
protected void preRenderCallback(EntityLivingBase entity)
{
if(EntityChiken.Grow == 1)
{
int sub = EntityChiken.Growtime - (entity.ticksExisted * 1);
}
if(EntityChiken.Growtime <= 0)
{
EntityChiken.Grow = 0;
}
}
{
if(EntityChiken.Grow == 0)
{
EntityChiken.Growtime = 100;
}
but I don't think sub works like I think it did, I don't even think it wasa command. So i tried this.
protected void preRenderCallback(EntityLivingBase entity)
{
if(EntityChiken.Grow == 1)
{
int amnt = EntityChiken.Growtime - (entity.ticksExisted * 1);
if(amnt <= 0)
{
EntityChiken.Grow = 0;
}
}
{
if(EntityChiken.Grow == 0)
{
EntityChiken.Growtime = 100;
but that didn't work either....
Any ideas of what could work?
(oops had to fix tht ok now the codes right.)
I made a tileEntity with the ability to grow right before your eyes. Perhaps add something like a variable called size and put size++ in the onUpdate function of your entity. Chances are you will need a data watcher to keep track of this. Here is a snippet of code from the tile entity renderer
float scale = 1.0F + entity.getPercentOfRecharge() * 2.5F;
GL11.glScalef(scale,scale,scale);
this code goes before any actuall rendering functions
AWSOME! IT WORKS! XD
Thanks SO much everyone.
Now to recap....
I have a mod I'm making were I want Entity A to grow, Then be replaced by a small and different texture version of Entity B, the THAT entity B to grow until it was big enough that a transition to the normal sized and textured Entity B wasn't out of the question.
So first I needed to make it grow and shrink, the answer was the line of code.
[pre]GL11.glScalef(scaleX, scaleY, scaleZ);
The way it works is it takes the width, Hieght, and length of a model and multiples it.
so if:
<width> <length>
|||||| ^ ||||^
||||||h ||||h
||||||e ||||e
ight ight
normally, and then you add the code
Gl11.glScalef(2, 1, 2);
then:
[/pre]
[pre]
<width> <length>
|||||||||||| ^ ||||||||^
||||||||||||h ||||||||h
||||||||||||e ||||||||e
ight ight
(NOTE: I'm only assuming X=width, Y=height, and Z=Length. I have noe idea. I don't even know if those would be what height width and length are on my pretend cube. I'm not super good with shape)
with math I guess it's
width = 6
Height= 3
Length= 4
and the cod makes it
width, 6 * 2 =12
Height 3 * 1 = 3
length 4 * 2 = 8
[/pre]
[pre]
But it wasn't enough to have it, I had to figure out were to put it.
I learned that this code, for my purposes at least, Goes in
The Model Class of witchever mob your trying to effect:
Under the code: public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { or something like this.
and it effects the lines of code that look like. head.renderWithRotation(f5); Their could be a couple of these for on mob (and probably are) but you put the code Above the ones you want it to effect. ones above the GL11 code line will not be affected.
However for the code to work you also need this:
GL11.glPushMatrix();
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(1.0F / 7, 1.0F / 7, 1.0F / 7);
GL11.glTranslatef(0.0F, 8.0F, 0.0F);
And this below all the renderwithrotation entries:
GL11.glPopMatrix();
Not the Extra GLscale that IS what we added but I needed all this other code to get it to work too. I have no idea why or how much of it is actually required.
and using that code you can grow and shrink a mob in mincraft! however when you do that they just Poof appear that size in game. I needed them to grow gradually. Luckily purebee gave me this code that works perfectly!
It's located here: http://hastebin.com/itozasaviq.java
and basically how it works is, you place it in you Entity class and the first line of code Starts everything,
The identifier entity after EntitLivingBase doesn't be to be changed since it's just giving an ID to something, not actually trying to point out an entity class. the float MAY need to be changed. it refers to the last float in the
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
line of code we discuss earlier. So I had to change mine to f5
The next line creates the numbers used in the GL11 scale code.
It works such as: scalefactor is and ID used to represent a number. that number is used three times in the gl11Scallef code as [/pre]
[pre](scaleX, scaleY, scaleZ)
numbers. It is equal to 1, meaning that the model doesn't change, But it's is added to by the math function (equation?)[/pre]
(entity.ticksExisted / 100.0f)
What this means is that the game keeps tracks of how many time increments or "Ticks" have happened since the entity your trying to make grow has been alive, or in the game at least. I COULD have said every second it's been alive but that wouldn't be true because a tick happens 5 times every second. (once every .25 milliseconds? IDK) Then that number is divided by 100.
THIS 100.0f number is the only number in the whole code that makes sense to edit if sometinhgs not wrong, this number decides how fast the mob actually grows! (ok ALSO changing the + to a - in[/pre]
1 + (entity.ticksExisted / 100.0f)
Will make the mob shrink. so two things)
What's happeneing with this math function is, every Tick your mobs been in the game it adds to the number. every tick equals 1. That number is then divided by 100. the result is add (or subtracted if you want it to shrink) to that 1 outside the parenthesis that represents our scale factor or "how much bigger the mob is when we start" and since 0/100 = 0 it will be normal size when you start (not mine but that's because I did something else I will explain later) as the number grows that's added to 1 so does the monster. that's why the number 100 decides how fast the mob grows or shrinks.
SO! I could make my mob grow in real time (thanks pbee) now I needed it to stop. I was introduced to Ticks just no in Pb's code so i thought I could try to use them to keep track of the growing time that it took my ob to get to a decent height. then jebelar came by and told me I could instead just set a value, and make a line of code that decreased that value every tick so I didn't have to learn a bunch of tick logic and write a bunch of tick code. I tried that but then learned my basic Java code skills were a litttllllleee lacking.
That's when I had a terrific idea!
I didn't know how to mess with ticks or subtract values. but I DID have a working understanding of my code and realized their was ALREADY a number being affected by Ticks.
THE SCALE FACTOR NUMBER!
At that point I realized the genius of this code.
Using the scale factor number I didn't have to wait an arbitrary amount of seconds until it looked bout the same size as the normal model. I could use the scale factors numbers to decide when the change happened EXACTLY wen the model WAS THE EXACT SAME HEIGHT AS NORMAL!
and I know I was busy patting myself on the back instead of explaining what the code actually does but... HEY LEMME DO THAT! DX
any way the way I could do this was I did use the GL11 code to make my mob smaller in the model class using an if else statement.
if soemthing was set to 1 then appear smaller if not appear normal.
I was trying to learn ticks to turn that "something set to 1" to 0.
and instead of straight up ticks I used something else.
PB's code makes it so the scale factor rises or lowers every tick, the scale factor IS a number and I made a code that turns the "Something set to 1" to 0 when that reaches a certain number! the number 7, because I made it so my mob is 7 times smaller then normal when growing using the Gl11 scale code.
FULL CIRCLE!
So sorry if things got a little confusing their but That's How to make you mobs grow and shrink gradually over time
Thanks for all your help and I guess my question is answered now!
Sees yah!
[/pre]
Width and length can be in any direction as long as it is horizontal, x & z refer to the x and z axes in the game or on the model, which are fixed in place.
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
This is not the signature you are looking for.
Banners and such things
Cool, Thanks for the info