Skip to content

Commit

Permalink
fix: jutsu sounds are now detected by the warden and skulk
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Sep 11, 2022
1 parent 8ab9755 commit 6376861
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/sekwah/narutomod/NarutoMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sekwah.narutomod.commands.NarutoCommands;
import com.sekwah.narutomod.entity.NarutoDataSerialisers;
import com.sekwah.narutomod.entity.NarutoEntities;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.item.NarutoDispenseItemBehavior;
import com.sekwah.narutomod.item.NarutoItems;
import com.sekwah.narutomod.network.PacketHandler;
Expand Down Expand Up @@ -63,6 +64,7 @@ public NarutoMod() {
NarutoBlocks.register(eventBus);
NarutoEntities.register(eventBus);
NarutoAbilities.register(eventBus);
NarutoGameEvents.register(eventBus);

DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> NarutoInGameGUI::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.INinjaData;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.sounds.NarutoSounds;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -57,5 +58,7 @@ public void performServer(Player player, INinjaData ninjaData, int ticksActive)

player.getLevel().playSound(null,
player, NarutoSounds.DOUBLE_JUMP.get(), SoundSource.PLAYERS, 1f, 1.0f);

player.getLevel().gameEvent(player, NarutoGameEvents.DOUBLE_JUMP.get(), player.position());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.INinjaData;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.sounds.NarutoSounds;
import com.sekwah.sekclib.util.PlayerUtil;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -54,5 +55,6 @@ public void performServer(Player player, INinjaData ninjaData, int ticksActive)
, lookVector.z * horScale, true);
player.getLevel().playSound(null,
player, NarutoSounds.LEAP.get(), SoundSource.PLAYERS, 0.5f, 1.0f);
player.getLevel().gameEvent(player, NarutoGameEvents.LEAP.get(), player.position());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.toggleabilitydata.ToggleAbilityData;
import com.sekwah.narutomod.config.NarutoConfig;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.registries.NarutoRegistries;
import com.sekwah.sekclib.capabilitysync.capabilitysync.annotation.Sync;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -244,6 +245,7 @@ public void setCurrentlyChanneledAbility(Player player, Ability ability) {
if (ability != null) {
if (ability.castingSound() != null) {
player.getLevel().playSound(null, player, ability.castingSound(), SoundSource.PLAYERS, 0.5f, 1.0f);
player.getLevel().gameEvent(player, NarutoGameEvents.JUTSU_CASTING.get(), player.position().add(0, player.getEyeHeight() * 0.7, 0));
}

if(!(ability instanceof Ability.Channeled channeled && channeled.hideChannelMessages())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public static void gatherData(GatherDataEvent event) {
DataGenerator gen = event.getGenerator();

gen.addProvider(event.includeServer(), new RecipeGen(gen));
gen.addProvider(event.includeServer(), new NarutoGameEventTagGen(gen, event.getExistingFileHelper()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.sekwah.narutomod.datagen;

import com.sekwah.narutomod.NarutoMod;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.tags.GameEventTagsProvider;
import net.minecraft.tags.GameEventTags;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraftforge.common.data.ExistingFileHelper;

public class NarutoGameEventTagGen extends GameEventTagsProvider {
public NarutoGameEventTagGen(DataGenerator p_176826_, ExistingFileHelper existingFileHelper) {
super(p_176826_, NarutoMod.MOD_ID, existingFileHelper);
}

private void soundDetected(GameEvent event) {
this.tag(GameEventTags.WARDEN_CAN_LISTEN).add(event);
this.tag(GameEventTags.VIBRATIONS).add(event);
this.tag(GameEventTags.SHRIEKER_CAN_LISTEN).add(event);
}

protected void addTags() {
soundDetected(NarutoGameEvents.JUTSU_CASTING.get());
soundDetected(NarutoGameEvents.DOUBLE_JUMP.get());
soundDetected(NarutoGameEvents.LEAP.get());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sekwah.narutomod.gameevents;

import net.minecraft.core.Registry;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import static com.sekwah.narutomod.NarutoMod.MOD_ID;

public class NarutoGameEvents {

public static final DeferredRegister<GameEvent> GAME_EVENTS = DeferredRegister.create(Registry.GAME_EVENT_REGISTRY, MOD_ID);

public static final RegistryObject<GameEvent> JUTSU_CASTING = GAME_EVENTS.register("jutsu_casting", () -> wardenAlert("jutsu_casting"));

public static final RegistryObject<GameEvent> LEAP = GAME_EVENTS.register("leap", () -> wardenAlert("leap"));

public static final RegistryObject<GameEvent> DOUBLE_JUMP = GAME_EVENTS.register("double_jump", () -> wardenAlert("double_jump"));

public static GameEvent wardenAlert(String name) {
return new GameEvent(name, 16);
}


public static void register(IEventBus eventBus) {
GAME_EVENTS.register(eventBus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler;
import com.sekwah.narutomod.capabilities.toggleabilitydata.ToggleAbilityData;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.registries.NarutoRegistries;
import net.minecraft.ChatFormatting;
import net.minecraft.network.FriendlyByteBuf;
Expand Down Expand Up @@ -64,6 +65,7 @@ public static void handle(ServerAbilityActivatePacket msg, Supplier<NetworkEvent
if(ability.castingSound() != null) {
player.getLevel().playSound(null,
player, ability.castingSound(), SoundSource.PLAYERS, 0.5f, 1.0f);
player.getLevel().gameEvent(player, NarutoGameEvents.JUTSU_CASTING.get(), player.position().add(0, player.getEyeHeight() * 0.7, 0));
}
ability.performServer(player, ninjaData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.logging.LogUtils;
import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler;
import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.registries.NarutoRegistries;
import net.minecraft.ChatFormatting;
import net.minecraft.network.FriendlyByteBuf;
Expand Down Expand Up @@ -77,6 +78,8 @@ public static void handle(ServerAbilityChannelPacket msg, Supplier<NetworkEvent.
if(ability.handleCost(player, ninjaData, -1)) {
if (ability.castingSound() != null) {
player.getLevel().playSound(null, player, ability.castingSound(), SoundSource.PLAYERS, 0.5f, 1.0f);

player.getLevel().gameEvent(player, NarutoGameEvents.JUTSU_CASTING.get(), player.position().add(0, player.getEyeHeight() * 0.7, 0));
}
player.displayClientMessage(Component.translatable("jutsu.cast", Component.translatable(ability.getTranslationKey(ninjaData)).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), false);
ability.performServer(player, ninjaData, -1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sekwah.narutomod.network.c2s;

import com.sekwah.narutomod.gameevents.NarutoGameEvents;
import com.sekwah.narutomod.sounds.NarutoSounds;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -48,6 +49,7 @@ public static void handle(ServerJutsuCastingPacket msg, Supplier<NetworkEvent.Co
player.getCommandSenderWorld().playSound(null,
player.getX(), player.getY(), player.getZ(),
playSound, SoundSource.PLAYERS, 1.0f, 1.0f);
player.getLevel().gameEvent(player, NarutoGameEvents.JUTSU_CASTING.get(), player.position().add(0, player.getEyeHeight() * 0.7, 0));
}
}
});
Expand Down

0 comments on commit 6376861

Please sign in to comment.