Posted December 13, 20159 yr 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]
December 13, 20159 yr You're using CLIENT only code in your #onImpact method: if(!Keyboard.isKeyDown(42)){ Not good. Also, your 'spiderMan' field will always be null on the client side unless you specifically send it with the spawn packet - implement IEntityAdditionalSpawnData. http://i.imgur.com/NdrFdld.png[/img]
December 13, 20159 yr Author Thanks! By removing the Client only code and implementing IEntityAdditionalSpawnData the problem was fixed! Thank you so much!
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.