EroticDungeonGame/src/main/java/top/r3944realms/eroticdungeongame/content/capability/AbstractPlayerDungeonData.java
2026-01-21 15:50:59 +08:00

62 lines
2.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright 2025-2026 R3944Realms
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.r3944realms.eroticdungeongame.content.capability;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.eroticdungeongame.api.capability.IPlayerDungeonData;
import top.r3944realms.eroticdungeongame.content.device.SeatType;
import top.r3944realms.eroticdungeongame.content.entity.SeatEntity;
import top.r3944realms.lib39.core.sync.NBTEntitySyncData;
import java.util.Objects;
//todo: 使用方块坐标代替UUID保存一致性
public sealed abstract class AbstractPlayerDungeonData extends NBTEntitySyncData implements IPlayerDungeonData permits PlayerDungeonData {
protected AbstractPlayerDungeonData(ResourceLocation id) {
super(id);
}
public void setDungeonData(@NotNull SeatType seatType, SeatEntity seat) {
setAnimationResourceLocation(Objects.requireNonNull(seatType.getAnimation(), "Seat Type has no animation.").getDefaultRL());
setDungeonData_(seat, seatType);
}
public void setDungeonData(@NotNull SeatType seatType, int varNumber, SeatEntity seat) {
setAnimationResourceLocation(Objects.requireNonNull(seatType.getAnimation(), "Seat Type has no animation.").getVarietyRL(varNumber));
setDungeonData_(seat, seatType);
}
public void clearDungeonData(@NotNull Player player) {
setDeviceMainBlockPos(null);
setAnimationResourceLocation(null);
setEyeHeight(-1.0f);
setPlayerBoundingBox(null);
AABB aabb = player.getDimensions(player.getPose()).makeBoundingBox(player.position());
player.setBoundingBox(aabb);
}
private void setDungeonData_(@NotNull SeatEntity seat, @NotNull SeatType type) {
setEyeHeight(type.getEyeHeight());
setPlayerBoundingBox(type.getPlayerBB());
setDeviceMainBlockPos(seat.getLinkedBlockPos());
}
}