Merge pull request #6482 from Attack8/mc1.18/gates-on-trains

Fence Gates on Trains
This commit is contained in:
simibubi 2024-07-16 16:24:40 +02:00 committed by GitHub
commit f29d26705c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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.ArrayList;
import java.util.List; import java.util.List;
import com.simibubi.create.content.contraptions.behaviour.FenceGateMovingInteraction;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction; import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction;
@ -75,6 +77,15 @@ public class AllInteractionBehaviours {
} }
return null; return null;
}); });
FenceGateMovingInteraction fenceGateBehavior = new FenceGateMovingInteraction();
registerBehaviourProvider(state -> {
if (state.is(BlockTags.FENCE_GATES)) {
return fenceGateBehavior;
}
return null;
});
} }
public interface BehaviourProvider { 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;
}
}