First up, I'm pretty sure that "Hitbox" and "BoundingBox" are the same thing as far as Minecraft is concerned, but I couldn't find a better way to describe the problem below:
I've made a custom mob which looks like the vanilla giant zombie, but with AI so that it moves & attacks.
The entity is rendering correctly and behaving correctly, but will only take damage if I shoot it in the legs. Arrows will pass straight through the entity above hip height, and the entity is capable of walking through blocks above it's hip height.
I've set the bounding box to cover the whole body as seen by "F3+B", yet still the problem persists.
Do I have to tell the game that the body & head are parts that can be hit, and if so how do I do that?
@SideOnly(Side.CLIENT)
public class RenderGiantZombie extends RenderLiving
{
private static final ResourceLocation giantZombieTextures = new ResourceLocation("monstermash:textures/entity/zombie.png");
private float scale;
Wildbill22 - That was a relic of code from when I was overriding the vanilla giant class. I'm not entirely sure what it did, but I think it was what prevented giants from spawning in game as the vanilla giant class value was <0. Removing it has no effect.
Jabelar - I thought that max height may be an issue, but hadn't found any record of similar problems online. The vanilla giant that I'm basing this off has the same issue, which may be a part of why it was abandoned as an idea. I haven't tried intermediate values as my intention is to revive vanilla mobs that have been left by the wayside (undead horses, giant, red dragon etc), so wanted to keep it as true to the original.
4.5 blocks high is exactly the height of my giant's legs, so you may be onto something there, I'll look into it.
Another thing you might try, is subscribe to the RenderLivingEvent.Pre event, and if the entity is instanceof your giant, then use this.boundingBox and change it directly. I'm not sure exactly, but either you set the boundingBox, or each of its parts, something like:
I've varied the mob height, and found that despite it being shown properly by "F3+B", the bounding box doesn't register at above 4 blocks high (to an integer level of accuracy). Whilst that's a shame, I've now got a smaller giant that takes damage properly.
Has anyone else made mobs taller than 5 blocks that take damage properly?
You know, this topic reminded me that I had a similar problem when creating my giant and I did find that the box is limited to 4.5. I can't seem to find any forum topic that really resolves it though.
I also just spent about 20 minutes looking at the code and I can't see where the height or boundingBox.maxY is specifically clamped. There is one other weird field called ySize that appears occasionally in the code, but also I don't see it clamped. I'll keep looking.
I noticed that the giant zombie class sets size to 6.0F, but I'm not sure that it works.
Leviathan - Possibly, but that's a whole new world I've not looked at, and as there's no registered maxY for the vanilla hitbox (that we can find) then I doubt creating a new bounding box entity would have any effect.
Jabelar - The vanilla giant suffers from the same problem. I've summoned it in via commands and exactly the same hitbox behaviour is observed.
Instead of looking at all entities at a distance, you would look for your special entity and use custom bounding box (actually you probably can take the actual bounding box since it seems to represent actual size).
It's actually possible that my extended reach code works without modification for your needs. Since we haven't found where the bounding box is clipped, my code takes the actual bounding box and sends a packet to server to initiate attack. So it might just work.
Yes, I just tested my extended reach code against a target that was 10.0F height. I was able to hit the top part consistently with my extended reach weapon, instead of sword which could not.
To adapt my code to work for all weapons on your giant, just don't limit the mouse event to the extended reach weapon type and in the get mouse over method only look for your custom entity.
Hi 'crafters!
First up, I'm pretty sure that "Hitbox" and "BoundingBox" are the same thing as far as Minecraft is concerned, but I couldn't find a better way to describe the problem below:
I've made a custom mob which looks like the vanilla giant zombie, but with AI so that it moves & attacks.
The entity is rendering correctly and behaving correctly, but will only take damage if I shoot it in the legs. Arrows will pass straight through the entity above hip height, and the entity is capable of walking through blocks above it's hip height.
I've set the bounding box to cover the whole body as seen by "F3+B", yet still the problem persists.
Do I have to tell the game that the body & head are parts that can be hit, and if so how do I do that?
EntityGiantZombie class:
package com.cookiehook.monstermash.entities;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
public class EntityGiantZombie extends EntityMob
{
public EntityGiantZombie(World worldIn)
{
super(worldIn);
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
this.tasks.addTask(2, this.field_175455_a);
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(8, new EntityAILookIdle(this));
this.setSize(3.0F, 12.0F);
this.applyEntityAI();
}
public float getEyeHeight()
{
return 10.440001F;
}
protected void applyEntityAI()
{
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityVillager.class, 1.0D, true));
this.tasks.addTask(4, new EntityAIAttackOnCollide(this, EntityIronGolem.class, 1.0D, true));
this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] {EntityPigZombie.class}));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, false));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityIronGolem.class, true));
}
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(70.0D);
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(100.0D);
this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(20.0D);
}
@Override
public float func_180484_a(BlockPos p_180484_1_)
{
return 0.0F;
}
}
RenderGiantZombie class:
package com.cookiehook.monstermash.client.renderer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelZombie;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.layers.LayerBipedArmor;
import net.minecraft.client.renderer.entity.layers.LayerHeldItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.cookiehook.monstermash.entities.EntityGiantZombie;
@SideOnly(Side.CLIENT)
public class RenderGiantZombie extends RenderLiving
{
private static final ResourceLocation giantZombieTextures = new ResourceLocation("monstermash:textures/entity/zombie.png");
private float scale;
public RenderGiantZombie(RenderManager p_i46173_1_, ModelBase p_i46173_2_, float p_i46173_3_, float p_i46173_4_)
{
super(p_i46173_1_, p_i46173_2_, p_i46173_3_ * p_i46173_4_);
this.scale = p_i46173_4_;
this.addLayer(new LayerHeldItem(this));
this.addLayer(new LayerBipedArmor(this)
{
protected void func_177177_a()
{
this.field_177189_c = new ModelZombie(0.5F, true);
this.field_177186_d = new ModelZombie(1.0F, true);
}
});
}
public void func_82422_c()
{
GlStateManager.translate(0.0F, 0.1875F, 0.0F);
}
protected void preRenderCallback(EntityGiantZombie p_77041_1_, float p_77041_2_)
{
GlStateManager.scale(this.scale, this.scale, this.scale);
}
protected ResourceLocation getEntityTexture(EntityGiantZombie entity)
{
return giantZombieTextures;
}
protected void preRenderCallback(EntityLivingBase p_77041_1_, float p_77041_2_)
{
this.preRenderCallback((EntityGiantZombie)p_77041_1_, p_77041_2_);
}
protected ResourceLocation getEntityTexture(Entity entity)
{
return this.getEntityTexture((EntityGiantZombie)entity);
}
}
Cheers,
-Cookiehook
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
What does this do:
func_180484_a
Seems unlikely it is related though (I've never done a 1.8 mod, so something new maybe)?
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
That is weird. The bounding box (used for pathfinding) and hitbox should be the same, and the F3+B should show it accurately. I created a giant entity in 1.8 you can compare your code with mine here: https://github.com/jabelar/MagicBeans-1.8fixed/blob/master/src/main/java/com/blogspot/jabelarminecraft/magicbeans/entities/EntityGiant.java
It may be possible that your size is too big, maybe there is some max. Did you try intermediate values? I'm using 4.5F for height in my giant.
Wildbill22 - That was a relic of code from when I was overriding the vanilla giant class. I'm not entirely sure what it did, but I think it was what prevented giants from spawning in game as the vanilla giant class value was <0. Removing it has no effect.
Jabelar - I thought that max height may be an issue, but hadn't found any record of similar problems online. The vanilla giant that I'm basing this off has the same issue, which may be a part of why it was abandoned as an idea. I haven't tried intermediate values as my intention is to revive vanilla mobs that have been left by the wayside (undead horses, giant, red dragon etc), so wanted to keep it as true to the original.
4.5 blocks high is exactly the height of my giant's legs, so you may be onto something there, I'll look into it.
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
Another thing you might try, is subscribe to the RenderLivingEvent.Pre event, and if the entity is instanceof your giant, then use this.boundingBox and change it directly. I'm not sure exactly, but either you set the boundingBox, or each of its parts, something like:
entity.boundingBox.maxX = entity.boundingBox.minX + (width);
entity.boundingBox.maxY = entity.boundingBox.minY + (height);
entity.boundingBox.maxZ = entity.boundingBox.minZ + (width);
I've used this method to change the player hit box to a different size, but of course I used the RenderPlayerEvent.Pre event.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
I've varied the mob height, and found that despite it being shown properly by "F3+B", the bounding box doesn't register at above 4 blocks high (to an integer level of accuracy). Whilst that's a shame, I've now got a smaller giant that takes damage properly.
Has anyone else made mobs taller than 5 blocks that take damage properly?
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
You know, this topic reminded me that I had a similar problem when creating my giant and I did find that the box is limited to 4.5. I can't seem to find any forum topic that really resolves it though.
I did find another person reporting the issue although we didn't come to a solution at the time: http://www.minecraftforge.net/forum/index.php?topic=25092.0
I also just spent about 20 minutes looking at the code and I can't see where the height or boundingBox.maxY is specifically clamped. There is one other weird field called ySize that appears occasionally in the code, but also I don't see it clamped. I'll keep looking.
I noticed that the giant zombie class sets size to 6.0F, but I'm not sure that it works.
entity.boundingBox is just an AxisAlignedBB, so couldn't you create your own and use that to detect attacks instead of the vanilla one?
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
Leviathan - Possibly, but that's a whole new world I've not looked at, and as there's no registered maxY for the vanilla hitbox (that we can find) then I doubt creating a new bounding box entity would have any effect.
Jabelar - The vanilla giant suffers from the same problem. I've summoned it in via commands and exactly the same hitbox behaviour is observed.
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
This is probably the way to go. I think you could start with my special mouse over method I use for extending a reach of a weapon: http://jabelarminecraft.blogspot.com/p/minecraft-modding-extending-reach-of.html
Instead of looking at all entities at a distance, you would look for your special entity and use custom bounding box (actually you probably can take the actual bounding box since it seems to represent actual size).
It's actually possible that my extended reach code works without modification for your needs. Since we haven't found where the bounding box is clipped, my code takes the actual bounding box and sends a packet to server to initiate attack. So it might just work.
Yes, I just tested my extended reach code against a target that was 10.0F height. I was able to hit the top part consistently with my extended reach weapon, instead of sword which could not.
To adapt my code to work for all weapons on your giant, just don't limit the mouse event to the extended reach weapon type and in the get mouse over method only look for your custom entity.