Skip to content

Commit

Permalink
Weapon swoosh
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Feb 7, 2016
1 parent f7e1039 commit e0de981
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ archive = DynamicSurroundings
version.mod.major = 2
version.mod.minor = 0
version.mod.revis = 4
version.mod.patch = .4BETA
version.mod.patch = .5BETA

version.minecraft = 1.8.9
version.forge = 11.15.1.1732
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ private ModOptions() {
protected static int streamingSoundChannelCount = 4;
protected static final String CONFIG_ENABLE_JUMP_SOUND = "Jump Sound";
protected static boolean enableJumpSound = true;
protected static final String CONFIG_ENABLE_SWING_SOUND = "Swing Sound";
protected static boolean enableSwingSound = true;

protected static final String CATEGORY_PLAYER = "player";
protected static final String CONFIG_SUPPRESS_POTION_PARTICLES = "Suppress Potion Particles";
Expand Down Expand Up @@ -255,6 +257,9 @@ public static void load(final Configuration config) {
comment = "Enable sound effect when jumping";
enableJumpSound = config.getBoolean(CONFIG_ENABLE_JUMP_SOUND, CATEGORY_SOUND, enableJumpSound, comment);

comment = "Enable weapons swing sound effect when attacking";
enableSwingSound = config.getBoolean(CONFIG_ENABLE_SWING_SOUND, CATEGORY_SOUND, enableSwingSound, comment);

// CATEGORY: player.potion hud
comment = "Enable display of potion icons in display";
potionHudEnabled = config.getBoolean(CONFIG_POTION_HUD_ENABLE, CATEGORY_POTION_HUD, potionHudEnabled, comment);
Expand Down Expand Up @@ -396,6 +401,10 @@ public static int getNumberStreamingSoundChannels() {
public static boolean getEnableJumpSound() {
return enableJumpSound;
}

public static boolean getEnableSwingSound() {
return enableSwingSound;
}

public static boolean getSuppressPotionParticleEffect() {
return suppressPotionParticles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -56,8 +61,24 @@
@SideOnly(Side.CLIENT)
public class EnvironStateHandler implements IClientEffectHandler {

private static final SoundEffect JUMP = ModOptions.getEnableJumpSound()
? new SoundEffect("dsurround:jump", 0.2F, 1.0F, true) : null;
private static final SoundEffect JUMP;
private static final SoundEffect SWORD;
private static final SoundEffect AXE;

static {
if (ModOptions.getEnableJumpSound())
JUMP = new SoundEffect("dsurround:jump", 0.2F, 1.0F, true);
else
JUMP = null;

if (ModOptions.getEnableSwingSound()) {
SWORD = new SoundEffect("dsurround:swoosh", 1.0F, 1.0F);
AXE = new SoundEffect("dsurround:swoosh", 1.0F, 0.5F);
} else {
SWORD = null;
AXE = null;
}
}

// Diagnostic strings to display in the debug HUD
private static List<String> diagnostics = new ArrayList<String>();
Expand Down Expand Up @@ -320,6 +341,24 @@ public void onJump(final LivingJumpEvent event) {
if (JUMP != null && event.entity.worldObj.isRemote && EnvironState.isPlayer(event.entity))
PlayerSoundEffectHandler.playSoundAtPlayer(EnvironState.getPlayer(), JUMP, 0);
}

@SubscribeEvent
public void onItemUse(final AttackEntityEvent event) {
if(SWORD != null && event.entityPlayer.worldObj.isRemote && EnvironState.isPlayer(event.entityPlayer)) {
final ItemStack currentItem = event.entityPlayer.getCurrentEquippedItem();
if(currentItem != null) {
SoundEffect sound = null;
final Item item = currentItem.getItem();
if(item instanceof ItemSword)
sound = SWORD;
else if(item instanceof ItemAxe)
sound = AXE;

if(sound != null)
PlayerSoundEffectHandler.playSoundAtPlayer(EnvironState.getPlayer(), sound, 0);
}
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void diagnostics(final DiagnosticEvent.Gather event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ public float getZPosF() {
public String toString() {
return this.sound.toString();
}

@Override
public boolean equals(final Object anObj) {
if (this == anObj)
return true;
if (anObj instanceof PlayerSound)
return this.sameSound(((PlayerSound) anObj).sound);
if (anObj instanceof SoundEffect)
return this.sameSound((SoundEffect) anObj);
return false;
}

}

private static boolean didReloadOccur() {
Expand All @@ -205,15 +217,15 @@ private static boolean didReloadOccur() {
}
return false;
}

private int currentSoundCount() {
return Minecraft.getMinecraft().getSoundHandler().sndManager.playingSounds.size();
}

private int maxSoundCount() {
return SoundSystemConfig.getNumberNormalChannels() + SoundSystemConfig.getNumberStreamingChannels();
}

private boolean canFitSound() {
return currentSoundCount() < (maxSoundCount() - SOUND_QUEUE_SLACK);
}
Expand All @@ -227,17 +239,26 @@ private static void clearSounds() {
activeSounds.clear();
}

private static boolean isPlaying(final SoundEffect sound) {
private static boolean isActive(final SoundEffect sound) {
for (final PlayerSound s : activeSounds)
if (s.sameSound(sound))
if (s.equals(sound))
return true;
return false;
}

private static boolean isSoundQueued(final PlayerSound sound) {
final SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
return handler.isSoundPlaying(sound) || handler.sndManager.delayedSounds.containsKey(sound);
}

private static void playSound(final EntityPlayer player, final SoundEffect sound) {
final PlayerSound s = new PlayerSound(player, sound);
activeSounds.add(s);
Minecraft.getMinecraft().getSoundHandler().playSound(s);
try {
final PlayerSound s = new PlayerSound(player, sound);
Minecraft.getMinecraft().getSoundHandler().playSound(s);
activeSounds.add(s);
} catch (final Throwable t) {
;
}
}

public static void playSoundAtPlayer(EntityPlayer player, final SoundEffect sound, final int tickDelay) {
Expand Down Expand Up @@ -272,13 +293,15 @@ private static void processSounds(final EntityPlayer player, final List<SoundEff
if (!sounds.contains(sound.sound)) {
sound.fadeAway();
itr.remove();
} else if (!isSoundQueued(sound)) {
itr.remove();
}
}

// Add sounds from the incoming list that are not
// active.
for (final SoundEffect sound : sounds)
if (!isPlaying(sound))
if (!isActive(sound))
playSound(player, sound);
}

Expand All @@ -300,13 +323,13 @@ public void process(final World world, final EntityPlayer player) {
processSounds(player, sounds);

SoundEffect sound = null;
if(canFitSound()) {
if (canFitSound()) {
sound = BiomeRegistry.getSpotSound(playerBiome, conditions, RANDOM);
if (sound != null)
playSoundAtPlayer(player, sound, 0);
}

if(canFitSound()) {
if (canFitSound()) {
sound = BiomeRegistry.getSpotSound(BiomeRegistry.PLAYER, conditions, RANDOM);
if (sound != null)
playSoundAtPlayer(player, sound, 0);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/dsurround_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ public-f net.minecraft.world.World field_73011_w # provider
public net.minecraft.client.audio.SoundHandler field_147697_e # sndRegistry
public net.minecraft.client.audio.SoundHandler field_147694_f # sndManager
public net.minecraft.client.audio.SoundManager field_148629_h # playingSounds
public net.minecraft.client.audio.SoundManager field_148626_m # delayedSounds
12 changes: 12 additions & 0 deletions src/main/resources/assets/dsurround/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@
"ambient/bees/bees5"
]

},
"swoosh":{
"category":"ambient",
"sounds":[
"ambient/steve/swoosh1",
"ambient/steve/swoosh2",
"ambient/steve/swoosh3",
"ambient/steve/swoosh4",
"ambient/steve/swoosh5",
"ambient/steve/swoosh6"
]

}

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

0 comments on commit e0de981

Please sign in to comment.