Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fence Gates on Trains #6482

Open
wants to merge 1 commit into
base: mc1.18/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/simibubi/create/AllInteractionBehaviours.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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;
Expand Down Expand Up @@ -75,6 +77,15 @@ static void registerDefaults() {
}
return null;
});

FenceGateMovingInteraction fenceGateBehavior = new FenceGateMovingInteraction();
registerBehaviourProvider(state -> {
if (state.is(BlockTags.FENCE_GATES)) {
return fenceGateBehavior;
}
return null;
});

}

public interface BehaviourProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}