Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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);
		}

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.