Jump to content

Mob flying too fast/ Not dealing damage


Eastonium

Recommended Posts

THIS PART HAS BEEN SOLVED! SEE BELOW FOR NEW PROBLEMS!

 

I'm trying to make a mob that flies toward you and attacks, but every 5 seconds or so, it'll throw a nullpointerexception saying the entity that it is attacking doesn't have a position.

Here is all the relevant code:

public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
	if (this.isEntityInvulnerable())
	{
		return false;
	}
	else
	{
		Entity entity = par1DamageSource.getEntity();

		if (entity instanceof Entity)
		{
			List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(16.0D, 16.0D, 16.0D));

			for (int i = 0; i < list.size(); ++i)
			{
				Entity entity1 = (Entity)list.get(i);

				if (entity1 instanceof EntityScarfy)
				{
					EntityScarfy entityscarfy = (EntityScarfy)entity1;
					entityscarfy.becomeAngryAt(entity);
				}
			}
			this.becomeAngryAt(entity);
		}

		return super.attackEntityFrom(par1DamageSource, par2);
	}
}

private void becomeAngryAt(Entity par1Entity)
{
	this.isAngry = true;
	this.entityToAttack = par1Entity;
}
public void updateAITasks()
{
	super.updateAITasks();
	if (this.currentFlightTarget != null && (!this.worldObj.isAirBlock(this.currentFlightTarget.posX, this.currentFlightTarget.posY, this.currentFlightTarget.posZ) || this.currentFlightTarget.posY < 1))
	{
		this.currentFlightTarget = null;
	}

	if (this.currentFlightTarget == null || this.rand.nextInt(30) == 0 || this.currentFlightTarget.getDistanceSquared((int)this.posX, (int)this.posY, (int)this.posZ) < 4.0F)
	{
		if(this.entityToAttack != null)
		{
//HERE IS THE PROBLEM		this.currentFlightTarget.set((int)this.entityToAttack.posX, (int)(this.entityToAttack.posY + 0.5F), (int)this.entityToAttack.posZ);
		}
		else
		{
			this.currentFlightTarget = new ChunkCoordinates((int)this.posX + this.rand.nextInt(7) - this.rand.nextInt(7), (int)this.posY + this.rand.nextInt(5) - 2, (int)this.posZ + this.rand.nextInt(7) - this.rand.nextInt(7));
		}
	}
	double d0 = (double)this.currentFlightTarget.posX - this.posX;
	double d1 = (double)this.currentFlightTarget.posY + 0.5F - this.posY;
	double d2 = (double)this.currentFlightTarget.posZ - this.posZ;
	this.motionX += (Math.signum(d0) * 0.5D - this.motionX) * 0.10000000149011612D;
	this.motionY += (Math.signum(d1) * 0.699999988079071D - this.motionY) * 0.10000000149011612D;
	this.motionZ += (Math.signum(d2) * 0.5D - this.motionZ) * 0.10000000149011612D;
	float f = (float)(Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) - 90.0F;
	float f1 = MathHelper.wrapAngleTo180_float(f - this.rotationYaw);
	this.moveForward = 0.5F;
	this.rotationYaw += f1;
}

It doesn't always throw the null pointer, so I don't know why it doesn't work all the time.

Link to comment
Share on other sites

	if (this.currentFlightTarget == null || this.rand.nextInt(30) == 0 || this.currentFlightTarget.getDistanceSquared((int)this.posX, (int)this.posY, (int)this.posZ) < 4.0F)
	{
		if(this.entityToAttack != null)
		{
//HERE IS THE PROBLEM		this.currentFlightTarget.set((int)this.entityToAttack.posX, (int)(this.entityToAttack.posY + 0.5F), (int)this.entityToAttack.posZ);
		}
		else
		{
			this.currentFlightTarget = new ChunkCoordinates((int)this.posX + this.rand.nextInt(7) - this.rand.nextInt(7), (int)this.posY + this.rand.nextInt(5) - 2, (int)this.posZ + this.rand.nextInt(7) - this.rand.nextInt(7));
		}
	}

 

so, you indicated the problem line

 

the reason it is sometimes null, is because you are explicitly executing that branch when the target IS null with the first bit...so you need to check if it executed that branch because of null, and un-nullifiy it (give it a reference to SOMETHING), such as:

 

 

	if (this.currentFlightTarget == null || this.rand.nextInt(30) == 0 || this.currentFlightTarget.getDistanceSquared((int)this.posX, (int)this.posY, (int)this.posZ) < 4.0F)
	{
		if(this.entityToAttack != null)
		{
                             if(this.currentFlightTarget==null)
                             {
                                          this.currentFlightTarget = new ChunkCoordinantes(0,0,0);
                             }
                     this.currentFlightTarget.set((int)this.entityToAttack.posX, (int)(this.entityToAttack.posY + 0.5F), (int)this.entityToAttack.posZ);
		}
		else
		{
			this.currentFlightTarget = new ChunkCoordinates((int)this.posX + this.rand.nextInt(7) - this.rand.nextInt(7), (int)this.posY + this.rand.nextInt(5) - 2, (int)this.posZ + this.rand.nextInt(7) - this.rand.nextInt(7));
		}
	}

 

Link to comment
Share on other sites

Obviously the motion parameters deal with how fast the entity is.

 

And how the entity attacks is your choice.

 

The whole point of me asking is because I've tried and can't get the flying speed to change.

 

And yes, I know than I control how it attacks. I want it to attack by touching you just like zombies do. But that is t working now that the mob flies.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Yeah idk how to shut this down but it had something to do with parchment. It works now, I think I may have had the wrong version or something?
    • Recently while playing offline due to internet outages Malwarebytes identified Javaw.exe as malware, not thinking too much of it i deleted the file causing this error.  Unable to start Java. Error details: The requested operation requires elevation. Filename on disk: javaw.exe Path: C:\Users\---\curseforge\minecraft\Install\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw.exe Exists: File I reinstalled the file, same error occurred. I deleted CurseForge, over wolf and Minecraft and reinstalled them. Same error occurring. I have read starting Minecraft in administrator mode will help. I attempted to launch Minecraft through CurseForge in administrative mode this did not help.  I updated and downloaded the newest version of java, again receiving the same error. I updated Malwarebytes authorizing settings to allow for Javaw.exe through the pathway C:\Users\jacob\curseforge\minecraft\Install\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw.exe this did not assist either.  I am unsure of what to try next or what i am missing, i am not an expert with the complexities of these systems but any help to teach me or assist in problem solving would help. I also cannot find any debug logs or crash logs based on this specific circumstance.  The only thing that pops up when I search debug through the files is https://pastebin.com/WqMEvEn6.    
    • I have been trying my hardest to find the method to detect if the player is on the ground. I looked it up and people just say it like onGround always works, or isOnGround always works. Nothing shows up for me and the wording is red. I tried looking up an import but it doesn't seem to exist. I had to same issue with hasGlint, which turned out to be in the Item class and was isFoil instead. I even found the checkfalldamage method in the Living Entity class (I found this through looking at isFallFlying method and looking at usages) but it  uses its own variable to see if the player is on the ground, and I have NO idea where it gets that from! (It is called pOnGround) I am using Intellij, SDk 21, Language level 17, and the Forge version is 1.20.1-47.1.0. I Don't know where to look anymore and I feel like im going crazy.
    • I have been trying my hardest to find the method to detect if the player is on the ground. I looked it up and people just say it like onGround always works, or isOnGround always works. Nothing shows up for me and the wording is red. I tried looking up an import but it doesn't seem to exist. I had to same issue with hasGlint, which turned out to be in the Item class and was isFoil instead. I even found the checkfalldamage method in the Living Entity class (I found this through looking at isFallFlying method and looking at usages) but it  uses its own variable to see if the player is on the ground, and I have NO idea where it gets that from! (It is called pOnGround) I am using Intellij, SDk 21, Language level 17, and the Forge version is 1.20.1-47.1.0. I Don't know where to look anymore and I feel like im going crazy.
  • Topics

×
×
  • Create New...

Important Information

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