Fence Gates on Trains

fixes Creators-of-Create#6354
This commit is contained in:
attackeight 2024-05-12 08:17:53 -04:00
parent d66170c8fe
commit 5ad844daf9
2 changed files with 40 additions and 0 deletions

View file

@ -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 {

View file

@ -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;
}
}