Skip to content

Commit

Permalink
Add glowing particles
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Mar 4, 2025
1 parent 33cebe6 commit 23b3246
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 41 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/wenxin2/marioverse/MarioverseClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wenxin2.marioverse;

import com.wenxin2.marioverse.blocks.client.WarpPipeScreen;
import com.wenxin2.marioverse.client.particles.FirePoweredUpParticle;
import com.wenxin2.marioverse.client.particles.GlowingSuspendedTownParticle;
import com.wenxin2.marioverse.client.particles.LargeRewardParticle;
import com.wenxin2.marioverse.client.particles.MediumRewardParticle;
import com.wenxin2.marioverse.client.particles.NoMovementParticle;
Expand Down Expand Up @@ -117,7 +117,8 @@ private static void registerParticleProviders(RegisterParticleProvidersEvent eve
event.registerSpriteSet(ParticleRegistry.COIN_GLINT.get(), SuspendedTownParticle.HappyVillagerProvider::new);
event.registerSpriteSet(ParticleRegistry.EXCELLENT.get(), LargeRewardParticle::new);
event.registerSpriteSet(ParticleRegistry.FANTASTIC.get(), LargeRewardParticle::new);
event.registerSpriteSet(ParticleRegistry.FIRE_POWERED_UP.get(), FirePoweredUpParticle::new);
event.registerSpriteSet(ParticleRegistry.FIRE_POWERED_UP.get(), GlowingSuspendedTownParticle.FireProvider::new);
event.registerSpriteSet(ParticleRegistry.GLOWING_STAR.get(), GlowingSuspendedTownParticle.GlowingProvider::new);
event.registerSpriteSet(ParticleRegistry.GOOD.get(), RewardParticle::new);
event.registerSpriteSet(ParticleRegistry.GREAT.get(), MediumRewardParticle::new);
event.registerSpriteSet(ParticleRegistry.INCREDIBLE.get(), LargeRewardParticle::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ public void entityInside(BlockState state, Level world, BlockPos pos, Entity ent
checkpointFlagBE.markUpdated();

if (!(entity instanceof Player)) {
entity.level().broadcastEntityEvent(entity, (byte) 113); // Coin Glint TODO: add glowing star particle
} else ParticleUtils.spawnParticlesOnBlockFaces(world, statePos, ParticleRegistry.COIN_GLINT.get(), UniformInt.of(1, 1));
entity.level().broadcastEntityEvent(entity, (byte) 112);
} else ParticleUtils.spawnParticlesOnBlockFaces(world, statePos, ParticleRegistry.GLOWING_STAR.get(), UniformInt.of(1, 1));

if (!checkpointFlagBE.isAmericanFlag() && statePart.getBlock() != BlockRegistry.CLASSIC_GOAL_POLE.get())
checkpointFlagBE.triggerAnim("switch_controller", "switch");
Expand Down Expand Up @@ -591,14 +591,14 @@ public void entityInside(BlockState state, Level world, BlockPos pos, Entity ent
checkpointFlagBE.triggerAnim("claim_controller", "claim");

world.playSound(null, newRespawnPos, SoundRegistry.GOAL_POLE_FINISH.get(), SoundSource.BLOCKS); // TODO
ParticleUtils.spawnParticlesOnBlockFaces(world, newRespawnPos, ParticleRegistry.COIN_GLINT.get(), UniformInt.of(1, 1));
ParticleUtils.spawnParticlesOnBlockFaces(world, newRespawnPos, ParticleRegistry.GLOWING_STAR.get(), UniformInt.of(1, 1));
player.setRespawnPosition(world.dimension(), newRespawnPos, player.getYRot(), false, true);
player.getPersistentData().putInt("marioverse:claimed_checkpoint_flag_cooldown", 40);

if (world instanceof ServerLevel serverWorld)
serverWorld.sendParticles(ParticleRegistry.COIN_GLINT.get(),
if (world instanceof ServerLevel serverWorld)
serverWorld.sendParticles(ParticleRegistry.GLOWING_STAR.get(),
newRespawnPos.getX() + 0.5, newRespawnPos.getY() + 0.5, newRespawnPos.getZ() + 0.5,
10, 0.4, 0.4, 0.4, 0.2);
10, 0.4, 0.4, 0.4, 0.6);
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.wenxin2.marioverse.client.particles;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.GlowParticle;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.particle.SuspendedTownParticle;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.util.Mth;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;

@OnlyIn(Dist.CLIENT)
public class GlowingSuspendedTownParticle extends GlowParticle {
public GlowingSuspendedTownParticle(ClientLevel world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) {
super(world, x, y, z, xSpeed, ySpeed, zSpeed, spriteSet);
}

@NotNull
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}

@Override
public int getLightColor(float partialTick) {
float f = ((float)this.age + partialTick) / (float)this.lifetime;
f = Mth.clamp(f, 0.0F, 1.0F);
int i = super.getLightColor(partialTick);
int j = i & 0xFF;
int k = i >> 16 & 0xFF;
j += (int)(f * 15.0F * 16.0F);
if (j > 240) {
j = 240;
}

return j | k << 16;
}

@OnlyIn(Dist.CLIENT)
public static class FireProvider extends GlowParticle.WaxOffProvider {
private final SpriteSet sprite;
public FireProvider(SpriteSet spriteSet) {
super(spriteSet);
this.sprite = spriteSet;
}

@Override
public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
Particle particle = new GlowingSuspendedTownParticle(world, x, y, z, xSpeed, ySpeed, zSpeed, this.sprite);

particle.setColor(1.0F, 1.0F, 1.0F);
particle.scale(1.5F);
particle.setParticleSpeed(0.0, 0.0, 0.0);
return particle;
}
}

@OnlyIn(Dist.CLIENT)
public static class GlowingProvider extends GlowParticle.WaxOffProvider {
private final SpriteSet sprite;
public GlowingProvider(SpriteSet spriteSet) {
super(spriteSet);
this.sprite = spriteSet;
}

@Override
public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
Particle particle = new GlowingSuspendedTownParticle(world, x, y, z, xSpeed, ySpeed, zSpeed, this.sprite);

particle.setColor(1.0F, 1.0F, 1.0F);
particle.setLifetime(world.random.nextInt(30) + 10);
particle.setParticleSpeed(xSpeed * 0.02 / 2.0, ySpeed * 0.04, zSpeed * 0.02 / 2.0);
return particle;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.wenxin2.marioverse.entities.ai.goals.ShootBouncingFireballGoal;
import com.wenxin2.marioverse.init.ConfigRegistry;
import com.wenxin2.marioverse.init.KeybindRegistry;
import com.wenxin2.marioverse.init.ParticleRegistry;
import com.wenxin2.marioverse.init.SoundRegistry;
import com.wenxin2.marioverse.init.TagRegistry;
import com.wenxin2.marioverse.items.BaseCostumeItem;
Expand All @@ -22,6 +23,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.DamageTypeTags;
Expand Down Expand Up @@ -261,10 +263,16 @@ public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
Level world = player.level();
BlockState state = world.getBlockState(respawnPos);

if (state.getBlock() instanceof CheckpointFlagBlock
&& ConfigRegistry.CHECKPOINT_FLAG_MODIFY_HEALTH.get()) {
player.setHealth(ConfigRegistry.CHECKPOINT_FLAG_RESPAWN_HEALTH.get().floatValue());
player.getFoodData().setFoodLevel(ConfigRegistry.CHECKPOINT_FLAG_FOOD_AMT.get());
if (state.getBlock() instanceof CheckpointFlagBlock) {
if (ConfigRegistry.CHECKPOINT_FLAG_MODIFY_HEALTH.get()) {
player.setHealth(ConfigRegistry.CHECKPOINT_FLAG_RESPAWN_HEALTH.get().floatValue());
player.getFoodData().setFoodLevel(ConfigRegistry.CHECKPOINT_FLAG_FOOD_AMT.get());
}

if (world instanceof ServerLevel serverWorld)
serverWorld.sendParticles(ParticleRegistry.GLOWING_STAR.get(),
respawnPos.getX() + 0.5, respawnPos.getY() + 0.5, respawnPos.getZ() + 0.5,
10, 0.4, 0.4, 0.4, 0.6);
}

if (state.getBlock() instanceof CheckpointFlagBlock flagBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ParticleRegistry {
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> EXCELLENT;
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> FANTASTIC;
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> FIRE_POWERED_UP;
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> GLOWING_STAR;
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> GOOD;
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> GREAT;
public static final DeferredHolder<ParticleType<?>, SimpleParticleType> INCREDIBLE;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class ParticleRegistry {
EXCELLENT = Marioverse.PARTICLES.register("excellent", () -> new SimpleParticleType(false));
FANTASTIC = Marioverse.PARTICLES.register("fantastic", () -> new SimpleParticleType(false));
FIRE_POWERED_UP = Marioverse.PARTICLES.register("fire_powered_up", () -> new SimpleParticleType(false));
GLOWING_STAR = Marioverse.PARTICLES.register("glowing_star", () -> new SimpleParticleType(true));
GOOD = Marioverse.PARTICLES.register("good", () -> new SimpleParticleType(false));
GREAT = Marioverse.PARTICLES.register("great", () -> new SimpleParticleType(false));
INCREDIBLE = Marioverse.PARTICLES.register("incredible", () -> new SimpleParticleType(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ private void handleEntityEvent(byte id, CallbackInfo info) {
LivingEntity entity = (LivingEntity) (Object) this;
RandomSource random = entity.getRandom();

if (id == 113) {
if (id == 112) {
ParticleUtils.spawnParticlesOnBlockFaces(entity.level(), this.blockPosition(), ParticleRegistry.GLOWING_STAR.get(), UniformInt.of(1, 1));
} else if (id == 113) {
ParticleUtils.spawnParticlesOnBlockFaces(entity.level(), this.blockPosition(), ParticleRegistry.COIN_GLINT.get(), UniformInt.of(1, 1));
} else if (id == 114) {
this.marioverse$starParticles(entity, ParticleRegistry.COIN_GLINT.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"marioverse:glowing_star"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 23b3246

Please sign in to comment.