Skip to content

Commit

Permalink
BOOM (sounds)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Jan 8, 2025
1 parent bfb0fbf commit 8a60e0f
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"item.pswg_gadgets.thermal_detonator": "Thermal Detonator",
"item.pswg_gadgets.fragmentation_grenade": "Fragmentation Grenade",
"tag.block.pswg_gadgets.fragmentation_destroy": "Fragmenetation Grenade Destroy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"shared.arm": {
"subtitle": "subtitle.pswg_gadgets.arm",
"sounds": [
"pswg_gadgets:arm"
]
},
"shared.disarm": {
"subtitle": "subtitle.pswg_gadgets.disarm",
"sounds": [
"pswg_gadgets:disarm"
]
},
"shared.throw": {
"subtitle": "subtitle.pswg_gadgets.grenade_throw",
"sounds": [
"pswg_gadgets:throw"
]
},
"thermaldetonator.beep": {
"subtitle": "subtitle.pswg_gadgets.thermaldetonator.beep",
"sounds": [
"pswg_gadgets:tdet_beep_loop"
]
},
"thermaldetonator.explode": {
"subtitle": "subtitle.pswg_gadgets.thermaldetonator.explode",
"sounds": [
"pswg_gadgets:tdet_explosion"
]
},
"fragmentationgrenade.explode1": {
"subtitle": "subtitle.pswg_gadgets.fragmentationgrenade.explode",
"sounds": [
"pswg_gadgets:c25_explosion_1"
]
},
"fragmentationgrenade.explode2": {
"subtitle": "subtitle.pswg_gadgets.fragmentationgrenade.explode",
"sounds": [
"pswg_gadgets:c25_explosion_2"
]
},
"fragmentationgrenade.explode3": {
"subtitle": "subtitle.pswg_gadgets.fragmentationgrenade.explode",
"sounds": [
"pswg_gadgets:c25_explosion_3"
]
},
"fragmentationgrenade.explode4": {
"subtitle": "subtitle.pswg_gadgets.fragmentationgrenade.explode",
"sounds": [
"pswg_gadgets:c25_explosion_4"
]
},
"fragmentationgrenade.beep": {
"subtitle": "subtitle.pswg_gadgets.fragmentationgrenade.beep",
"sounds": [
"pswg_gadgets_gadgets:c25_beep_loop"
]
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 16 additions & 0 deletions projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;

Expand Down Expand Up @@ -89,6 +90,21 @@ public static Identifier id(String path)

public static final SimpleParticleType EXPLOSION_SMOKE_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("explosion_smoke"), FabricParticleTypes.simple());

public static final SoundEvent ARM = registerSound(id("shared.arm"));
public static final SoundEvent DISARM = registerSound(id("shared.disarm"));
public static final SoundEvent THROW = registerSound(id("shared.throw"));
public static final SoundEvent THERMAL_DETONATOR_BEEP = registerSound(id("thermaldetonator.beep"));
public static final SoundEvent THERMAL_DETONATOR_EXPLOSION = registerSound(id("thermaldetonator.explode"));
public static final SoundEvent FRAGMENTATION_GRENADE_EXPLOSION1 = registerSound(id("fragmentationgrenade.explode1"));
public static final SoundEvent FRAGMENTATION_GRENADE_EXPLOSION2 = registerSound(id("fragmentationgrenade.explode2"));
public static final SoundEvent FRAGMENTATION_GRENADE_EXPLOSION3 = registerSound(id("fragmentationgrenade.explode3"));
public static final SoundEvent FRAGMENTATION_GRENADE_EXPLOSION4 = registerSound(id("fragmentationgrenade.explode4"));
public static final SoundEvent FRAGMENTATION_GRENADE_BEEP = registerSound(id("fragmentationgrenade.beep"));

private static SoundEvent registerSound(Identifier id)
{
return Registry.register(Registries.SOUND_EVENT, id, SoundEvent.of(id));
}

@Override
public void onGalaxiesReady()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
Expand Down Expand Up @@ -67,14 +68,21 @@ public void explode()

int randomNum = Random.create().nextBetween(1, 4);

/*

switch (randomNum){
case 1: getWorld().playSound(null, getBlockPos(), SwgSounds.Explosives.FRAGMENTATION_GRENADE_EXPLOSION1, SoundCategory.PLAYERS, 4f, 1f); break;
case 2: getWorld().playSound(null, getBlockPos(), SwgSounds.Explosives.FRAGMENTATION_GRENADE_EXPLOSION2, SoundCategory.PLAYERS, 4f, 1f); break;
case 3: getWorld().playSound(null, getBlockPos(), SwgSounds.Explosives.FRAGMENTATION_GRENADE_EXPLOSION3, SoundCategory.PLAYERS, 4f, 1f); break;
case 4: getWorld().playSound(null, getBlockPos(), SwgSounds.Explosives.FRAGMENTATION_GRENADE_EXPLOSION4, SoundCategory.PLAYERS, 4f, 1f); break;
case 1:
getWorld().playSound(null, getBlockPos(), Gadgets.FRAGMENTATION_GRENADE_EXPLOSION1, SoundCategory.PLAYERS, 4f, 1f);
break;
case 2:
getWorld().playSound(null, getBlockPos(), Gadgets.FRAGMENTATION_GRENADE_EXPLOSION2, SoundCategory.PLAYERS, 4f, 1f);
break;
case 3:
getWorld().playSound(null, getBlockPos(), Gadgets.FRAGMENTATION_GRENADE_EXPLOSION3, SoundCategory.PLAYERS, 4f, 1f);
break;
case 4:
getWorld().playSound(null, getBlockPos(), Gadgets.FRAGMENTATION_GRENADE_EXPLOSION4, SoundCategory.PLAYERS, 4f, 1f);
break;
}
*/
}
}

Expand Down Expand Up @@ -135,7 +143,7 @@ public void tick()
}
if (EXPLOSION_TICK >= 15)
{
super.explode();
super.explode(new Vec3d(getX(), getY() + 0.1d, getZ()));
}
if (IS_EXPLODING)
EXPLOSION_TICK++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,17 @@ public boolean canHit()
}

public void explode()
{
Vec3d pos = new Vec3d(getX(), getY(), getZ());
explode(pos);
}

public void explode(Vec3d pos)
{
if (getWorld() instanceof ServerWorld serverWorld)
{
Vec3d pos = new Vec3d(getX(), getY(), getZ());
var explosion = new ExplosionImpl(serverWorld, this, getDamageSources().create(DamageTypes.EXPLOSION), (ExplosionBehavior)null, pos, getExplosionPower(), false, Explosion.DestructionType.DESTROY_WITH_DECAY);
explosion.explode();
//getWorld().createExplosion(this, (DamageSource)null, (ExplosionBehavior)null, this.getX(), this.getY() + 0.1f, this.getZ(), explosionPower, false, World.ExplosionSourceType.BLOCK);
createParticles(getX(), getY(), getZ(), serverWorld);
}
this.discard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
Expand Down Expand Up @@ -45,7 +46,7 @@ public GrenadeBlock getBlock()
@Override
public void explode()
{
//getWorld().playSound(null, getBlockPos(), SwgSounds.Explosives.THERMAL_DETONATOR_EXPLOSION, SoundCategory.PLAYERS, 4f, 1f);
getWorld().playSound(null, getBlockPos(), Gadgets.THERMAL_DETONATOR_EXPLOSION, SoundCategory.PLAYERS, 4f, 1f);
super.explode();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.pswg.item;

import dev.pswg.Gadgets;
import net.minecraft.entity.LivingEntity;

public abstract class ExplosionSoundGroup
{
public abstract void playArmSound(LivingEntity player);

public abstract void playDisarmSound(LivingEntity player);

public abstract void playThrowSound(LivingEntity player);

public abstract void playBeepingSound(LivingEntity player);
}

class ThermalDetonatorSoundGroup extends ExplosionSoundGroup
{

@Override
public void playArmSound(LivingEntity player)
{
player.playSound(Gadgets.ARM, 1f, 1f);
}

@Override
public void playDisarmSound(LivingEntity player)
{
player.playSound(Gadgets.DISARM, 1f, 1f);
}

@Override
public void playThrowSound(LivingEntity player)
{
player.playSound(Gadgets.THROW, 1f, 1f);
}

@Override
public void playBeepingSound(LivingEntity player)
{
//SoundHelper.playDetonatorItemSound(player);
}
}

class FragmentationGrenadeSoundGroup extends ExplosionSoundGroup
{

@Override
public void playArmSound(LivingEntity player)
{
player.playSound(Gadgets.ARM, 1f, 1f);
}

@Override
public void playDisarmSound(LivingEntity player)
{
player.playSound(Gadgets.DISARM, 1f, 1f);
}

@Override
public void playThrowSound(LivingEntity player)
{
player.playSound(Gadgets.THROW, 1f, 1f);
}

@Override
public void playBeepingSound(LivingEntity player)
{
//SoundHelper.playFragmentationGrenadeItemSound(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class FragmentationGrenadeItem extends GrenadeItem
{
public FragmentationGrenadeItem(Item.Settings settings)
{
super(settings, Gadgets.FRAGMENTATION_GRENADE_ITEM, 50);
super(settings, Gadgets.FRAGMENTATION_GRENADE_ITEM, 50, new FragmentationGrenadeSoundGroup());
}

@Override
Expand Down
18 changes: 10 additions & 8 deletions projects/pswg_gadgets/src/main/java/dev/pswg/item/GrenadeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class GrenadeItem extends Item implements ILeftClickUsable, ProjectileIte
{
public final int baseTicksToExplosion;
public final Item item;
//public final ExplosionSoundGroup sounds;
public final ExplosionSoundGroup sounds;

public GrenadeItem(Item.Settings settings, Item item, int baseTicksToExplosion)
public GrenadeItem(Item.Settings settings, Item item, int baseTicksToExplosion, ExplosionSoundGroup sounds)
{
super(settings);
this.item = item;
//this.sounds = sounds;
this.sounds = sounds;
this.baseTicksToExplosion = baseTicksToExplosion;
}

Expand Down Expand Up @@ -67,6 +67,9 @@ public void throwEntity(World world, ItemStack stack, PlayerEntity player)
grenade.setVelocity(player, player.getPitch(), player.getYaw(), (float)player.getRotationVector().z * 10, 1.0F, 0F);

world.spawnEntity(grenade);

if (world.isClient())
sounds.playThrowSound(player);
}

/**
Expand Down Expand Up @@ -234,19 +237,18 @@ public ActionResult useLeft(World world, LivingEntity user, Hand hand)
ItemStack stack = user.getMainHandStack();
if (!stack.contains(Gadgets.PRIMING_TIME))
{
if(user instanceof PlayerEntity player){
player.sendMessage(Text.of("Primed"), true);
}

stack.set(Gadgets.PRIMING_TIME, world.getTime());
if (world.isClient())
{

//sounds.playArmSound(user);
sounds.playArmSound(user);
//sounds.playBeepingSound(user);
}
}
else
{
if (world.isClient())
sounds.playArmSound(user);
stack.remove(Gadgets.PRIMING_TIME);
//sounds.playDisarmSound(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ThermalDetonatorItem extends GrenadeItem
{
public ThermalDetonatorItem(Item.Settings settings)
{
super(settings, Gadgets.THERMAL_DETONATOR_ITEM, 150);
super(settings, Gadgets.THERMAL_DETONATOR_ITEM, 150, new ThermalDetonatorSoundGroup());
}

@Override
Expand Down

0 comments on commit 8a60e0f

Please sign in to comment.