forked from WildfireRomeo/WildfireFemaleGenderMod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client-sided hurt sounds, remove now redundant hurt packet
Fixes WildfireRomeo#83
- Loading branch information
1 parent
cf9fd80
commit b2abdc9
Showing
10 changed files
with
111 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Wildfire's Female Gender Mod is a female gender mod created for Minecraft. | ||
Copyright (C) 2022 WildfireRomeo | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.wildfire.mixins; | ||
|
||
import com.wildfire.main.GenderPlayer; | ||
import com.wildfire.main.WildfireGender; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.sound.SoundEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(LivingEntity.class) | ||
public class LivingEntityMixin { | ||
@Environment(EnvType.CLIENT) | ||
@Inject( | ||
method = "handleStatus", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/entity/LivingEntity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z" | ||
) | ||
) | ||
public void wildfiregender$clientGenderHurtSound(byte status, CallbackInfo ci) { | ||
if((LivingEntity)(Object)this instanceof PlayerEntity player) { | ||
// Only act on the client player; the server will send the hurt sound separately for other players | ||
// in the below mixin | ||
if(!player.world.isClient() || player != MinecraftClient.getInstance().player) return; | ||
wildfiregender$playHurtSound(player); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "damage", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/entity/LivingEntity;playHurtSound(Lnet/minecraft/entity/damage/DamageSource;)V" | ||
) | ||
) | ||
public void wildfiregender$serverGenderHurtSound(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) { | ||
if((LivingEntity)(Object)this instanceof PlayerEntity player) { | ||
// While this is never called client-side for the client player due to ClientPlayerEntity overriding this | ||
// method, it is called client-side for *other* players; as such, we need to check this to ensure we don't | ||
// play double hurt sounds when the mod is installed on the server as well. | ||
if(player.world.isClient()) return; | ||
wildfiregender$playHurtSound(player); | ||
} | ||
} | ||
|
||
private void wildfiregender$playHurtSound(PlayerEntity player) { | ||
GenderPlayer genderPlayer = WildfireGender.getPlayerById(player.getUuid()); | ||
if(genderPlayer == null) return; | ||
|
||
SoundEvent hurtSound = genderPlayer.getGender().getHurtSound(); | ||
if(hurtSound != null) { | ||
float pitch = (player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.2F + 1.0F; | ||
player.playSound(hurtSound, 1f, pitch); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
src/main/java/com/wildfire/mixins/PlayerEntityServerMixin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.