Skip to content

Commit

Permalink
Fix star coin particle spam
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Mar 5, 2025
1 parent eb6019c commit 305ad33
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/wenxin2/marioverse/blocks/StarCoinBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected void entityInside(BlockState state, Level world, BlockPos pos, Entity
boolean itemAdded = false;

world.playSound(null, pos, SoundRegistry.STAR_COIN_PICKUP.get(), SoundSource.BLOCKS);
removeCoinParts(world, partPos);
removeCoinPartsWithParticles(world, partPos, entity);

if (entity instanceof Player player) {
itemAdded = player.addItem(coinItem);
Expand Down Expand Up @@ -244,7 +244,7 @@ protected void onRemove(BlockState oldState, Level world, BlockPos pos, BlockSta
BlockPos partPos = this.getPartPos(pos, quadrant, half);
if (!world.isClientSide() && !(newState.getBlock() instanceof StarCoinBlock)) {
world.levelEvent(2001, partPos, Block.getId(world.getBlockState(partPos)));
this.removeCoinParts(world, partPos);
this.removeCoinPartsWithParticles(world, partPos, null);
}
super.onRemove(oldState, world, pos, newState, isMoving);
}
Expand All @@ -270,7 +270,7 @@ public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state,
if (!world.isClientSide) {
if (player.isCreative() || !player.hasCorrectToolForDrops(state, world, pos)) {
world.levelEvent(player, 2001, partPos, Block.getId(world.getBlockState(partPos)));
this.removeCoinParts(world, partPos);
this.removeCoinPartsWithParticles(world, partPos, player);
}
}
return super.playerWillDestroy(world, pos, state, player);
Expand Down Expand Up @@ -317,14 +317,14 @@ private boolean areCoinPartsPlaced(LevelReader world, BlockPos partPos) {
&& world.getBlockState(northWestPos.relative(Direction.SOUTH).relative(Direction.EAST).above()).canBeReplaced();
}

private void removeCoinParts(Level world, BlockPos pos) {
private void removeCoinPartsWithParticles(Level world, BlockPos pos, @Nullable Entity entity) {
BlockPos[] positions = {
pos, pos.east(), pos.south(), pos.south().east(),
pos.above(), pos.east().above(), pos.south().above(), pos.south().east().above()
};

for (BlockPos partPos : positions) {
if (world instanceof ServerLevel serverWorld)
if (world instanceof ServerLevel serverWorld && entity != null)
ServerParticleUtils.spawnParticlesOnBlockFaces(serverWorld, partPos, ParticleRegistry.COIN_GLINT.get(), UniformInt.of(1, 1));
world.removeBlock(partPos, false);
}
Expand Down

0 comments on commit 305ad33

Please sign in to comment.