Skip to content

Commit 369efe7

Browse files
committed
Strange sounding door noises with double doors fixed
1 parent 2f4d665 commit 369efe7

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

common/src/main/java/net/adeptstack/Blocks/Behaviour/SlidingDoor/TrainSlidingDoorMovementBehaviour.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.simibubi.create.content.trains.station.GlobalStation;
1313
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
1414
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
15+
import net.adeptstack.Blocks.Doors.SlidingDoor.TrainSlidingDoorBlock;
1516
import net.adeptstack.Core.Utils.TrainSlidingDoorProperties;
1617
import net.adeptstack.Blocks.Doors.SlidingDoor.TrainSlidingDoorBlockEntity;
1718
import net.adeptstack.registry.TrainUtilitiesBuilderTransformers;
@@ -25,6 +26,7 @@
2526
import net.minecraft.world.level.block.DoorBlock;
2627
import net.minecraft.world.level.block.entity.BlockEntity;
2728
import net.minecraft.world.level.block.state.BlockState;
29+
import net.minecraft.world.level.block.state.properties.DoorHingeSide;
2830
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
2931
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
3032
import net.minecraft.world.phys.Vec3;
@@ -76,16 +78,32 @@ public void run() {
7678
}
7779
};
7880

79-
if (wasSettled && !sdbe.animation.settled() && !open) {
80-
context.world.playLocalSound(context.position.x, context.position.y, context.position.z,
81-
tsdp.GetClose(), SoundSource.BLOCKS, 1f, 1, false);
82-
}
81+
if (TrainSlidingDoorBlock.isDoubleDoor(structureBlockInfo.state().getValue(TrainSlidingDoorBlock.HINGE), context.localPos, context.state.getValue(TrainSlidingDoorBlock.FACING), context)) {
82+
if (structureBlockInfo.state().getValue(TrainSlidingDoorBlock.HINGE) == DoorHingeSide.RIGHT) {
83+
if (wasSettled && !sdbe.animation.settled() && !open) {
84+
context.world.playLocalSound(context.position.x, context.position.y, context.position.z,
85+
tsdp.GetClose(), SoundSource.BLOCKS, 1f, 1, false);
86+
}
8387

84-
if (wasSettled && !sdbe.animation.settled() && open) {
85-
context.world.playLocalSound(context.position.x, context.position.y, context.position.z,
86-
tsdp.GetOpen(), SoundSource.BLOCKS, 1f, 1, false);
87-
//Timer t = new Timer();
88-
//t.schedule(closeTask, 6000);
88+
if (wasSettled && !sdbe.animation.settled() && open) {
89+
context.world.playLocalSound(context.position.x, context.position.y, context.position.z,
90+
tsdp.GetOpen(), SoundSource.BLOCKS, 1f, 1, false);
91+
//Timer t = new Timer();
92+
//t.schedule(closeTask, 6000);
93+
}
94+
}
95+
} else {
96+
if (wasSettled && !sdbe.animation.settled() && !open) {
97+
context.world.playLocalSound(context.position.x, context.position.y, context.position.z,
98+
tsdp.GetClose(), SoundSource.BLOCKS, 1f, 1, false);
99+
}
100+
101+
if (wasSettled && !sdbe.animation.settled() && open) {
102+
context.world.playLocalSound(context.position.x, context.position.y, context.position.z,
103+
tsdp.GetOpen(), SoundSource.BLOCKS, 1f, 1, false);
104+
//Timer t = new Timer();
105+
//t.schedule(closeTask, 6000);
106+
}
89107
}
90108
}
91109

common/src/main/java/net/adeptstack/Blocks/Doors/SlidingDoor/TrainSlidingDoorBlock.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package net.adeptstack.Blocks.Doors.SlidingDoor;
22

3+
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
34
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock;
45
import com.simibubi.create.foundation.item.ItemDescription;
56
import com.simibubi.create.foundation.item.KineticStats;
67
import com.simibubi.create.foundation.item.TooltipHelper;
78
import com.simibubi.create.foundation.item.TooltipModifier;
89
import net.adeptstack.Core.Client.ClientWrapper;
10+
import net.adeptstack.Core.Utils.ScreenUtils.PlacementUtils;
911
import net.adeptstack.registry.ModBlockEntities;
1012
import net.minecraft.core.BlockPos;
13+
import net.minecraft.core.Direction;
1114
import net.minecraft.world.InteractionHand;
1215
import net.minecraft.world.InteractionResult;
1316
import net.minecraft.world.entity.player.Player;
@@ -19,7 +22,9 @@
1922
import net.minecraft.world.level.block.state.BlockState;
2023
import net.minecraft.world.level.block.state.StateDefinition;
2124
import net.minecraft.world.level.block.state.properties.BlockSetType;
25+
import net.minecraft.world.level.block.state.properties.DoorHingeSide;
2226
import net.minecraft.world.level.block.state.properties.IntegerProperty;
27+
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
2328
import net.minecraft.world.phys.BlockHitResult;
2429
import org.jetbrains.annotations.Nullable;
2530

@@ -43,6 +48,28 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
4348
pBuilder.add(DOOR_SOUND);
4449
}
4550

51+
public static boolean isDoubleDoor(DoorHingeSide hinge, BlockPos pos, Direction facing, MovementContext context) {
52+
if (hinge == DoorHingeSide.LEFT) {
53+
BlockPos posH2 = PlacementUtils.getPlaceDirectionLeft(pos, facing);
54+
StructureTemplate.StructureBlockInfo structureBlockInfo = context.contraption.getBlocks().get(posH2);
55+
if (structureBlockInfo == null)
56+
return false;
57+
if (structureBlockInfo.state().getValue(HINGE) == DoorHingeSide.RIGHT) {
58+
return structureBlockInfo.state().getBlock() instanceof TrainSlidingDoorBlock;
59+
}
60+
}
61+
else {
62+
BlockPos posH2 = PlacementUtils.getPlaceDirectionRight(pos, facing);
63+
StructureTemplate.StructureBlockInfo structureBlockInfo = context.contraption.getBlocks().get(posH2);
64+
if (structureBlockInfo == null)
65+
return false;
66+
if (structureBlockInfo.state().getValue(HINGE) == DoorHingeSide.LEFT) {
67+
return structureBlockInfo.state().getBlock() instanceof TrainSlidingDoorBlock;
68+
}
69+
}
70+
return false;
71+
}
72+
4673
@Override
4774
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
4875
if (!pPlayer.isShiftKeyDown()) {

0 commit comments

Comments
 (0)