Jump to content

[1.9] getThrower() null on client


FLUFFY2

Recommended Posts

I found out that EntityThrowable has a bug where sometimes the thrown entity straight up hit its thrower.

So i made a custom EntityThrowable named EntityShootable and i found that there is a problem in its onUpdate() method logic.

	Entity entity = null;
	List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expandXyz(1.0D));
	double d0 = 0.0D;
	boolean flag = false;

	for(int i = 0; i < list.size(); ++i){
		Entity entity1 = list.get(i);
		if(entity1.canBeCollidedWith()){
			if(entity1 == this.field_184539_c){
				flag = true;
			}else if(this.ticksExisted < 2 && this.field_184539_c == null){
				this.field_184539_c = entity1;
				flag = true;
			}else{
				flag = false;
				AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz(0.30000001192092896D);
				RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);

				if(raytraceresult1 != null){
					double d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);

					if(d1 < d0 || d0 == 0.0D){
						entity = entity1;
						d0 = d1;
					}
				}
			}
		}
	}

Sometimes the "entity1" is the actual thrower so it sets the "entity" to the thrower, and "entity" should be the actual target(enemy).

 

Now i tryed to make so if the "entity1" is the getThrower(), than do nothing and move on, in the entity list to the actual target.

BUT, the cute little getThrower() is a server only thing, so i get nullPoinetrsExpections.

Packets could slove the issue, but if the entity is spammed form like a fast firing gun, than thats a huge network overload.

 

How i could fix this issue guys? This is sort of a vanilla bug i guess...

Thanks!

Link to comment
Share on other sites

Do you see vanilla throwables hitting throwers? I don't, and no - that is not a bug.

 

If client doesn't need something - you don't force sending it.

 

Yes, you can easily implement IAdditinalSpawnData (name of sorts) and send thrower within spawn packet as entityId.

No, even if client would detect that thrown thing hit anything - client is NOT responsible for applying hit (meaning you don't call setDead() on client). What I am saying is basically this: If you don't need client to know thrower, you shouldn't care about what client does with that data. Server is the one who is supposed to kill throwable.

 

Unless I didn't get your point.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I would suggest you to try snowballs in close range with zombies. You will sometimes hit yourself with the snowball. Even in creative you will see that the snowball explodes in fornt of you(sometimes).

 

Now imagine a gun that is used in close combat and the bullet straight hits you. You die... and thats annoying.

I will try to supply you with a code that you can test and see later.

Link to comment
Share on other sites

You guys dont understand...

 

I have a gun that has EntityBullet extending EntityThrowable. Registered in the EntityRegistry!!!

In survival i go close to any living entity, like cow or zombie i keep shooting MYSELF sometimes, and eventually i kill myself.

Go ahead get snowballs, go close to a cow and start throwing it at him, sometimes it will do nothing to the cow, because it hits you.

Thats because the onImpact() method resoult.entityHit returns the thrower sometimes.

 

I made a new class called EntityShootable, that is a straight copy of EntityThrowable, and my EntityBullet calls extends that.

In the EntityThrowable's onUpdate() where the actual resoult.entityHit is created(RayTraceResoult), i can see it does indeed not makes sure that the thrower cannot hit himself at the time the entity is spawned.

 

Thats why i need the getThrower() on client site to make sure it never adds the player to the RayTraceResoult.

But because its a server only field, the client still thinks im being shot at, only the damage is not dealt because its handled my the server.

 

Mojang did f*cked it up, but if you dont believe just test my code:

 

In main class preInit:

EntityRegistry.registerModEntity(EntityBullet.class, ModID + ":Bullet", 1, instance, 250, 5, true);

 

EntityBullet.calss

public class EntityBullet extends EntityThrowable{

private int bulletdamage = 0;

public EntityBullet(World worldIn){
	super(worldIn);
	setSize(0.05F, 0.05F);
}

public EntityBullet(World worldIn, EntityLivingBase throwerIn){
	super(worldIn, throwerIn);
	setSize(0.05F, 0.05F);
}

public EntityBullet(World worldIn, double x, double y, double z){
	super(worldIn, x, y, z);
	setSize(0.05F, 0.05F);
}

public EntityBullet(World worldIn, EntityPlayer player, int damage){
	super(worldIn, player);
	setSize(0.05F, 0.05F);
	this.bulletdamage = damage;
}

@Override
protected void onImpact(RayTraceResult result){
	if(result.entityHit != null){
		if(result.entityHit instanceof EntityLivingBase){
			result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), bulletdamage);
			result.entityHit.motionX = 0D;
			result.entityHit.motionY = 0D;
			result.entityHit.motionZ = 0D;
			//worldObj.playSound(this.posX, this.posY, this.posZ, SoundEventContainer.hit, SoundCategory.PLAYERS, 1F, 1F, false);
		}
	}else{
		//worldObj.playSound(result.hitVec.xCoord, result.hitVec.yCoord, result.hitVec.zCoord, SoundEventContainer.bulletimpact, SoundCategory.BLOCKS, 1F, 1F, false);
	}
	if(!worldObj.isRemote){
		this.setDead();
	}
}
}

 

Add this to an item to shoot the bullet:

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand){
	if(!worldIn.isRemote){
		EntityBullet bullet = new EntityBullet(worldIn, playerIn, 10);
		bullet.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0F, 3F, 0F);
		worldIn.spawnEntityInWorld(bullet);
	}
	//worldIn.playSound(playerIn, playerIn.getPosition(), SoundEventContainer.uspsshoot, SoundCategory.PLAYERS, 1F, 1F);

	return new ActionResult(EnumActionResult.PASS, itemStackIn);
}

 

Put this stuff in, spawn some cows, go close to them(like inside), and start shooting in survival.

You will eventually kill yourself...

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.