Jump to content

Recommended Posts

Posted

I've not been able to figure out what's causing my throwable entity to lose the player as the owner. AFAIK I'm doing it all correctly. Here's the code:

 

EntityRegistration

EntityRegistry.registerModEntity(EntityWebString.class, "Web String", webStringID, this, 128, 10, true);

 

EntityThrowable

public class EntityWebString extends EntityThrowable{

public EntityPlayer spiderMan;

public EntityWebString(World world){
	super(world);
	this.spiderMan = (EntityPlayer) this.getThrower();
}

public EntityWebString(World world,	EntityLivingBase throwingEntity) {
	super(world, throwingEntity);
	this.spiderMan = (EntityPlayer) throwingEntity;
	this.ignoreFrustumCheck = true;
	this.setSize(0.1F, 0.1F);
	this.motionX *= 2F;
	this.motionZ *= 2F;
	this.motionY *= 2F;
	SuperHeroLogger.debug("Spawned String with owner:" + spiderMan);
}

@Override
protected float getGravityVelocity() {
	return 0.03F;
}

@Override
public void onUpdate() {
	super.onUpdate();
}

protected void onImpact(MovingObjectPosition hitPos) {
	SuperHeroLogger.debug("Object String: " + hitPos.hitInfo);
	SuperHeroLogger.debug("Owner is: " + this.spiderMan);
	SuperHeroLogger.debug("Owner is: " + this.getThrower());
	if(hitPos.typeOfHit == MovingObjectType.ENTITY){
		SuperHeroLogger.debug("Object Hit by String: " + hitPos.entityHit.toString());
		hitPos.entityHit.motionX = -0.75F * this.motionX;
		hitPos.entityHit.motionZ = -0.75F * this.motionZ;
		hitPos.entityHit.motionY += 0.5F;

		this.setDead();
	}
	else if(hitPos.typeOfHit == MovingObjectType.BLOCK){
		if(!Keyboard.isKeyDown(42)){
			try{
				SuperHeroLogger.debug("Block Hit by String: " + hitPos.blockX + "x, " + hitPos.blockZ + "z, " + hitPos.blockY + "y");
				this.spiderMan.motionX = 2F * this.motionX;
				this.spiderMan.motionZ = 2F * this.motionZ;
				this.spiderMan.motionY = (double)(4.0F * -MathHelper.sin(this.spiderMan.rotationPitch / 180.0F * (float)Math.PI));
			}
			catch(NullPointerException e){
				SuperHeroLogger.error(e.getMessage());
				e.printStackTrace();
			}
		}
		this.setDead();
	}

}

}

 

Item Right click code

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
	EntityWebString string = new EntityWebString(world, player);

	switch (shotType){
	case 0:
		if(player.inventory.hasItem(SpiderMan.webString)){
			if(!world.isRemote){
				world.spawnEntityInWorld(string);
			}
			player.inventory.consumeInventoryItem(SpiderMan.webString);
		}
		break;
	case 1:
		if (player.inventory.hasItem(SpiderMan.webBall)){
			if(!world.isRemote){
				world.spawnEntityInWorld(new EntityWebBallNew(world, player));
			}
			player.inventory.consumeInventoryItem(SpiderMan.webBall);
		}
		break;
	}

	return super.onItemRightClick(itemStack, world, player);
}

 

Log Output

[15:06:30] [Client thread/ERROR] [dg_shc]: Spawned String with owner:EntityClientPlayerMP['rara_avia'/268, l='MpServer', x=-260.85, y=68.62, z=226.77]
[15:06:30] [server thread/ERROR] [dg_shc]: Spawned String with owner:EntityPlayerMP['rara_avia'/268, l='New World', x=-260.85, y=67.00, z=226.77]
[15:06:30] [Client thread/ERROR] [dg_shc]: Owner is: null
[15:06:30] [Client thread/ERROR] [dg_shc]: Owner is: null
[15:06:30] [Client thread/ERROR] [dg_shc]: null
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.lang.NullPointerException
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.dudgames.spiderman.entities.EntityWebString.onImpact(EntityWebString.java:64)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.entity.projectile.EntityThrowable.onUpdate(EntityThrowable.java:229)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.dudgames.spiderman.entities.EntityWebString.onUpdate(EntityWebString.java:45)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2298)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.world.World.updateEntity(World.java:2258)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.world.World.updateEntities(World.java:2108)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.client.Minecraft.runTick(Minecraft.java:2097)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.client.Minecraft.run(Minecraft.java:962)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.client.main.Main.main(Main.java:164)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at java.lang.reflect.Method.invoke(Unknown Source)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
[15:06:30] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: 	at GradleStart.main(Unknown Source)
[15:06:30] [server thread/ERROR] [dg_shc]: Owner is: EntityPlayerMP['rara_avia'/268, l='New World', x=-260.85, y=67.00, z=226.77]
[15:06:30] [server thread/ERROR] [dg_shc]: Owner is: EntityPlayerMP['rara_avia'/268, l='New World', x=-260.85, y=67.00, z=226.77]

 

 

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.

×
×
  • Create New...

Important Information

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