Skip to content

Commit

Permalink
Fix doors not using custom open sounds when teleporting
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jul 5, 2024
1 parent e233f7e commit 96bd6c9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package agency.highlysuspect.dokokashiradoor.client;

import agency.highlysuspect.dokokashiradoor.Init;
import agency.highlysuspect.dokokashiradoor.util.DoorUtil;
import net.minecraft.block.BlockState;
import net.minecraft.client.sound.MovingSoundInstance;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -25,11 +27,11 @@ public OffsetEntityTrackingSoundInstance(SoundEvent soundEvent, SoundCategory so
updatePos();
}

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

return new OffsetEntityTrackingSoundInstance(
SoundEvents.BLOCK_WOODEN_DOOR_OPEN,
DoorUtil.getOpenSound(doorState),
SoundCategory.BLOCKS,
random,
1f, //volume
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down Expand Up @@ -194,8 +193,8 @@ public void arrive(World world, Gateway departureGateway, PlayerEntity player) {
//On the server, to *other players*, play the door opening sound from both doors.
if(world instanceof ServerWorld sworld) {
//playSound with a PlayerEntity argument skips that player
sworld.playSound(player, departureGateway.doorTopPos, SoundEvents.BLOCK_WOODEN_DOOR_OPEN, SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
sworld.playSound(player, this.doorTopPos, SoundEvents.BLOCK_WOODEN_DOOR_OPEN, SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
sworld.playSound(player, departureGateway.doorTopPos, DoorUtil.getOpenSound(departureDoorState), SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
sworld.playSound(player, this.doorTopPos, DoorUtil.getOpenSound(arrivalDoorState), SoundCategory.BLOCKS, 1f, world.random.nextFloat() * 0.1f + 0.9f);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static boolean playerUseDoorClient(World world, BlockPos leftFromPos, Blo
destination.arrive(world, thisGateway, player);

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

//5. Suppress sending a player-use-block packet.
//This prevents the door from opening normally on the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
Expand Down Expand Up @@ -34,4 +36,12 @@ public static void sneakySwapHinge(World world, BlockPos doorTop, BlockState top
public static void sneakySetBlockstate(World world, BlockPos pos, BlockState state) {
world.setBlockState(pos, state, Block.NOTIFY_LISTENERS);
}

public static SoundEvent getOpenSound(BlockState state) {
if (state.getBlock() instanceof DoorBlock door) {
return door.getBlockSetType().doorOpen();
}

return SoundEvents.BLOCK_WOODEN_DOOR_OPEN;
}
}

0 comments on commit 96bd6c9

Please sign in to comment.