Skip to content

Commit 655297c

Browse files
committed
Fix sounds
1 parent 0055b30 commit 655297c

File tree

6 files changed

+69
-29
lines changed

6 files changed

+69
-29
lines changed

src/main/java/io/icker/factions/core/InteractionManager.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import net.minecraft.item.Item;
2727
import net.minecraft.item.ItemStack;
2828
import net.minecraft.item.ItemUsageContext;
29+
import net.minecraft.server.network.ServerPlayerEntity;
2930
import net.minecraft.util.ActionResult;
3031
import net.minecraft.util.Hand;
3132
import net.minecraft.util.hit.BlockHitResult;
@@ -61,7 +62,8 @@ private static boolean onBreakBlock(
6162
boolean result =
6263
checkPermissions(player, pos, world, Permissions.BREAK_BLOCKS) == ActionResult.FAIL;
6364
if (result) {
64-
InteractionsUtil.warn(player, InteractionsUtilActions.BREAK_BLOCKS);
65+
InteractionsUtil.warn(
66+
(ServerPlayerEntity) player, InteractionsUtilActions.BREAK_BLOCKS);
6567
}
6668
return !result;
6769
}
@@ -78,7 +80,7 @@ private static ActionResult onExplodeBlock(
7880
Permissions.BREAK_BLOCKS);
7981
if (result == ActionResult.FAIL) {
8082
InteractionsUtil.warn(
81-
(PlayerEntity) explosion.getCausingEntity(),
83+
(ServerPlayerEntity) explosion.getCausingEntity(),
8284
InteractionsUtilActions.BREAK_BLOCKS);
8385
}
8486
return result;
@@ -117,7 +119,7 @@ private static ActionResult onExplodeDamage(Explosion explosion, Entity entity)
117119
Permissions.ATTACK_ENTITIES);
118120
if (result == ActionResult.FAIL) {
119121
InteractionsUtil.warn(
120-
(PlayerEntity) explosion.getCausingEntity(),
122+
(ServerPlayerEntity) explosion.getCausingEntity(),
121123
InteractionsUtilActions.BREAK_BLOCKS);
122124
}
123125
return result;
@@ -151,16 +153,16 @@ private static ActionResult onUseBlock(
151153

152154
BlockPos hitPos = hitResult.getBlockPos();
153155
if (checkPermissions(player, hitPos, world, Permissions.USE_BLOCKS) == ActionResult.FAIL) {
154-
InteractionsUtil.warn(player, InteractionsUtilActions.USE_BLOCKS);
155-
InteractionsUtil.sync(player, stack, hand);
156+
InteractionsUtil.warn((ServerPlayerEntity) player, InteractionsUtilActions.USE_BLOCKS);
157+
InteractionsUtil.sync((ServerPlayerEntity) player, stack, hand);
156158
return ActionResult.FAIL;
157159
}
158160

159161
BlockPos placePos = hitPos.add(hitResult.getSide().getVector());
160162
if (checkPermissions(player, placePos, world, Permissions.USE_BLOCKS)
161163
== ActionResult.FAIL) {
162-
InteractionsUtil.warn(player, InteractionsUtilActions.USE_BLOCKS);
163-
InteractionsUtil.sync(player, stack, hand);
164+
InteractionsUtil.warn((ServerPlayerEntity) player, InteractionsUtilActions.USE_BLOCKS);
165+
InteractionsUtil.sync((ServerPlayerEntity) player, stack, hand);
164166
return ActionResult.FAIL;
165167
}
166168

@@ -174,8 +176,12 @@ private static ActionResult onPlaceBlock(ItemUsageContext context) {
174176
context.getWorld(),
175177
Permissions.PLACE_BLOCKS)
176178
== ActionResult.FAIL) {
177-
InteractionsUtil.warn(context.getPlayer(), InteractionsUtilActions.PLACE_BLOCKS);
178-
InteractionsUtil.sync(context.getPlayer(), context.getStack(), context.getHand());
179+
InteractionsUtil.warn(
180+
(ServerPlayerEntity) context.getPlayer(), InteractionsUtilActions.PLACE_BLOCKS);
181+
InteractionsUtil.sync(
182+
(ServerPlayerEntity) context.getPlayer(),
183+
context.getStack(),
184+
context.getHand());
179185
return ActionResult.FAIL;
180186
}
181187

@@ -189,8 +195,11 @@ private static ActionResult onUseBucket(PlayerEntity player, World world, Hand h
189195
ActionResult playerResult =
190196
checkPermissions(player, player.getBlockPos(), world, Permissions.PLACE_BLOCKS);
191197
if (playerResult == ActionResult.FAIL) {
192-
InteractionsUtil.warn(player, InteractionsUtilActions.PLACE_OR_PICKUP_LIQUIDS);
193-
InteractionsUtil.sync(player, player.getStackInHand(hand), hand);
198+
InteractionsUtil.warn(
199+
(ServerPlayerEntity) player,
200+
InteractionsUtilActions.PLACE_OR_PICKUP_LIQUIDS);
201+
InteractionsUtil.sync(
202+
(ServerPlayerEntity) player, player.getStackInHand(hand), hand);
194203
return ActionResult.FAIL;
195204
}
196205

@@ -206,16 +215,22 @@ private static ActionResult onUseBucket(PlayerEntity player, World world, Hand h
206215
BlockPos raycastPos = raycastResult.getBlockPos();
207216
if (checkPermissions(player, raycastPos, world, Permissions.PLACE_BLOCKS)
208217
== ActionResult.FAIL) {
209-
InteractionsUtil.warn(player, InteractionsUtilActions.PLACE_OR_PICKUP_LIQUIDS);
210-
InteractionsUtil.sync(player, player.getStackInHand(hand), hand);
218+
InteractionsUtil.warn(
219+
(ServerPlayerEntity) player,
220+
InteractionsUtilActions.PLACE_OR_PICKUP_LIQUIDS);
221+
InteractionsUtil.sync(
222+
(ServerPlayerEntity) player, player.getStackInHand(hand), hand);
211223
return ActionResult.FAIL;
212224
}
213225

214226
BlockPos placePos = raycastPos.add(raycastResult.getSide().getVector());
215227
if (checkPermissions(player, placePos, world, Permissions.PLACE_BLOCKS)
216228
== ActionResult.FAIL) {
217-
InteractionsUtil.warn(player, InteractionsUtilActions.PLACE_OR_PICKUP_LIQUIDS);
218-
InteractionsUtil.sync(player, player.getStackInHand(hand), hand);
229+
InteractionsUtil.warn(
230+
(ServerPlayerEntity) player,
231+
InteractionsUtilActions.PLACE_OR_PICKUP_LIQUIDS);
232+
InteractionsUtil.sync(
233+
(ServerPlayerEntity) player, player.getStackInHand(hand), hand);
219234
return ActionResult.FAIL;
220235
}
221236
}
@@ -230,7 +245,8 @@ private static ActionResult onAttackEntity(
230245
&& checkPermissions(
231246
player, entity.getBlockPos(), world, Permissions.ATTACK_ENTITIES)
232247
== ActionResult.FAIL) {
233-
InteractionsUtil.warn(player, InteractionsUtilActions.ATTACK_ENTITIES);
248+
InteractionsUtil.warn(
249+
(ServerPlayerEntity) player, InteractionsUtilActions.ATTACK_ENTITIES);
234250
return ActionResult.FAIL;
235251
}
236252

@@ -246,7 +262,8 @@ private static ActionResult onUseEntity(PlayerEntity player, Entity entity, Worl
246262
}
247263

248264
if (checkPermissions(player, pos, world, Permissions.USE_ENTITIES) == ActionResult.FAIL) {
249-
InteractionsUtil.warn(player, InteractionsUtilActions.USE_ENTITIES);
265+
InteractionsUtil.warn(
266+
(ServerPlayerEntity) player, InteractionsUtilActions.USE_ENTITIES);
250267
return ActionResult.FAIL;
251268
}
252269

@@ -256,7 +273,8 @@ private static ActionResult onUseEntity(PlayerEntity player, Entity entity, Worl
256273
private static ActionResult onUseInventory(PlayerEntity player, BlockPos pos, World world) {
257274
if (checkPermissions(player, pos, world, Permissions.USE_INVENTORIES)
258275
== ActionResult.FAIL) {
259-
InteractionsUtil.warn(player, InteractionsUtilActions.USE_INVENTORY);
276+
InteractionsUtil.warn(
277+
(ServerPlayerEntity) player, InteractionsUtilActions.USE_INVENTORY);
260278
return ActionResult.FAIL;
261279
}
262280

src/main/java/io/icker/factions/core/InteractionsUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import io.icker.factions.api.persistents.User;
44
import io.icker.factions.util.Message;
55

6-
import net.minecraft.entity.player.PlayerEntity;
76
import net.minecraft.item.ItemStack;
7+
import net.minecraft.server.network.ServerPlayerEntity;
88
import net.minecraft.text.Text;
99
import net.minecraft.util.Hand;
1010

1111
public class InteractionsUtil {
12-
public static void sync(PlayerEntity player, ItemStack itemStack, Hand hand) {
12+
public static void sync(ServerPlayerEntity player, ItemStack itemStack, Hand hand) {
1313
player.setStackInHand(hand, itemStack);
1414
itemStack.setCount(itemStack.getCount());
1515
if (itemStack.isDamageable()) {
@@ -21,7 +21,7 @@ public static void sync(PlayerEntity player, ItemStack itemStack, Hand hand) {
2121
}
2222
}
2323

24-
public static void warn(PlayerEntity player, InteractionsUtilActions action) {
24+
public static void warn(ServerPlayerEntity player, InteractionsUtilActions action) {
2525
SoundManager.warningSound(player);
2626
User user = User.get(player.getUuid());
2727
new Message(

src/main/java/io/icker/factions/core/SoundManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import io.icker.factions.api.events.FactionEvents;
55
import io.icker.factions.api.persistents.Faction;
66
import io.icker.factions.api.persistents.User;
7+
import io.icker.factions.util.GuiInteract;
78

8-
import net.minecraft.entity.player.PlayerEntity;
99
import net.minecraft.registry.entry.RegistryEntry;
1010
import net.minecraft.server.PlayerManager;
11+
import net.minecraft.server.network.ServerPlayerEntity;
1112
import net.minecraft.sound.SoundEvent;
1213
import net.minecraft.sound.SoundEvents;
1314

@@ -32,19 +33,19 @@ public static void register() {
3233
private static void playFaction(
3334
Faction faction, RegistryEntry.Reference<SoundEvent> soundEvent, float pitch) {
3435
for (User user : faction.getUsers()) {
35-
PlayerEntity player = FactionsManager.playerManager.getPlayer(user.getID());
36+
ServerPlayerEntity player = FactionsManager.playerManager.getPlayer(user.getID());
3637
if (player != null
3738
&& (user.sounds == User.SoundMode.ALL
3839
|| user.sounds == User.SoundMode.FACTION)) {
39-
player.playSound(soundEvent.value(), 0.2F, pitch);
40+
GuiInteract.playSound(player, soundEvent.value(), 0.2F, pitch);
4041
}
4142
}
4243
}
4344

44-
public static void warningSound(PlayerEntity player) {
45+
public static void warningSound(ServerPlayerEntity player) {
4546
User user = User.get(player.getUuid());
4647
if (user.sounds == User.SoundMode.ALL || user.sounds == User.SoundMode.WARNINGS) {
47-
player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_BASS.value(), 0.5F, 1.0F);
48+
GuiInteract.playSound(player, SoundEvents.BLOCK_NOTE_BLOCK_BASS.value(), 0.5F, 1.0F);
4849
}
4950
}
5051
}

src/main/java/io/icker/factions/ui/InputGui.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import eu.pb4.sgui.api.elements.GuiElementBuilder;
44
import eu.pb4.sgui.api.gui.AnvilInputGui;
55

6+
import io.icker.factions.util.GuiInteract;
7+
68
import net.minecraft.component.DataComponentTypes;
79
import net.minecraft.item.ItemStack;
810
import net.minecraft.item.Items;
@@ -47,7 +49,8 @@ public void showErrorMessage(MutableText text, int slotIndex) {
4749
item.set(
4850
DataComponentTypes.CUSTOM_NAME,
4951
text.setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.RED)));
50-
player.playSound(SoundEvent.of(Identifier.of("minecraft:item.shield.break")), 1, 1);
52+
GuiInteract.playSound(
53+
player, SoundEvent.of(Identifier.of("minecraft:item.shield.break")), 1f, 1f);
5154
timer.schedule(
5255
new TimerTask() {
5356
@Override

src/main/java/io/icker/factions/ui/PagedGui.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import eu.pb4.sgui.api.elements.GuiElementInterface;
77
import eu.pb4.sgui.api.gui.SimpleGui;
88

9+
import io.icker.factions.util.GuiInteract;
910
import io.icker.factions.util.Icons;
1011

1112
import net.minecraft.item.ItemStack;
@@ -208,6 +209,6 @@ public static DisplayElement empty() {
208209
}
209210

210211
public static final void playClickSound(ServerPlayerEntity player) {
211-
player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), 1, 1);
212+
GuiInteract.playSound(player, SoundEvents.UI_BUTTON_CLICK.value(), 1f, 1f);
212213
}
213214
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
package io.icker.factions.util;
22

3+
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
4+
import net.minecraft.registry.Registries;
35
import net.minecraft.server.network.ServerPlayerEntity;
6+
import net.minecraft.sound.SoundCategory;
47
import net.minecraft.sound.SoundEvent;
58
import net.minecraft.util.Identifier;
69

710
public class GuiInteract {
811
public static void playClickSound(ServerPlayerEntity player) {
9-
player.playSound(SoundEvent.of(Identifier.of("minecraft:ui.button.click")), 1, 1);
12+
playSound(player, SoundEvent.of(Identifier.of("minecraft:ui.button.click")), 1, 1);
13+
}
14+
15+
public static void playSound(
16+
ServerPlayerEntity player, SoundEvent sound, float volume, float pitch) {
17+
player.networkHandler.sendPacket(
18+
new PlaySoundS2CPacket(
19+
Registries.SOUND_EVENT.getEntry(sound),
20+
SoundCategory.UI,
21+
player.getX(),
22+
player.getY(),
23+
player.getZ(),
24+
volume,
25+
pitch,
26+
player.getRandom().nextLong()));
1027
}
1128
}

0 commit comments

Comments
 (0)