mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
Merge branch 'dev' of https://github.com/Xiao-MoMi/craft-engine into dev
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.bukkit.block.entity;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.block.behavior.SeatBlockBehavior;
|
||||
import net.momirealms.craftengine.bukkit.entity.seat.BukkitSeat;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntity;
|
||||
@@ -14,8 +13,6 @@ import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class SeatBlockEntity extends BlockEntity implements SeatOwner {
|
||||
private final Seat<SeatBlockEntity>[] seats;
|
||||
|
||||
@@ -41,25 +38,20 @@ public class SeatBlockEntity extends BlockEntity implements SeatOwner {
|
||||
}
|
||||
|
||||
public boolean spawnSeat(Player player) {
|
||||
Optional<SeatBlockBehavior> seatBehavior = super.blockState.behavior().getAs(SeatBlockBehavior.class);
|
||||
if (seatBehavior.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
float yRot = 0;
|
||||
Property<HorizontalDirection> directionProperty = seatBehavior.get().directionProperty();
|
||||
if (directionProperty != null) {
|
||||
HorizontalDirection direction = super.blockState.get(directionProperty);
|
||||
if (direction == HorizontalDirection.NORTH) {
|
||||
yRot = 180;
|
||||
} else if (direction == HorizontalDirection.EAST) {
|
||||
yRot = -90;
|
||||
} else if (direction == HorizontalDirection.WEST) {
|
||||
yRot = 90;
|
||||
}
|
||||
Property<?> facing = super.blockState.owner().value().getProperty("facing");
|
||||
int yRot = 0;
|
||||
if (facing != null && facing.valueClass() == HorizontalDirection.class) {
|
||||
HorizontalDirection direction = (HorizontalDirection) super.blockState.get(facing);
|
||||
yRot = switch (direction) {
|
||||
case NORTH -> 0;
|
||||
case SOUTH -> 180;
|
||||
case WEST -> 270;
|
||||
case EAST -> 90;
|
||||
};
|
||||
}
|
||||
for (Seat<SeatBlockEntity> seat : this.seats) {
|
||||
if (!seat.isOccupied()) {
|
||||
if (seat.spawnSeat(player, new WorldPosition(super.world.world(), super.pos.x() + 0.5, super.pos.y(), super.pos.z() + 0.5, 0, 180 - yRot))) {
|
||||
if (seat.spawnSeat(player, new WorldPosition(super.world.world(), super.pos.x() + 0.5, super.pos.y(), super.pos.z() + 0.5, 0, yRot))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BukkitSeatManager implements SeatManager {
|
||||
public class BukkitSeatManager implements SeatManager, Listener {
|
||||
private static BukkitSeatManager instance;
|
||||
public static final NamespacedKey SEAT_KEY = KeyUtils.toNamespacedKey(SeatManager.SEAT_KEY);
|
||||
public static final NamespacedKey SEAT_EXTRA_DATA_KEY = KeyUtils.toNamespacedKey(SeatManager.SEAT_EXTRA_DATA_KEY);
|
||||
|
||||
Reference in New Issue
Block a user