Skip to content

Commit

Permalink
feat: add jutsu failed sounds and switch min-cast to -1 to differentiate
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed May 5, 2022
1 parent f71c906 commit 80b77b9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/main/java/com/sekwah/narutomod/abilities/Ability.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public long defaultCombo() {
*
* If this fails and is above 0 for charge amount the last successful will call perform.
*
* If channeled and chargeAmount is 0, it will either be a minCast (if enabled) or the stop packet is
* If channeled and chargeAmount is -1, it will either be a minCast (if enabled) or the stop packet is
* received at the same time. If this returns false then perform will not be called.
*
* @param player
Expand Down Expand Up @@ -82,6 +82,14 @@ public SoundEvent castingSound() {
return NarutoSounds.JUTSU_CAST.get();
}

/**
* Sound to play when an ability fails to cast.
* @return
*/
public SoundEvent castingFailSound() {
return NarutoSounds.JUTSU_FAIL.get();
}

public String getTranslationKey(INinjaData ninjaData) {
return this.getTranslationKey(ninjaData, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.sekwah.narutomod.abilities.Ability;
import com.sekwah.narutomod.capabilities.INinjaData;
import com.sekwah.narutomod.entity.SubstitutionLogEntity;
import com.sekwah.narutomod.sounds.NarutoSounds;
import net.minecraft.ChatFormatting;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
Expand All @@ -25,6 +28,11 @@ public long defaultCombo() {

@Override
public boolean handleCost(Player player, INinjaData ninjaData, int chargeAmount) {
if (ninjaData.getSubstitutionCount() < 1 && chargeAmount == -1) {
player.displayClientMessage(new TranslatableComponent("jutsu.fail.notenoughcharges", new TranslatableComponent(this.getTranslationKey(ninjaData)).withStyle(ChatFormatting.YELLOW)), true);
player.playNotifySound( NarutoSounds.JUTSU_FAIL.get(), SoundSource.PLAYERS, 0.5f, 1.0f);
return false;
}
return true;
}

Expand All @@ -42,7 +50,7 @@ public String getTranslationKey(INinjaData ninjaData, int ticksActive) {
*/
@Override
public void performServer(Player player, INinjaData ninjaData, int ticksActive) {
if(ticksActive == 0) {
if(ticksActive == -1) {
// Activate
ninjaData.useSubstitution(1);
Vec3 loc = ninjaData.getSubstitutionLoc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ public boolean logInChat() {
return false;
}

@Override
public SoundEvent castingSound() {
return null;
}

@Override
public SoundEvent castingFailSound() {
return null;
}

@Override
public boolean handleCost(Player player, INinjaData ninjaData, int chargeAmount) {
if(!player.isOnGround()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sekwah.narutomod.abilities.NarutoAbilities;
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler;
import com.sekwah.narutomod.capabilities.toggleabilitydata.ToggleAbilityData;
import com.sekwah.narutomod.sounds.NarutoSounds;
import net.minecraft.ChatFormatting;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.TranslatableComponent;
Expand Down Expand Up @@ -70,6 +71,8 @@ public static void handle(ServerAbilityActivatePacket msg, Supplier<NetworkEvent
if (ability instanceof Ability.Cooldown) {
((Ability.Cooldown) ability).registerCooldown(ninjaData, ability.getTranslationKey(ninjaData));
}
} else if(ability.castingFailSound() != null) {
player.playNotifySound( ability.castingFailSound(), SoundSource.PLAYERS, 0.5f, 1.0f);
}
} else if(ability.activationType() == Ability.ActivationType.TOGGLE) {
ToggleAbilityData abilityTracker = ninjaData.getToggleAbilityData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public static void handle(ServerAbilityChannelPacket msg, Supplier<NetworkEvent.
}
} else if(msg.status == ChannelStatus.MIN_ACTIVATE) {
if (ability instanceof Ability.Channeled channeled && channeled.canActivateBelowMinCharge()) {
if(ability.handleCost(player, ninjaData, 0)) {
if(ability.handleCost(player, ninjaData, -1)) {
if (ability.castingSound() != null) {
player.getLevel().playSound(null, player, ability.castingSound(), SoundSource.PLAYERS, 0.5f, 1.0f);
}
player.sendMessage(new TranslatableComponent("jutsu.cast", new TranslatableComponent(ability.getTranslationKey(ninjaData)).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.GREEN), player.getUUID());
ability.performServer(player, ninjaData, 0);
ability.performServer(player, ninjaData, -1);
}
} else {
player.sendMessage(new TranslatableComponent("jutsu.channel.needed", new TranslatableComponent(ability.getTranslationKey(ninjaData)).withStyle(ChatFormatting.YELLOW)).withStyle(ChatFormatting.RED), player.getUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class NarutoSounds {
public static final RegistryObject<SoundEvent> SEAL_C = register("seal_c");

public static final RegistryObject<SoundEvent> JUTSU_CAST = register("jutsu_cast");
public static final RegistryObject<SoundEvent> JUTSU_FAIL = register("jutsu_fail");

public static final RegistryObject<SoundEvent> FIREBALL_EXPLODE = register("fireball.explosion");
public static final RegistryObject<SoundEvent> FIREBALL_SHOOT = register("fireball.shoot");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/narutomod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"narutomod.subtitle.needle_hit": "Needle Hit",
"narutomod.subtitle.jutsu_seal": "Jutsu Seal",
"narutomod.subtitle.jutsu_cast": "Jutsu Cast",
"narutomod.subtitle.jutsu_fail": "Jutsu Fail",
"narutomod.subtitle.fireball.shoot": "Fireball Shoot",
"narutomod.subtitle.fireball.explosion": "Fireball Explosion",
"narutomod.subtitle.waterbullet.shoot": "Water Bullet Shoot",
Expand All @@ -62,6 +63,7 @@
"jutsu.fail.notonground": "You must be on the ground to use %s",
"jutsu.fail.notenoughstamina": "You do not have enough stamina to use %s",
"jutsu.fail.notenoughchakra": "You do not have enough chakra to use %s",
"jutsu.fail.notenoughcharges": "You do not have enough charges to use %s",
"ability.double_jump": "Double Jump",
"jutsu.leap": "Leap",
"jutsu.waterwalk": "Water Walking",
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/narutomod/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
],
"subtitle": "narutomod.subtitle.jutsu_cast"
},
"jutsu_fail": {
"sounds": [
"narutomod:jutsu/jutsu_fail"
],
"subtitle": "narutomod.subtitle.jutsu_fail"
},
"seal_c": {
"sounds": [
"narutomod:jutsu/seal_c"
Expand Down
Binary file not shown.

0 comments on commit 80b77b9

Please sign in to comment.