Skip to content

Commit

Permalink
Play sound when metals are extinguished non-voluntarily
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jan 14, 2024
1 parent 66aa593 commit 501e80b
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package com.legobmw99.allomancy.modules.powers.client;

import com.legobmw99.allomancy.Allomancy;
import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.powers.data.AllomancerAttachment;
import com.legobmw99.allomancy.modules.powers.network.AllomancerDataPayload;
import com.legobmw99.allomancy.modules.powers.network.EnhanceTimePayload;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;

import java.util.Arrays;

public class ClientPayloadHandler {

public static void handleAllomancerData(final AllomancerDataPayload data, final PlayPayloadContext ctx) {
public static void handleAllomancerData(final AllomancerDataPayload payload, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
Minecraft.getInstance().level.getPlayerByUUID(data.player()).getData(AllomancerAttachment.ALLOMANCY_DATA).deserializeNBT(data.nbt());
Player player = Minecraft.getInstance().level.getPlayerByUUID(payload.player());
if (player == Minecraft.getInstance().player) {
var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA);
long burningBefore = Arrays.stream(Metal.values()).filter(data::isBurning).count();
data.deserializeNBT(payload.nbt());
long burningAfter = Arrays.stream(Metal.values()).filter(data::isBurning).count();
if (burningAfter < burningBefore) {
player.playSound(SoundEvent.createFixedRangeEvent(new ResourceLocation("block.fire.extinguish"), 1f), 1, 4);
}
} else {
player.getData(AllomancerAttachment.ALLOMANCY_DATA).deserializeNBT(payload.nbt());
}


}).exceptionally(e -> {
Allomancy.LOGGER.error("Failed to handle allomancerData update", e);
ctx.packetHandler().disconnect(Component.translatable("allomancy.networking.failed", e.getMessage()));
Expand Down

0 comments on commit 501e80b

Please sign in to comment.