Skip to content

Commit 96bd6c9

Browse files
committed
Fix doors not using custom open sounds when teleporting
1 parent e233f7e commit 96bd6c9

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/main/java/agency/highlysuspect/dokokashiradoor/client/OffsetEntityTrackingSoundInstance.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package agency.highlysuspect.dokokashiradoor.client;
22

33
import agency.highlysuspect.dokokashiradoor.Init;
4+
import agency.highlysuspect.dokokashiradoor.util.DoorUtil;
5+
import net.minecraft.block.BlockState;
46
import net.minecraft.client.sound.MovingSoundInstance;
57
import net.minecraft.entity.Entity;
68
import net.minecraft.entity.player.PlayerEntity;
@@ -25,11 +27,11 @@ public OffsetEntityTrackingSoundInstance(SoundEvent soundEvent, SoundCategory so
2527
updatePos();
2628
}
2729

28-
public static OffsetEntityTrackingSoundInstance doorOpen(PlayerEntity opener, BlockPos doorPos, Vec3d offset, Random random) {
30+
public static OffsetEntityTrackingSoundInstance doorOpen(PlayerEntity opener, BlockPos doorPos, BlockState doorState, Vec3d offset, Random random) {
2931
Vec3d offset2 = Vec3d.ofCenter(doorPos).subtract(opener.getPos());
3032

3133
return new OffsetEntityTrackingSoundInstance(
32-
SoundEvents.BLOCK_WOODEN_DOOR_OPEN,
34+
DoorUtil.getOpenSound(doorState),
3335
SoundCategory.BLOCKS,
3436
random,
3537
1f, //volume

src/main/java/agency/highlysuspect/dokokashiradoor/gateway/Gateway.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import net.minecraft.server.network.ServerPlayerEntity;
1919
import net.minecraft.server.world.ServerWorld;
2020
import net.minecraft.sound.SoundCategory;
21-
import net.minecraft.sound.SoundEvents;
2221
import net.minecraft.util.Identifier;
2322
import net.minecraft.util.math.BlockPos;
2423
import net.minecraft.util.math.Direction;
@@ -194,8 +193,8 @@ public void arrive(World world, Gateway departureGateway, PlayerEntity player) {
194193
//On the server, to *other players*, play the door opening sound from both doors.
195194
if(world instanceof ServerWorld sworld) {
196195
//playSound with a PlayerEntity argument skips that player
197-
sworld.playSound(player, departureGateway.doorTopPos, SoundEvents.BLOCK_WOODEN_DOOR_OPEN, SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
198-
sworld.playSound(player, this.doorTopPos, SoundEvents.BLOCK_WOODEN_DOOR_OPEN, SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
196+
sworld.playSound(player, departureGateway.doorTopPos, DoorUtil.getOpenSound(departureDoorState), SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
197+
sworld.playSound(player, this.doorTopPos, DoorUtil.getOpenSound(arrivalDoorState), SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
199198
}
200199
}
201200
}

src/main/java/agency/highlysuspect/dokokashiradoor/tp/ClientDoorTp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static boolean playerUseDoorClient(World world, BlockPos leftFromPos, Blo
5858
destination.arrive(world, thisGateway, player);
5959

6060
//4. Play the special clientside door-opening sound. This one follows the player around as they teleport.
61-
MinecraftClient.getInstance().getSoundManager().play(OffsetEntityTrackingSoundInstance.doorOpen(player, destination.doorTopPos(), null, world.random));
61+
MinecraftClient.getInstance().getSoundManager().play(OffsetEntityTrackingSoundInstance.doorOpen(player, destination.doorTopPos(), destination.doorBlock().getDefaultState(), null, world.random));
6262

6363
//5. Suppress sending a player-use-block packet.
6464
//This prevents the door from opening normally on the server.

src/main/java/agency/highlysuspect/dokokashiradoor/util/DoorUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import net.minecraft.block.BlockState;
55
import net.minecraft.block.DoorBlock;
66
import net.minecraft.entity.Entity;
7+
import net.minecraft.sound.SoundEvent;
8+
import net.minecraft.sound.SoundEvents;
79
import net.minecraft.util.math.BlockPos;
810
import net.minecraft.world.World;
911
import net.minecraft.world.event.GameEvent;
@@ -34,4 +36,12 @@ public static void sneakySwapHinge(World world, BlockPos doorTop, BlockState top
3436
public static void sneakySetBlockstate(World world, BlockPos pos, BlockState state) {
3537
world.setBlockState(pos, state, Block.NOTIFY_LISTENERS);
3638
}
39+
40+
public static SoundEvent getOpenSound(BlockState state) {
41+
if (state.getBlock() instanceof DoorBlock door) {
42+
return door.getBlockSetType().doorOpen();
43+
}
44+
45+
return SoundEvents.BLOCK_WOODEN_DOOR_OPEN;
46+
}
3747
}

0 commit comments

Comments
 (0)