Skip to content

Commit

Permalink
one player per seat
Browse files Browse the repository at this point in the history
  • Loading branch information
bazke committed Oct 9, 2024
1 parent 1f1144a commit e77e441
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/lovetropics/extras/block/SeatBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import org.checkerframework.checker.units.qual.C;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class SeatBlock extends SlabBlock {

public static final MapCodec<SeatBlock> CODEC = simpleCodec(SeatBlock::new);
Expand All @@ -34,14 +37,21 @@ protected InteractionResult useWithoutItem(final BlockState state, final Level l
return InteractionResult.PASS;
}

if (level.isClientSide) {
return InteractionResult.SUCCESS;
}

final List<SeatEntity> foundSeats = level.getEntitiesOfClass(SeatEntity.class, new AABB(pos));

if (!foundSeats.isEmpty() && !foundSeats.stream().allMatch(seat -> seat.getPassengers().isEmpty())) {
return InteractionResult.FAIL;
}

final SeatEntity seatEntity = new SeatEntity(ExtraEntities.SEAT.get(), level);
seatEntity.setPos(pos.getX() + 0.5f, pos.getY(), pos.getZ() + 0.5f);
level.addFreshEntity(seatEntity);
player.startRiding(seatEntity);

System.out.println("sitter");


return InteractionResult.SUCCESS;
}

Expand Down

0 comments on commit e77e441

Please sign in to comment.