Files
src
build.gradle
settings.gradle
Code
11 319
src/client/java/com/kodari/featherfallkills/FeatherfallKillsClient.java
package com.kodari.featherfallkills;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
public final class FeatherfallKillsClient implements ClientModInitializer {
private static final Set<Entity> FEATHERED_VICTIMS = Collections.newSetFromMap(new WeakHashMap<>());
@Override
public void onInitializeClient() {
ParticleFactoryRegistry.getInstance().register(FeatherfallKills.FEATHER, sprites ->
(effect, world, x, y, z, velocityX, velocityY, velocityZ, random) ->
new FeatherParticle(world, x, y, z, velocityX, velocityZ, sprites.getSprite(random))
);
ClientPlayNetworking.registerGlobalReceiver(FeatherBurstPayload.ID, (payload, context) -> {
ClientWorld world = context.client().world;
if (world == null) {
return;
}
Entity victim = world.getEntityById(payload.entityId());
if (victim != null) {
FEATHERED_VICTIMS.add(victim);
}
int count = Math.min(100, 48 + (int) (payload.width() * payload.height() * 12.0F));
for (int i = 0; i < count; i++) {
double angle = world.random.nextDouble() * Math.PI * 2.0;
double speed = 0.035 + world.random.nextDouble() * 0.055;
double x = payload.x() + (world.random.nextDouble() - 0.5) * payload.width() * 1.2;
double y = payload.y() + 0.1 + world.random.nextDouble() * payload.height() * 0.85;
double z = payload.z() + (world.random.nextDouble() - 0.5) * payload.width() * 1.2;
world.addParticleClient(FeatherfallKills.FEATHER, true, true,
x, y, z, Math.cos(angle) * speed, 0.0, Math.sin(angle) * speed);
}
world.playSoundClient(payload.x(), payload.y(), payload.z(),
SoundEvents.ENTITY_CHICKEN_EGG, SoundCategory.PLAYERS, 0.6F, 1.15F, true);
});
}
public static boolean shouldHide(Entity entity) {
return !entity.isAlive() && FEATHERED_VICTIMS.contains(entity);
}
}