Jump to content

[1.7.2] Make a 3D throwable item animate when it hits an entity


Thornack

Recommended Posts

I Have a 3D ball and I want to get it to land on the ground when it hits an entity, so far I have figured out that inside the onImpact method there is the if statement

 if (movingItemPosition.entityHit != null) {}

and if I call a method inside it then it is only executed if the bounding box of my throwable ball comes into contact with the bounding box of the entity.

 

I wish to use this to cause the thrown ball to land on the ground, whereas if the entity is missed and the ball hits the ground then it is set to dead. (this part I have down where the if statement

 if (!this.worldObj.isRemote) 
        {
        this.setDead();} 

takes care of that part. However I am not sure how to get the same thrown ball to land on the ground when it hits an entity. Here is my full onImpact Method. Any Ideas on how to achieve this?

 

 

 

@Override
protected void onImpact(MovingObjectPosition movingItemPosition) {
	if (movingItemPosition.entityHit != null)
        {
            // float thrownItemDamage = 0;//how much damage the thrown item will inflict (removing this now makes the player not jump 
                                                             //when they are hit )
            this.setPosition(posX, posY, posZ);
		this.injurePlayer(); // placing this method here fixes the earlier problem where even if you missed the entities hitbox    
                                                     //then the injurePlayer method would execute now the Balls hitbox must come into contact with a   
                                                    //living entity to execute the injurePlayer method
           
            // movingItemPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), thrownItemDamage); //(removing this now makes the player not jump when they are hit )
        }

        for (int i = 0; i < 8; ++i)
        {
            this.worldObj.spawnParticle("crit", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
        }
    
        // this if statement is required or it will keep updating forever and you'll end up with lots of leftover entities in the world
        if (!this.worldObj.isRemote) 
        {
        this.setDead();}
        
        
		} 

Link to comment
Share on other sites

I have figured out my throwable entity problem where upon hitting a living entity it drops itself as an item (but I think I used a workaround where it despawns itself and spawns a new item (im not sure if thats exactly what is going on but I do suspect that it is)) All that was required to solve this was

 entityDropItem(new ItemStack(CommonProxy.itemBall), 0.0F); 

to be added to the onImpact method. I have also added functionality where if you miss the entity then the entity is set to dead and sends a coloured chat message to the thrower.

 

I wish to animate this item after the Entity drops it.

 

My model is constructed to have two halves and is a sphere made of over 150 cubes. I want the halves to rotate in different directions to simulate the ball "popping". I  have been trying to figure out minecrafts animations and so far i only understand a little, I have been reading a bunch of stuff on this but havent had any luck.

 

My model class is really really long so I have just posted in the rotation functions (to keep this post readable) where all of my models boxes are accounted for in these functions and the sphere renders properly midflight, on the ground, in inventory, in first and third person.

 

The rotation functions in my Model Class

public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    //super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5);
    B1.render(f5);
    B2.render(f5);
    B3.render(f5);
    B4.render(f5);
    B5.render(f5);
    B6.render(f5);
    B7.render(f5);
    B8.render(f5);
    B9.render(f5);
    B10.render(f5);
    B11.render(f5);
    B12.render(f5);
    B13.render(f5);
    B14.render(f5);
    B15.render(f5);
    B16.render(f5);
    B17.render(f5);
    B18.render(f5);
    B19.render(f5);
    B20.render(f5);
    B21.render(f5);
    B22.render(f5);
    B23.render(f5);
    B24.render(f5);
    B25.render(f5);
    B26.render(f5);
    B27.render(f5);
    B28.render(f5);
    B29.render(f5);
    B30.render(f5);
    B31.render(f5);
    B32.render(f5);
    B33.render(f5);
    B34.render(f5);
    B35.render(f5);
    B36.render(f5);
    B37.render(f5);
    B38.render(f5);
    B39.render(f5);
    B40.render(f5);
    B41.render(f5);
    B42.render(f5);
    B43.render(f5);
    B44.render(f5);
    B45.render(f5);
    B46.render(f5);
    B47.render(f5);
    B48.render(f5);
    B49.render(f5);
    B50.render(f5);
    B51.render(f5);
    B52.render(f5);
    B53.render(f5);
    B54.render(f5);
    B55.render(f5);
    B56.render(f5);
    B57.render(f5);
    B58.render(f5);
    B59.render(f5);
    B60.render(f5);
    B61.render(f5);
    B62.render(f5);
    B63.render(f5);
    B64.render(f5);
    B65.render(f5);
    B66.render(f5);
    B67.render(f5);
    B68.render(f5);
    B69.render(f5);
    B70.render(f5);
    B71.render(f5);
    B72.render(f5);
    B73.render(f5);
    B74.render(f5);
    T1.render(f5);
    T2.render(f5);
    T3.render(f5);
    T4.render(f5);
    T5.render(f5);
    T6.render(f5);
    T7.render(f5);
    T8.render(f5);
    T9.render(f5);
    T10.render(f5);
    T11.render(f5);
    T12.render(f5);
    T13.render(f5);
    T14.render(f5);
    T15.render(f5);
    T16.render(f5);
    T17.render(f5);
    T18.render(f5);
    T19.render(f5);
    T20.render(f5);
    T21.render(f5);
    T22.render(f5);
    T23.render(f5);
    T24.render(f5);
    T25.render(f5);
    T26.render(f5);
    T27.render(f5);
    T28.render(f5);
    T29.render(f5);
    T30.render(f5);
    T31.render(f5);
    T32.render(f5);
    T33.render(f5);
    T34.render(f5);
    T35.render(f5);
    T36.render(f5);
    T37.render(f5);
    T38.render(f5);
    T39.render(f5);
    T40.render(f5);
    T41.render(f5);
    T42.render(f5);
    T43.render(f5);
    T44.render(f5);
    T45.render(f5);
    T46.render(f5);
    T47.render(f5);
    T48.render(f5);
    T49.render(f5);
    T50.render(f5);
    T51.render(f5);
    T52.render(f5);
    T53.render(f5);
    T54.render(f5);
    T55.render(f5);
    T56.render(f5);
    T57.render(f5);
    T58.render(f5);
    T59.render(f5);
    T60.render(f5);
    T61.render(f5);
    T62.render(f5);
    T63.render(f5);
    T64.render(f5);
    T65.render(f5);
    T66.render(f5);
    T67.render(f5);
    T68.render(f5);
    T69.render(f5);
    T70.render(f5);
    T71.render(f5);
    T72.render(f5);
    T73.render(f5);
    T74.render(f5);
   
  }

private void setRotation(ModifiedModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
  {
  float topRotateX = MathHelper.cos(f * 2F) * f1;
  RotationSet top = new RotationSet(Arrays.asList(this.T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45, T46, T47, T48, T49, T50, T51, T52, T53, T54, T55, T56, T57, T58, T59, T60, T61, T62, T63, T64, T65, T66, T67, T68, T69, T70, T71, T72, T73));
  top.doRotation(0,topRotateX, 0);
  float bottomRotateX = MathHelper.cos(f * -1F) * f1;
  new RotationSet(Arrays.asList(this.B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15, B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, B30, B31, B32, B33, B34, B35, B36, B37, B38, B39, B40, B41, B42, B43, B44, B45, B46, B47, B48, B49, B50, B51, B52, B53, B54, B55, B56, B57, B58, B59, B60, B61, B62, B63, B64, B65, B66, B67, B68, B69, B70, B71, B72, B73));
  top.doRotation(0,bottomRotateX, 0);
  }

 

Entity Class

package soccer.entity;

import java.util.Iterator;
import java.util.List;
import java.util.Random;

import soccer.CommonProxy;
import soccer.calculations.CalcCapture;
import soccer.model.ItemModelBall;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.client.C01PacketChatMessage;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;

public class EntityBall extends EntityThrowable {

public EntityBall(World world) {
	super(world);
	this.setSize(0.5F, 0.5F); // hit-box size?

}


public EntityBall(World world, EntityLivingBase par2EntityLivingBase)
    {
        super(world, par2EntityLivingBase);
        this.motionX *= 0.75f;
        this.motionZ *= 0.75f;
        this.motionY *= 1f;
    }

    public EntityBall(World world, double x, double y, double z)
    {
        super(world, x, y, z);
    }

public EntityBall(World world, EntityLiving entityLiving) {
	super(world, entityLiving);
}


/**
 * Called when this EntityThrowable hits a block or entity.
 */
@Override
protected void onImpact(MovingObjectPosition movingItemPosition) {

	int BallMissed = 0;
	if (movingItemPosition.entityHit != null)
        {
           float thrownItemDamage = 0;
           captureCalcStarted = 1;
           movingItemPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), thrownItemDamage); 
           entityDropItem(new ItemStack(CommonProxy.itemBall), 0.0F);//the float valuer makes the item bounce up (the higher the number the higher the bounce on impact)
           setDead();
                    
        }

        for (int i = 0; i < 8; ++i)
        {
            this.worldObj.spawnParticle("crit", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
        }
    
        // this if statement is required or it will keep updating forever and you'll end up with lots of leftover entities in the world
        if (!this.worldObj.isRemote) 
        {
        ballMissed = 1;
        this.setDead();
                }
        if (ballMissed ==1){
        	Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You Missed The Player"));
        	    }
        
		}

   	 
protected void entityInit() {
}}

 

I think I have to call setRotationAngles in my Entity Class but I am not sure how. I tried making an object of my model class and then calling the method but that didnt work. Any help will be greatly appreciated.

ItemModelBall ball = new ItemModelBall();
           ball.setRotationAngles(1f, 1f, 1f, 1f, 1f, 0f);

 

 

Link to comment
Share on other sites

I have noticed that inside this onImpact method is that if I remove the if statement

 

if (!this.worldObj.isRemote) 
        {
        this.setDead();}

but leave everything else as is the thrown ball seems to hit the ground then continue falling through blocks until it falls out of the world. My workaround this issue may not be the best solution to the problem of getting my ball entity to hit a living entity and then fall to the ground. If anyone has any ideas on how else to achieve this, I am working on both problems and would appreciate any input.

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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