Everything is solved! Thanks everyone!
The solutions:
Entity disappearing - I spawned the entity on both sides instead of only the server side. (derp)
Entity falling through blocks - changing from setting the positions like: posX = , posY = , etc. to entity.setLocationAndAngle(...) solved it.
Edit:
I'm having another problem - my mob is just falling through blocks and despawning a few seconds later. Any help?
Can I do it in the attackEntityWithRangedAttack method? Or it's only called one? And if it's only called once per attack, is there another place I can do it on?
Thanks.
Yes I'm planning to have the rotations as field so they would be rendered by the model, but I want the entity to attack only after the render. Is it possible?
Keep in mind that rendering is performed client side, and attacking server side. One easy way to do it is to set a timer on both sides.
When your attack method is called, instead of performing the attack, set the timer on the server side and send a health update flag.
attackMethod() {
timer = 10; // just an example
worldObj.setEntityState(this, flag); // IronGolems, for example, send (byte) 4 as the flag to begin their attack animation
// don't attack here yet!
}
@Override
@SideOnly(Side.CLIENT)
public void handleHealthUpdate(byte flag) {
if (flag == yourFlag) {
timer = 10; // now it's set client side as well, so you can use this information in your model / render classes to animate
} else {
super.handleHealthUpdate(flag);
}
}
In your entity's onUpdate() method, decrement the timer each tick and if it reaches zero, then perform the actual attack. You could also use a DataWatcher for your animation instead of sending a health update, but the result is the same.
Oh the attack method is only called done on the server side?
I got the solution, thanks
I edited the main post earlier with another error, I'd appreciate it of you'd help me
I haven't changed anything in the onUpdate method. It's falling only 1 block. So if I place it above, it will fall and then stop. It won't fall any further, but if I break the block "below" it (The block it's fallen into) it will fall again, so it would always be half block in, half block out. And it's still disappearing after a few seconds.
I'll check the server or client thing now and I'll update.
It might be the case. My entity's most bottom part is 12 high and has the y offset of -1 because I wanted it to rotate properly. Although I modeled it in Techne, and in the view there it's right on the block. I'm really not sure what's hapenning.
Until now I had the setSize in the constructor. I wasn't really sure what to put there, so I used the nubmers from the EntitySkeleton class. Removing that statement caused the entity to fall to the void (through any block). I'm really confused now.
I'm so stupid I was spawning it on both sides.
That will hopefully fix it. I can't test it though because they're still falling through blocks
And yes, printing the coordinations on both sides showed that in the server they are at 0, 100, 0 and in the client side they are at 0, [something around 0 and lower], 0. Not sure how to fix it.
Actually, I just went through the console again. On the client side it's exactly at 0, 2, 0 as I defined it, but on ther server side is ~0.05, 0.0, ~0.05
It's just getting weirder and weirder
What I currently have is:
this.setSize(0.72F, 2.34F); (copied from the skeleton class)
In the constructor and:
@Override
public double getYOffset() {
return super.getYOffset() - 0.5D;
}
In the entity class. I'm not changing the yOffset itself.
Note that the skeleton is also using that overriden method and also not changing it's yOffset.
I'll try changing it to your statements.
Tested it. It might have changed something, but I can't tell since it's still falling through blocks.
And the this.height field, is it assigned somewhere? Because I'm not assigning it anywhere.
That size is in blocks? And if so, when you said to use:
this.setSize(1.5F, 5F)
Does it mean it will be 5 blocks tall? Isn't it too much?
And maybe it falls through blocks beacuse it doesn't have a collision box?
A quick search on the bounding box shows that it's only written in the base Entity class:
the entity is still falling through blocks. I used 1D on each because I don't really know what the values mean.
And from checking in the entity class, height and width are assigned, so the setSize method is really unrelvant - it's just changing these values, which isn't really an issue right now.
It's still falling through blocks though..
All the vanilla entity classes don't bother with all of that.. It looks really simple there and everything just works fine. I'm not sure what I'm doing wrong.
Here is the relevant part in the onItemUse method for a temporary item I use to spawn it:
if (!world.isRemote) {
EntityThrower entity = new EntityThrower(world);
entity.posX = x;
entity.posY = y + 1;
entity.posZ = z;
world.spawnEntityInWorld(entity);
}
By the way, I deleted most of the entity's class so it would be like other classes I see in the forum, git and minecraft source. It's still falling through blocks, so I think the problem isn't in the entity itself. Probably in the spawning/registring/model/renderer.
The solutions:
Entity disappearing - I spawned the entity on both sides instead of only the server side. (derp)
Entity falling through blocks - changing from setting the positions like: posX = , posY = , etc. to entity.setLocationAndAngle(...) solved it.
Edit:
I'm having another problem - my mob is just falling through blocks and despawning a few seconds later. Any help?
Can I do it in the attackEntityWithRangedAttack method? Or it's only called one? And if it's only called once per attack, is there another place I can do it on?
Thanks.
Yes I'm planning to have the rotations as field so they would be rendered by the model, but I want the entity to attack only after the render. Is it possible?
When your attack method is called, instead of performing the attack, set the timer on the server side and send a health update flag.
In your entity's onUpdate() method, decrement the timer each tick and if it reaches zero, then perform the actual attack. You could also use a DataWatcher for your animation instead of sending a health update, but the result is the same.
I got the solution, thanks
I edited the main post earlier with another error, I'd appreciate it of you'd help me
I'll check the server or client thing now and I'll update.
Until now I had the setSize in the constructor. I wasn't really sure what to put there, so I used the nubmers from the EntitySkeleton class. Removing that statement caused the entity to fall to the void (through any block). I'm really confused now.
I added the relevant classes to the main post. If someone could look at them and tell me what's wrong it would be great.
That will hopefully fix it. I can't test it though because they're still falling through blocks
And yes, printing the coordinations on both sides showed that in the server they are at 0, 100, 0 and in the client side they are at 0, [something around 0 and lower], 0. Not sure how to fix it.
(Just to clerify, I intended to spawn them at 0, 100, 0)
It's just getting weirder and weirder
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (!world.isRemote) {
EntityThrower entity = new EntityThrower(world);
entity.posX = entity.posZ = 0;
entity.posY = 20;
world.spawnEntityInWorld(entity);
}
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
return stack;
}
this.setSize(0.72F, 2.34F); (copied from the skeleton class)
In the constructor and:
@Override
public double getYOffset() {
return super.getYOffset() - 0.5D;
}
In the entity class. I'm not changing the yOffset itself.
Note that the skeleton is also using that overriden method and also not changing it's yOffset.
I'll try changing it to your statements.
Tested it. It might have changed something, but I can't tell since it's still falling through blocks.
And the this.height field, is it assigned somewhere? Because I'm not assigning it anywhere.
That size is in blocks? And if so, when you said to use:
Does it mean it will be 5 blocks tall? Isn't it too much?
And maybe it falls through blocks beacuse it doesn't have a collision box?
A quick search on the bounding box shows that it's only written in the base Entity class:
So maybe changing it to something more than *empty* would be?
Ok the boundingBox field is final. Not sure what to do.
Neither of these methods are overriden in the skeleton class.
I've tried overriding both, returning:
the entity is still falling through blocks. I used 1D on each because I don't really know what the values mean.
And from checking in the entity class, height and width are assigned, so the setSize method is really unrelvant - it's just changing these values, which isn't really an issue right now.
I'm updating the classes in the first post.
It's still falling through blocks though..
All the vanilla entity classes don't bother with all of that.. It looks really simple there and everything just works fine. I'm not sure what I'm doing wrong.
By the way, I deleted most of the entity's class so it would be like other classes I see in the forum, git and minecraft source. It's still falling through blocks, so I think the problem isn't in the entity itself. Probably in the spawning/registring/model/renderer.