Jump to content

[1.15.2] How do I make projectiles invisible for a certain amount of time in first person mode?


Recommended Posts

Posted

I have a projectile that I shoot out of my head, but it covers almost the whole screen so I want it to be invisible for like half a second in first person mode.

How would I do this?

Posted

Howdy

 

I'd suggest you make your own EntityRenderer for your projectile.  The renderer can check whether the player is in first person view, and if so, make sure that the entity is at least a given minimum distance away from the player's head before rendering it.

Third person view (0, 1, 2) is accessible from GameSettings and ActiveRenderInfo (minecraft->gameRenderer->activerenderinfo)

 

-TGG

 

Posted

Thank you for replying.
This works perfectly, but I have another question.
How do I get the player that is rendering the entity, because I would like the render to be cancelled only for the shooter.

Posted

if( Minecraft.getInstance().gameSettings.thirdPersonView==0 && entityIn.ticksExisted<20 && Minecraft.getInstance().player == entityIn.shootingEntity ) {
	return;
}
	super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);

This is now never true, but if I add .getEntity() to them the player and shootingEntity, it crashes, also, I tried using .getName but that also crashes the game.
The crash occurs whenever the entity is rendered

Posted
@Override
	public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
		if(player.isSneaking()) {
			Vec3d look = player.getLookVec();
			Vec3d pos = player.getPositionVec();
			AccurateSkull skull = new AccurateSkull(world, player, look.x*2, look.y*2, look.z*2);
			skull.setPosition(pos.x, player.getPosYEye(), pos.z);
			skull.addTag("shooter:"+player.getName().toString());
			world.playSound(player, player.getPosition(), SoundEvents.ENTITY_WITHER_SHOOT, SoundCategory.PLAYERS , 1.0F, 1.0F);
			world.addEntity(skull);
			player.getHeldItem(hand).damageItem(100, player, Player -> {});
			return ActionResult.resultSuccess(player.getHeldItem(hand));
		}
		else {
			return ActionResult.resultFail(player.getHeldItem(hand));
		}
	}

 

Posted

AccurateSkull skull = new AccurateSkull(world, player, look.x*2, look.y*2, look.z*2);

here are the constructors being used

 

public AccurateSkull(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ) {
		super(EntityType.WITHER_SKULL, shooter, accelX, accelY, accelZ, worldIn);
	}


 

public AccurateProjectile(EntityType<?> p_i50175_1_, LivingEntity p_i50175_2_, double p_i50175_3_, double p_i50175_5_, double p_i50175_7_, World p_i50175_9_) {
	      this(p_i50175_1_, p_i50175_9_);
	      this.shootingEntity = p_i50175_2_;
	      this.setLocationAndAngles(p_i50175_2_.getPosX(), p_i50175_2_.getPosY(), p_i50175_2_.getPosZ(), p_i50175_2_.rotationYaw, p_i50175_2_.rotationPitch);
	      this.recenterBoundingBox();
	      this.setMotion(Vec3d.ZERO);
	      p_i50175_3_ = p_i50175_3_ + this.rand.nextGaussian() * 0.02D;
	      p_i50175_5_ = p_i50175_5_ + this.rand.nextGaussian() * 0.02D;
	      p_i50175_7_ = p_i50175_7_ + this.rand.nextGaussian() * 0.02D;
	      double d0 = (double)MathHelper.sqrt(p_i50175_3_ * p_i50175_3_ + p_i50175_5_ * p_i50175_5_ + p_i50175_7_ * p_i50175_7_);
	      this.accelerationX = p_i50175_3_ / d0 * 0.1D;
	      this.accelerationY = p_i50175_5_ / d0 * 0.1D;
	      this.accelerationZ = p_i50175_7_ / d0 * 0.1D;
	   }

 

Posted

ok I checked if the entity is null
 

and it is null, but that doesn't make sense because the constructor should set this.shootingEntity to the correct player

Posted

so in the writespawndata I can write down the entity with it's UniqueId or Id

 

but in the readSpawnData, how would I convert it back into an entity from it's id, or is there a way to write the LivingEntity into the buffer

Posted

It's still null, what am I doing wrong?
 

@Override
	public void writeSpawnData(PacketBuffer buffer) {
		buffer.writeInt(this.shootingEntity.getEntityId());
		
	}

	@Override
	public void readSpawnData(PacketBuffer additionalData) {
		this.shootingEntity=(LivingEntity) this.world.getEntityByID(additionalData.readInt());
	}

 

Posted
return NetworkHooks.getEntitySpawningPacket(this);


I overrided createSpawnPacket with this and now I see writeSpawnData from the server side, but readSpawnData doesn't do anything

Posted
[m[32m[08:59:51] [Server thread/INFO] [me.jo.be.BedrockThings/]: entitySpawningPacket created
[m[32m[08:59:51] [Server thread/INFO] [me.jo.be.BedrockThings/]: false writing
[m[32m[08:59:51] [Render thread/INFO] [me.jo.be.BedrockThings/]: true reading
[m[1;31m[08:59:51] [Render thread/FATAL] [minecraft/Minecraft]: Unreported exception thrown!
java.lang.NullPointerException: null
	at net.minecraft.client.renderer.entity.EntityRendererManager.shouldRender(EntityRendererManager.java:233) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.WorldRenderer.updateCameraAndRender(WorldRenderer.java:947) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.renderWorld(GameRenderer.java:612) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:434) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:961) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:558) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:177) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231] {}
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.1.0.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.1.0.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102) [forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar:?] {}

 

Posted

opened with debugger

[m[1;31m[09:07:28] [Server thread/ERROR] [minecraft/ChunkSerializer]: An Entity type net.minecraft.entity.EntityType@1d8ecb80 has thrown an exception trying to write state. It will not persist. Report this to the mod author
net.minecraft.crash.ReportedException: Saving entity NBT
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1562) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.Entity.writeUnlessRemoved(Entity.java:1467) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.entity.Entity.writeUnlessPassenger(Entity.java:1483) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.chunk.storage.ChunkSerializer.write(ChunkSerializer.java:302) ~[?:?] {re:classloading}
	at net.minecraft.world.server.ChunkManager.func_219229_a(ChunkManager.java:701) ~[?:?] {re:classloading}
	at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) [?:1.8.0_231] {}
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source) [?:1.8.0_231] {}
	at java.util.stream.ReferencePipeline.forEach(Unknown Source) [?:1.8.0_231] {}
	at net.minecraft.world.server.ChunkManager.save(ChunkManager.java:355) [?:?] {re:classloading}
	at net.minecraft.world.server.ServerChunkProvider.save(ServerChunkProvider.java:317) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.server.ServerWorld.save(ServerWorld.java:778) [?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.save(MinecraftServer.java:544) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:587) [?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:241) [?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:701) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_231] {}
Caused by: java.lang.NullPointerException
	at me.joshua.bedrockthings.util.AccurateProjectile.writeAdditional(AccurateProjectile.java:159) ~[?:?] {re:classloading}
	at net.minecraft.entity.Entity.writeWithoutTypeId(Entity.java:1541) ~[?:?] {re:classloading,pl:accesstransformer:B}

 

Posted
42 minutes ago, TallYate said:

Caused by: java.lang.NullPointerException at me.joshua.bedrockthings.util.AccurateProjectile.writeAdditional(AccurateProjectile.java:159) ~[?:?] {re:classloading}

Track that NPE down I'd say, based on the partial logs you've shown, figure out what's null and why, and fix it if it shouldn't be :)

Posted

I think this is what is crashing the game because if I removed the overrided createSpawnPacket, it doesn't crash, but the skull is invisible

@Override
	public void writeSpawnData(PacketBuffer buffer) {
		BedrockThings.log( (this.world.isRemote()) + " writing");
		buffer.writeInt(this.shootingEntity.getEntityId());
	}

	@Override
	public void readSpawnData(PacketBuffer additionalData) {
		BedrockThings.log( (this.world.isRemote()) + " reading");
		//this.shootingEntity=(LivingEntity) this.world.getEntityByID(additionalData.readInt());
	}
	
	public IPacket<?> createSpawnPacket() {
		BedrockThings.log("entitySpawningPacket created");
		return NetworkHooks.getEntitySpawningPacket(this);
	   }

 

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.