From 5ad844daf996a7d1363c6eda64550b871d8ce07c Mon Sep 17 00:00:00 2001 From: attackeight Date: Sun, 12 May 2024 08:17:53 -0400 Subject: [PATCH] Fence Gates on Trains fixes Creators-of-Create#6354 --- .../create/AllInteractionBehaviours.java | 11 +++++++ .../behaviour/FenceGateMovingInteraction.java | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/behaviour/FenceGateMovingInteraction.java diff --git a/src/main/java/com/simibubi/create/AllInteractionBehaviours.java b/src/main/java/com/simibubi/create/AllInteractionBehaviours.java index 31c518c5f..0c857e93d 100644 --- a/src/main/java/com/simibubi/create/AllInteractionBehaviours.java +++ b/src/main/java/com/simibubi/create/AllInteractionBehaviours.java @@ -3,6 +3,8 @@ package com.simibubi.create; import java.util.ArrayList; import java.util.List; +import com.simibubi.create.content.contraptions.behaviour.FenceGateMovingInteraction; + import org.jetbrains.annotations.Nullable; import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction; @@ -75,6 +77,15 @@ public class AllInteractionBehaviours { } return null; }); + + FenceGateMovingInteraction fenceGateBehavior = new FenceGateMovingInteraction(); + registerBehaviourProvider(state -> { + if (state.is(BlockTags.FENCE_GATES)) { + return fenceGateBehavior; + } + return null; + }); + } public interface BehaviourProvider { diff --git a/src/main/java/com/simibubi/create/content/contraptions/behaviour/FenceGateMovingInteraction.java b/src/main/java/com/simibubi/create/content/contraptions/behaviour/FenceGateMovingInteraction.java new file mode 100644 index 000000000..95510d99a --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/behaviour/FenceGateMovingInteraction.java @@ -0,0 +1,29 @@ +package com.simibubi.create.content.contraptions.behaviour; + +import com.simibubi.create.content.contraptions.Contraption; + +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.FenceGateBlock; +import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.level.block.state.BlockState; + +public class FenceGateMovingInteraction extends SimpleBlockMovingInteraction { + + @Override + protected BlockState handle(Player player, Contraption contraption, BlockPos pos, BlockState currentState) { + SoundEvent sound = currentState.getValue(FenceGateBlock.OPEN) ? SoundEvents.FENCE_GATE_CLOSE + : SoundEvents.FENCE_GATE_OPEN; + float pitch = player.level.random.nextFloat() * 0.1F + 0.9F; + playSound(player, sound, pitch); + return currentState.cycle(FenceGateBlock.OPEN); + } + + @Override + protected boolean updateColliders() { + return true; + } + +}