Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrcrayfish.guns.entity;

import com.mrcrayfish.guns.init.ModSounds;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
Expand All @@ -11,6 +12,7 @@
import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.EntityRayTraceResult;
Expand Down Expand Up @@ -106,7 +108,25 @@ protected void onImpact(RayTraceResult result)
double speed = this.getMotion().length();
if(speed > 0.1)
{
this.world.playSound(null, result.getHitVec().x, result.getHitVec().y, result.getHitVec().z, event, SoundCategory.AMBIENT, 1.0F, 1.0F);
float pitch = 1.4F + 0.2F * rand.nextFloat();
boolean hitStone = event == SoundEvents.BLOCK_STONE_STEP;
if(hitStone || event == SoundEvents.BLOCK_METAL_STEP || event == SoundEvents.BLOCK_ANVIL_STEP)
{
event = ModSounds.ENTITY_STUN_GRENADE_HIT_STONE.get();
if(!hitStone)
{
pitch += 0.5F;
}
}
else if(event == SoundEvents.BLOCK_GLASS_STEP)
{
event = ModSounds.ENTITY_STUN_GRENADE_HIT_GLASS.get();
}
else if(event == SoundEvents.BLOCK_WOOD_STEP || event == SoundEvents.BLOCK_LADDER_STEP)
{
event = ModSounds.ENTITY_STUN_GRENADE_HIT_WOOD.get();
}
this.world.playSound(null, result.getHitVec().x, result.getHitVec().y, result.getHitVec().z, event, SoundCategory.AMBIENT, (float) Math.min(1, speed), pitch);
}
Direction direction = blockResult.getFace();
switch(direction.getAxis())
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/mrcrayfish/guns/init/ModSounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public class ModSounds
public static final RegistryObject<SoundEvent> ITEM_MACHINE_PISTOL_FIRE = register("item.machine_pistol.fire");
public static final RegistryObject<SoundEvent> ITEM_MACHINE_PISTOL_SILENCED_FIRE = register("item.machine_pistol.silenced_fire");
public static final RegistryObject<SoundEvent> ITEM_GRENADE_PIN = register("item.grenade.pin");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_EXPLOSION = register("entity.stun_grenade.explosion");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_RING = register("entity.stun_grenade.ring");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_EXPLOSION = register("entity.grenade.stun.explosion");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_RING = register("entity.grenade.stun.ring");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_HIT_GLASS = register("entity.grenade.hit_glass");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_HIT_STONE = register("entity.grenade.hit_stone");
public static final RegistryObject<SoundEvent> ENTITY_STUN_GRENADE_HIT_WOOD = register("entity.grenade.hit_wood");
public static final RegistryObject<SoundEvent> UI_WEAPON_ATTACH = register("ui.weapon.attach");

private static RegistryObject<SoundEvent> register(String key)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/cgm/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"effect.cgm.deafened": "Deafened",
"subtitle.cgm.stun.explosion": "Stun grenade explosion",
"subtitle.cgm.stun.ring": "Ringing",
"subtitle.cgm.grenade.hit": "Grenade hit hard surface",
"subtitle.cgm.fire": "Gunfire",
"subtitle.cgm.fire.silenced": "Silenced gunfire",
"subtitle.cgm.reload": "Reloading",
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/assets/cgm/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
"item.machine_pistol.fire": { "subtitle": "subtitle.cgm.fire", "sounds": [{ "name": "cgm:item/machine_pistol/fire" }]},
"item.machine_pistol.silenced_fire": { "subtitle": "subtitle.cgm.fire.silenced", "sounds": [{ "name": "cgm:item/machine_pistol/silenced_fire" }]},
"item.grenade.pin": { "subtitle": "subtitle.cgm.grenade.pin", "sounds": [{ "name": "cgm:item/grenade/pin" }]},
"entity.stun_grenade.explosion": { "subtitle": "subtitle.cgm.stun.explosion", "sounds": [{ "name": "cgm:entity/stun_grenade/explosion" }]},
"entity.stun_grenade.ring": { "subtitle": "subtitle.cgm.stun.ring", "sounds": [{ "name": "cgm:entity/stun_grenade/ring", "stream": true }]},
"entity.grenade.stun.explosion": { "subtitle": "subtitle.cgm.stun.explosion", "sounds": [{ "name": "cgm:entity/grenade/stun/explosion" }]},
"entity.grenade.stun.ring": { "subtitle": "subtitle.cgm.stun.ring", "sounds": [{ "name": "cgm:entity/grenade/stun/ring", "stream": true }]},
"entity.grenade.hit_glass": { "subtitle": "subtitle.cgm.grenade.hit", "sounds": [{ "name": "cgm:entity/grenade/hit_glass" }]},
"entity.grenade.hit_stone": { "subtitle": "subtitle.cgm.grenade.hit", "sounds": [{ "name": "cgm:entity/grenade/hit_stone" }]},
"entity.grenade.hit_wood": { "subtitle": "subtitle.cgm.grenade.hit", "sounds": [{ "name": "cgm:entity/grenade/hit_wood" }]},
"ui.weapon.attach": { "subtitle": "subtitle.cgm.attach", "sounds": [{ "name": "cgm:ui/weapon/attach" }]}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.