Skip to content

Commit

Permalink
WIP blaster bolt flyby sound
Browse files Browse the repository at this point in the history
  • Loading branch information
parzivail committed Oct 17, 2023
1 parent d981b2b commit ea03e0b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 67 deletions.
2 changes: 2 additions & 0 deletions projects/pswg/src/main/java/com/parzivail/pswg/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.parzivail.pswg.client.screen.CrateGenericSmallScreen;
import com.parzivail.pswg.client.screen.CrateOctagonScreen;
import com.parzivail.pswg.client.screen.MoistureVaporatorScreen;
import com.parzivail.pswg.client.sound.EnvironmentSoundManager;
import com.parzivail.pswg.container.*;
import com.parzivail.pswg.entity.ship.ShipEntity;
import com.parzivail.pswg.features.blasters.BlasterItem;
Expand Down Expand Up @@ -160,6 +161,7 @@ public void onInitializeClient()

ClientTickEvents.START_CLIENT_TICK.register(KeyHandler::tick);
ClientTickEvents.START_CLIENT_TICK.register(BlasterRecoilManager::tick);
ClientTickEvents.START_CLIENT_TICK.register(EnvironmentSoundManager::tick);

ClientTickEvents.END_CLIENT_TICK.register(BlasterZoomHandler::tick);
ClientTickEvents.END_CLIENT_TICK.register(DebugUtil::tick);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.parzivail.pswg.client.sound;

import com.parzivail.pswg.entity.BlasterBoltEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.Box;

public class EnvironmentSoundManager
{
public static void tick(MinecraftClient mc)
{
if (mc.player == null || mc.world == null)
return;

var pos = mc.player.getEyePos();

var box = Box.of(mc.player.getPos(), 16, 16, 16);
for (var entity : mc.world.getEntitiesByClass(BlasterBoltEntity.class, box, e -> true))
{
var entityDirection = entity.getVelocity();

var newEntityPos = entity.getLerpedPos(1);

var oldPlayerDelta = entity.getLerpedPos(0).subtract(pos);
var newPlayerDelta = newEntityPos.subtract(pos);

var oldPlayerDot = entityDirection.dotProduct(oldPlayerDelta);
var newPlayerDot = entityDirection.dotProduct(newPlayerDelta);

if (oldPlayerDot >= 0 && newPlayerDot < 0)
{
// Entity transitioned from moving towards the
// player (i.e. pos-player vector and direction
// vector face the same direction) to away from
// the player (i.e. vectors point opposite
// directions)

mc.world.playSound(newEntityPos.x, newEntityPos.y, newEntityPos.z, SoundEvents.ENTITY_GHAST_SCREAM, SoundCategory.PLAYERS, 1, 1, true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.parzivail.pswg.client.sound;

import com.parzivail.pswg.features.blasters.client.BlasterBoltHissSoundInstance;
import com.parzivail.pswg.entity.BlasterBoltEntity;
import com.parzivail.pswg.features.lightsabers.client.ThrownLightsaberEntity;
import com.parzivail.pswg.entity.ship.ShipEntity;
import com.parzivail.pswg.features.lightsabers.client.ThrownLightsaberEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.sound.SoundEvent;
Expand All @@ -16,12 +14,6 @@ public static void playThrownLightsaberSound(ThrownLightsaberEntity entity)
minecraft.getSoundManager().play(new LightsaberThrownSoundInstance(entity));
}

public static void playBlasterBoltHissSound(BlasterBoltEntity entity)
{
var minecraft = MinecraftClient.getInstance();
minecraft.getSoundManager().play(new BlasterBoltHissSoundInstance(entity));
}

public static void playShipExteriorSound(ShipEntity entity, SoundEvent sound)
{
var minecraft = MinecraftClient.getInstance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.parzivail.pswg.entity;

import com.parzivail.pswg.Resources;
import com.parzivail.pswg.client.sound.SoundHelper;
import com.parzivail.pswg.container.SwgDamageTypes;
import com.parzivail.pswg.container.SwgPackets;
import com.parzivail.pswg.container.SwgParticles;
Expand Down Expand Up @@ -123,7 +122,6 @@ public Packet<ClientPlayPacketListener> createSpawnPacket()
public void onSpawnPacket(EntitySpawnS2CPacket packet)
{
super.onSpawnPacket(packet);
SoundHelper.playBlasterBoltHissSound(this);

if (packet instanceof PreciseEntitySpawnS2CPacket pes)
{
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit ea03e0b

Please sign in to comment.