generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/portingdeadmods/modjam/utils/ParticlesUtils.java
This file contains 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,39 @@ | ||
package com.portingdeadmods.modjam.utils; | ||
|
||
import net.minecraft.core.particles.ParticleOptions; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.level.Level; | ||
|
||
public class ParticlesUtils { | ||
|
||
private static final int PARTICLE_COUNT = 20; // Number of particles to spawn | ||
private static final double PARTICLE_RADIUS = 0.5; // Radius of the sphere around the item | ||
private static final int PARTICLE_DELAY = 5; // Number of ticks between particle spawns | ||
|
||
private int particleTicks = 0; | ||
|
||
public static void spawnParticles(ItemEntity itemEntity, Level level, ParticleOptions particlesTypes) { | ||
// Spawn particles around the item entity in a spherical pattern | ||
if (particleTicks % PARTICLE_DELAY == 0) { // Control particle spawn rate | ||
for (int i = 0; i < PARTICLE_COUNT; i++) { | ||
double theta = level.random.nextDouble() * Math.PI * 2; // Random angle | ||
double phi = level.random.nextDouble() * Math.PI; // Random angle | ||
|
||
// Spherical coordinates to Cartesian coordinates | ||
double xOffset = PARTICLE_RADIUS * Math.sin(phi) * Math.cos(theta); | ||
double yOffset = PARTICLE_RADIUS * Math.cos(phi); | ||
double zOffset = PARTICLE_RADIUS * Math.sin(phi) * Math.sin(theta); | ||
|
||
level.addParticle(particlesTypes, | ||
itemEntity.getX() + xOffset, | ||
itemEntity.getY() + yOffset, | ||
itemEntity.getZ() + zOffset, | ||
0, 0, 0); | ||
} | ||
} | ||
|
||
particleTicks++; | ||
} | ||
|
||
} |