-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(world): occasional meteor shower sky effect #5388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
soloturn
wants to merge
1
commit into
develop
Choose a base branch
from
soloturn-meteor-shower-97
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
engine/src/main/java/org/terasology/engine/world/sun/MeteorShowerSystem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Copyright 2026 The Terasology Foundation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package org.terasology.engine.world.sun; | ||
|
|
||
| import org.joml.Vector3f; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.terasology.engine.entitySystem.entity.EntityBuilder; | ||
| import org.terasology.engine.entitySystem.entity.EntityManager; | ||
| import org.terasology.engine.entitySystem.entity.EntityRef; | ||
| import org.terasology.engine.entitySystem.systems.BaseComponentSystem; | ||
| import org.terasology.engine.entitySystem.systems.RegisterMode; | ||
| import org.terasology.engine.entitySystem.systems.RegisterSystem; | ||
| import org.terasology.engine.logic.location.LocationComponent; | ||
| import org.terasology.engine.network.Client; | ||
| import org.terasology.engine.network.ClientComponent; | ||
| import org.terasology.engine.network.NetworkSystem; | ||
| import org.terasology.engine.registry.In; | ||
| import org.terasology.engine.utilities.random.FastRandom; | ||
| import org.terasology.engine.utilities.random.Random; | ||
| import org.terasology.gestalt.entitysystem.event.ReceiveEvent; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Occasionally spawns a meteor shower - a brief burst of streaking particles above each connected player - | ||
| * when night falls. See https://github.com/MovingBlocks/Terasology/issues/97: a rare special-effect | ||
| * event in the sky, distinct from the constant day/night cycle. | ||
| * <p> | ||
| * The roll happens once per {@link OnDuskEvent}, i.e. at most once per night, matching the issue's own | ||
| * "rare, not constant" requirement. Position is per connected player rather than a single world-wide | ||
| * event, since {@code CoreAssets:meteorShowerParticleEffect} entities are ordinary world-space particle | ||
| * emitters (see {@link org.terasology.engine.particles.components.ParticleEmitterComponent}), not part of | ||
| * the sky dome itself - they need to be near enough each player to actually render. | ||
| */ | ||
| @RegisterSystem(RegisterMode.AUTHORITY) | ||
| public class MeteorShowerSystem extends BaseComponentSystem { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(MeteorShowerSystem.class); | ||
|
|
||
| private static final String METEOR_SHOWER_PREFAB = "CoreAssets:meteorShowerParticleEffect"; | ||
|
|
||
| /** Rolled once per night; keep it low; a meteor shower every single night stops being rare. */ | ||
| private static final float CHANCE_PER_NIGHT = 0.15f; | ||
|
|
||
| private static final int MIN_METEORS = 3; | ||
| private static final int MAX_METEORS = 7; | ||
|
|
||
| /** Spawn height above the player - high enough to read as "in the sky", not "over your head". */ | ||
| private static final float MIN_HEIGHT_OFFSET = 40f; | ||
| private static final float MAX_HEIGHT_OFFSET = 80f; | ||
|
|
||
| /** Horizontal spread around the player, so meteors don't all converge on one point overhead. */ | ||
| private static final float HORIZONTAL_SPREAD = 60f; | ||
|
|
||
| @In | ||
| private EntityManager entityManager; | ||
|
|
||
| @In | ||
| private NetworkSystem networkSystem; | ||
|
|
||
| private Random random; | ||
|
|
||
| @Override | ||
| public void initialise() { | ||
| random = new FastRandom(); | ||
| } | ||
|
|
||
| @ReceiveEvent | ||
| public void onDusk(OnDuskEvent event, EntityRef worldEntity) { | ||
| if (random.nextFloat() >= CHANCE_PER_NIGHT) { | ||
| return; | ||
| } | ||
|
|
||
| logger.debug("perfProbe meteorShower: starting tonight"); | ||
| for (Client client : networkSystem.getPlayers()) { | ||
| EntityRef character = client.getEntity().getComponent(ClientComponent.class).character; | ||
| LocationComponent location = character.getComponent(LocationComponent.class); | ||
| if (location == null) { | ||
| continue; | ||
| } | ||
| spawnShowerAround(location.getWorldPosition(new Vector3f())); | ||
| } | ||
| } | ||
|
|
||
| /** Public so tests can inspect exactly what a shower produced, against the real registered instance. */ | ||
| public List<EntityRef> spawnShowerAround(Vector3f playerPosition) { | ||
| List<EntityRef> spawned = new ArrayList<>(); | ||
| int meteorCount = random.nextInt(MIN_METEORS, MAX_METEORS + 1); | ||
| for (int i = 0; i < meteorCount; i++) { | ||
| Vector3f spawnPos = new Vector3f( | ||
| playerPosition.x + random.nextFloat(-HORIZONTAL_SPREAD, HORIZONTAL_SPREAD), | ||
| playerPosition.y + random.nextFloat(MIN_HEIGHT_OFFSET, MAX_HEIGHT_OFFSET), | ||
| playerPosition.z + random.nextFloat(-HORIZONTAL_SPREAD, HORIZONTAL_SPREAD)); | ||
|
|
||
| EntityBuilder meteorBuilder = entityManager.newBuilder(METEOR_SHOWER_PREFAB); | ||
| if (meteorBuilder.hasComponent(LocationComponent.class)) { | ||
| meteorBuilder.getComponent(LocationComponent.class).setWorldPosition(spawnPos); | ||
| spawned.add(meteorBuilder.build()); | ||
| } | ||
| } | ||
| return spawned; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Keep the horizontal offset within 60 blocks.
Lines 93 and 95 sample
xandzindependently. A meteor can spawn about 84.9 blocks away when both offsets are near 60. This exceeds the 60-block maximum in the PR objective.Sample a radial distance in
[0, HORIZONTAL_SPREAD]and an angle, or reject offsets outside the radius.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents