Skip to content

Commit 89c974e

Browse files
committed
Limit potion effect sounds to players
Fixes #8
1 parent 7df31a0 commit 89c974e

File tree

6 files changed

+52
-63
lines changed

6 files changed

+52
-63
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ buildscript {
1818
apply plugin: 'net.minecraftforge.gradle.forge'
1919
apply plugin: 'org.spongepowered.mixin'
2020

21-
version = '1.12.2-1.3.1'
21+
version = '1.12.2-1.3.2'
2222
group = 'mod.acgaming.extrasounds'
2323
archivesBaseName = 'ExtraSounds'
2424

src/main/java/mod/acgaming/extrasounds/ExtraSounds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ExtraSounds
1717
{
1818
public static final String MODID = "extrasounds";
1919
public static final String NAME = "Extra Sounds";
20-
public static final String VERSION = "1.12.2-1.3.1";
20+
public static final String VERSION = "1.12.2-1.3.2";
2121
public static final String DEPENDENCIES = "required-after:mixinbooter;required-after:assetmover;after:jei;after:asmc;after:dsurround";
2222
public static final Logger LOGGER = LogManager.getLogger(NAME);
2323
public static boolean asmc = false;

src/main/java/mod/acgaming/extrasounds/mixin/EntityLivingBaseMixin.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/main/java/mod/acgaming/extrasounds/mixin/EntityPlayerMixin.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package mod.acgaming.extrasounds.mixin;
22

3+
import net.minecraft.entity.EntityLivingBase;
34
import net.minecraft.entity.item.EntityItem;
45
import net.minecraft.entity.player.EntityPlayer;
56
import net.minecraft.item.ItemStack;
7+
import net.minecraft.potion.PotionEffect;
8+
import net.minecraft.world.World;
69

710
import mod.acgaming.extrasounds.config.ESConfig;
811
import mod.acgaming.extrasounds.sound.ESSoundEvents;
@@ -13,8 +16,13 @@
1316
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1417

1518
@Mixin(EntityPlayer.class)
16-
public class EntityPlayerMixin
19+
public abstract class EntityPlayerMixin extends EntityLivingBase
1720
{
21+
public EntityPlayerMixin(World worldIn)
22+
{
23+
super(worldIn);
24+
}
25+
1826
@Inject(at = @At("TAIL"), method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/item/EntityItem;")
1927
public void esDropItemSound(ItemStack droppedItem, boolean dropAround, boolean traceItem, CallbackInfoReturnable<EntityItem> cir)
2028
{
@@ -28,4 +36,42 @@ public void esDropItemSound(ItemStack droppedItem, boolean dropAround, boolean t
2836
}
2937
}
3038
}
39+
40+
@Override
41+
public void onNewPotionEffect(PotionEffect id)
42+
{
43+
super.onNewPotionEffect(id);
44+
if (ESConfig.soundToggles.esPotionSound)
45+
{
46+
if (id.getPotion().isBadEffect())
47+
{
48+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_add_negative, this.getPosition());
49+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_add_negative, this.getPosition());
50+
}
51+
else
52+
{
53+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_add_positive, this.getPosition());
54+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_add_positive, this.getPosition());
55+
}
56+
}
57+
}
58+
59+
@Override
60+
public void onFinishedPotionEffect(PotionEffect effect)
61+
{
62+
super.onFinishedPotionEffect(effect);
63+
if (ESConfig.soundToggles.esPotionSound)
64+
{
65+
if (effect.getPotion().isBadEffect())
66+
{
67+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_remove_negative, this.getPosition());
68+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_remove_negative, this.getPosition());
69+
}
70+
else
71+
{
72+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_remove_positive, this.getPosition());
73+
ESSoundManager.playSoundWorld(ESSoundEvents.effect_remove_positive, this.getPosition());
74+
}
75+
}
76+
}
3177
}

src/main/java/mod/acgaming/extrasounds/sound/ESSoundManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public static void playSoundPlayer(SoundEvent soundEvent)
203203

204204
public static void playSoundWorld(SoundEvent soundEvent, BlockPos blockPos, float pitch, float volume)
205205
{
206+
if (Minecraft.getMinecraft().world == null) return;
206207
long now = System.currentTimeMillis();
207208
if (now - lastPlayed > 5)
208209
{
@@ -213,6 +214,7 @@ public static void playSoundWorld(SoundEvent soundEvent, BlockPos blockPos, floa
213214

214215
public static void playSoundWorld(SoundEvent soundEvent, BlockPos blockPos)
215216
{
217+
if (Minecraft.getMinecraft().world == null) return;
216218
long now = System.currentTimeMillis();
217219
if (now - lastPlayed > 5)
218220
{

src/main/resources/extrasounds.mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"refmap": "extrasounds.refmap.json",
44
"minVersion": "0.8",
55
"compatibilityLevel": "JAVA_8",
6-
"mixins": ["BlockFlowerPotMixin", "BlockJukeboxMixin", "BlockPortalMixin", "EntityEnderPearlMixin", "EntityLivingBaseMixin", "EntityPlayerMixin", "InventoryPlayerMixin", "ItemBoatMixin", "ItemBowMixin", "ItemDyeMixin", "ItemMinecartMixin", "ItemMonsterPlacerMixin", "ItemSeedsMixin", "MobSpawnerBaseLogicMixin", "SlotCraftingMixin", "TileEntityBeaconMixin"],
6+
"mixins": ["BlockFlowerPotMixin", "BlockJukeboxMixin", "BlockPortalMixin", "EntityEnderPearlMixin", "EntityPlayerMixin", "InventoryPlayerMixin", "ItemBoatMixin", "ItemBowMixin", "ItemDyeMixin", "ItemMinecartMixin", "ItemMonsterPlacerMixin", "ItemSeedsMixin", "MobSpawnerBaseLogicMixin", "SlotCraftingMixin", "TileEntityBeaconMixin"],
77
"client": ["GuiContainerCreativeMixin", "GuiContainerMixin", "GuiInventoryMixin", "GuiNewChatMixin", "GuiRecipeBookMixin", "GuiScreenBookMixin", "GuiTextFieldMixin", "MinecraftMixin"]
88
}

0 commit comments

Comments
 (0)