Jump to content

[SOLVED] Entity Motion Not Updating


bignose956

Recommended Posts

Hello,

 

Today I seek help in making a block that launches ThrowableEntitys at hostile mobs. It is a little like a snowman, except it is a block and its position is constant. The method i am using is as follows:

setThrowableHeading()

 

The problem is that it continues to lock onto the possession of the first mob it encounters, and will throw only at that position, even after the mob is dead.

 

The first thing that would come to one's mind when reading my code sample is that I only reference the first index of the list list.get(0), but this is not causing the "locked aim" because I use list.clear() after spawning the entity, and when the mob is dead, the first index of the list will obtain a new value. 

 

[Forge 1.8.9]

 

Spoiler

//Class extends net.minecraft.block.Block
	
	@Override
	public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand){
		
		int xCoord = pos.getX();
		int yCoord = pos.getY() + 1;
		int zCoord = pos.getZ();
		
		List<EntityMob> list = worldIn.getEntitiesWithinAABB(EntityMob.class, new AxisAlignedBB((float) (xCoord + 40), (float) (yCoord + 40), (float) (zCoord + 40), (float) (xCoord - 40), (float) (yCoord - 4), (float) (zCoord - 40)));
		
		if(!list.isEmpty()){
			
			EntityGranade e = new EntityGranade(worldIn, (double)xCoord, (double)(yCoord + 1), (double)zCoord);
			
			e.setThrowableHeading(list.get(0).posX, list.get(0).posY, list.get(0).posZ, 5, 0);
		
			worldIn.spawnEntityInWorld(e);
		}
		list.clear();
		worldIn.scheduleUpdate(pos, this, 100);
	}

 

 

Edited by bignose956
Fixing Formatting, Updating Status
Link to comment
Share on other sites

I got it :o

 

List<EntityMob> list = worldIn.getEntitiesWithinAABB(EntityMob.class, new AxisAlignedBB((float) (xCoord + 40), (float) (yCoord + 40), (float) (zCoord + 40), (float) (xCoord - 40), (float) (yCoord - 4), (float) (zCoord - 40)));
		
		if(!list.isEmpty()){
			
			EntityMob target = list.get(0);
		
			EntityGrenade entitysnowball = new EntityGrenade(worldIn, xCoord, yCoord, zCoord);
	        double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
	        double d1 = target.posX - pos.getX();
	        double d2 = d0 - entitysnowball.posY;
	        double d3 = target.posZ - pos.getZ();
	        float f = MathHelper.sqrt_double(d1 * d1 + d3 * d3) * 0.2F;
	        entitysnowball.setThrowableHeading(d1, d2 + (double)f, d3, 4, 0);
	        worldIn.spawnEntityInWorld(entitysnowball);
		}

 

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.