Jump to content

[1.18.2] Spawn any lightning and create a custom one


ModCrafting

Recommended Posts

I'm starting with modding and I'm having a hard time spawning a lightning. Don't know if I'm doing something wrong here. I tried with a class extending from LightningBolt first, but can't spawn a vanilla one neither.

public static void SpawnLightning(Level level) {
	level.addFreshEntity(EntityType.LIGHTNING_BOLT.create(level));
	//level.addFreshEntity(Registry.UNSTABLE_LIGHTNING.get().create(level));
}

Is this supposed to be done differently? Also, my console is getting spammed with

[Render thread/ERROR] [minecraft/Util]: Entity lightningmobs:unstable_lightning has no attributes

Dunno why or how to fix it. This is how I am registering this.

public static final RegistryObject<EntityType<UnstableLightning>> UNSTABLE_LIGHTNING = ENTITIES.register(
	"unstable_lightning", (Supplier<? extends EntityType<UnstableLightning>>)
	() -> {
		EntityType.Builder<UnstableLightning> builder = EntityType.Builder.of(UnstableLightning::new, MobCategory.AMBIENT);
		EntityType<UnstableLightning> type = builder.build(new ResourceLocation(LMobs.MODID + ":unstable_lightning").toString());
		return type;
	}
);
Link to comment
Share on other sites

You are not setting the position for the lightning bolt entity. It is probably spawning at 0,0,0

Look at ServerLevel.tickChunk() for how vanilla does it.

I assume you are spawning it on the server?

 

See https://forge.gemwire.uk/wiki/Making_Entities for how to define the attributes for your entity and other things.

 

The parameter passed to build() is used by DFU (datafixerupper)

So it's pretty much irrelevant unless Mojang somehow know about your Entity and want to apply a fix to its persistent data. 🙂 

 

  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

59 minutes ago, warjort said:

You are not setting the position for the lightning bolt entity. It is probably spawning at 0,0,0

Look at ServerLevel.tickChunk() for how vanilla does it.

I assume you are spawning it on the server?

 

See https://forge.gemwire.uk/wiki/Making_Entities for how to define the attributes for your entity and other things.

 

The parameter passed to build() is used by DFU (datafixerupper)

So it's pretty much irrelevant unless Mojang somehow know about your Entity and want to apply a fix to its persistent data. 🙂 

 

Oh wow ok, but sending null to that last one was causing me a crash 😧
thanks a lot i'll test all of that

Link to comment
Share on other sites

2 hours ago, warjort said:

You are not setting the position for the lightning bolt entity. It is probably spawning at 0,0,0

Look at ServerLevel.tickChunk() for how vanilla does it.

I assume you are spawning it on the server?

 

See https://forge.gemwire.uk/wiki/Making_Entities for how to define the attributes for your entity and other things.

 

The parameter passed to build() is used by DFU (datafixerupper)

So it's pretty much irrelevant unless Mojang somehow know about your Entity and want to apply a fix to its persistent data. 🙂 

 

Ok now it crashed because entityrenderer is null, I expected it because I don't know what files I could need to make a model for a lightning, or how to grab vanilla one.

Link to comment
Share on other sites

Don't paraphrase errors. Show the full error message preferably by posting a link to the run/logs/debug.log

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.



×
×
  • Create New...

Important Information

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