Skip to content
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
17 changes: 15 additions & 2 deletions src/main/java/com/simibubi/create/AllInteractionBehaviours.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@
import com.simibubi.create.api.behaviour.interaction.MovingInteractionBehaviour;
import com.simibubi.create.api.registry.SimpleRegistry;
import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction;
import com.simibubi.create.content.contraptions.behaviour.FenceGateMovingInteraction;
import com.simibubi.create.content.contraptions.behaviour.LeverMovingInteraction;
import com.simibubi.create.content.contraptions.behaviour.TrapdoorMovingInteraction;

import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Blocks;

public class AllInteractionBehaviours {
static void registerDefaults() {
MovingInteractionBehaviour.REGISTRY.register(Blocks.LEVER, new LeverMovingInteraction());

MovingInteractionBehaviour.REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(BlockTags.WOODEN_DOORS, new DoorMovingInteraction()));
MovingInteractionBehaviour.REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(BlockTags.MOB_INTERACTABLE_DOORS, new DoorMovingInteraction()));
MovingInteractionBehaviour.REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(BlockTags.WOODEN_TRAPDOORS, new TrapdoorMovingInteraction()));
MovingInteractionBehaviour.REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(BlockTags.FENCE_GATES, new TrapdoorMovingInteraction()));
MovingInteractionBehaviour.REGISTRY.registerProvider(SimpleRegistry.Provider.forBlockTag(BlockTags.FENCE_GATES, new FenceGateMovingInteraction()));

TrapdoorMovingInteraction copperTrapdoorInteraction =
new TrapdoorMovingInteraction(SoundEvents.COPPER_TRAPDOOR_OPEN, SoundEvents.COPPER_TRAPDOOR_CLOSE);
MovingInteractionBehaviour.REGISTRY.register(Blocks.COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.EXPOSED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.WEATHERED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.OXIDIZED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.WAXED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.WAXED_EXPOSED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.WAXED_WEATHERED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
MovingInteractionBehaviour.REGISTRY.register(Blocks.WAXED_OXIDIZED_COPPER_TRAPDOOR, copperTrapdoorInteraction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ protected BlockState handle(Player player, Contraption contraption, BlockPos pos
if (!(currentState.getBlock() instanceof DoorBlock))
return currentState;

boolean trainDoor = currentState.getBlock() instanceof SlidingDoorBlock;
SoundEvent sound = currentState.getValue(DoorBlock.OPEN) ? trainDoor ? null : SoundEvents.WOODEN_DOOR_CLOSE
: trainDoor ? SoundEvents.IRON_DOOR_OPEN : SoundEvents.WOODEN_DOOR_OPEN;
DoorBlock doorBlock = (DoorBlock) currentState.getBlock();
boolean slidingDoor = doorBlock instanceof SlidingDoorBlock;
boolean open = currentState.getValue(DoorBlock.OPEN);

SoundEvent sound = null;
if (slidingDoor) {
if (!open)
sound = SoundEvents.IRON_DOOR_OPEN;
} else {
sound = open ? doorBlock.type().doorClose() : doorBlock.type().doorOpen();
}

BlockPos otherPos = currentState.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER ? pos.above() : pos.below();
StructureBlockInfo info = contraption.getBlocks()
Expand All @@ -38,7 +46,7 @@ protected BlockState handle(Player player, Contraption contraption, BlockPos pos

if (player != null) {

if (trainDoor) {
if (slidingDoor) {
DoorHingeSide hinge = currentState.getValue(SlidingDoorBlock.HINGE);
Direction facing = currentState.getValue(SlidingDoorBlock.FACING);
BlockPos doublePos =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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.state.BlockState;
Expand All @@ -13,8 +12,9 @@ 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;
FenceGateBlock fenceGateBlock = (FenceGateBlock) currentState.getBlock();
SoundEvent sound = currentState.getValue(FenceGateBlock.OPEN) ? fenceGateBlock.closeSound
: fenceGateBlock.openSound;
float pitch = player.level().random.nextFloat() * 0.1F + 0.9F;
playSound(player, sound, pitch);
return currentState.cycle(FenceGateBlock.OPEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@

public class TrapdoorMovingInteraction extends SimpleBlockMovingInteraction {

private final SoundEvent openSound;
private final SoundEvent closeSound;

public TrapdoorMovingInteraction() {
this(SoundEvents.WOODEN_TRAPDOOR_OPEN, SoundEvents.WOODEN_TRAPDOOR_CLOSE);
}

public TrapdoorMovingInteraction(SoundEvent openSound, SoundEvent closeSound) {
this.openSound = openSound;
this.closeSound = closeSound;
}

@Override
protected BlockState handle(Player player, Contraption contraption, BlockPos pos, BlockState currentState) {
SoundEvent sound = currentState.getValue(TrapDoorBlock.OPEN) ? SoundEvents.WOODEN_TRAPDOOR_CLOSE
: SoundEvents.WOODEN_TRAPDOOR_OPEN;
SoundEvent sound = currentState.getValue(TrapDoorBlock.OPEN) ? closeSound : openSound;
float pitch = player.level().random.nextFloat() * 0.1F + 0.9F;
playSound(player, sound, pitch);
return currentState.cycle(TrapDoorBlock.OPEN);
Expand Down
Loading