89 lines
2.8 KiB
Java
89 lines
2.8 KiB
Java
/*
|
|
* *
|
|
* * Copyright (c) 2025 R3944Realms. All rights reserved.
|
|
* *
|
|
* * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
|
* * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
* * or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
|
|
* *
|
|
* * 本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
|
|
*
|
|
*/
|
|
|
|
package top.r3944realms.eroticdungeongame.content.capability;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import top.r3944realms.eroticdungeongame.EroticDungeon;
|
|
import top.r3944realms.eroticdungeongame.content.register.EDGCapabilities;
|
|
import top.r3944realms.lib39.core.network.NetworkHandler;
|
|
import top.r3944realms.lib39.core.network.toClient.SyncNBTDataS2CPack;
|
|
import top.r3944realms.lib39.util.nbt.NBTReader;
|
|
import top.r3944realms.lib39.util.nbt.NBTWriter;
|
|
|
|
import java.util.UUID;
|
|
|
|
public final class PlayerDungeonData extends AbstractPlayerDungeonData {
|
|
public final String SEAT_ANIMATION_ID = "seat_animation_id";
|
|
public final String SEAT_ENTITY_ID = "seat_entity_id";
|
|
public final Player player;
|
|
public Integer seatAnimationId;
|
|
public Integer seatEntityId;
|
|
public PlayerDungeonData(Player player) {
|
|
super(EroticDungeon.rl(EDGCapabilities.DUNGEON_DATA));
|
|
this.player = player;
|
|
}
|
|
|
|
@Override
|
|
public CompoundTag serializeNBT() {
|
|
return NBTWriter.builder()
|
|
.intValue(SEAT_ANIMATION_ID, seatAnimationId)
|
|
.intValue(SEAT_ENTITY_ID, seatEntityId)
|
|
.build();
|
|
}
|
|
|
|
@Override
|
|
public void deserializeNBT(CompoundTag compoundTag) {
|
|
NBTReader.of(compoundTag)
|
|
.intValue(SEAT_ANIMATION_ID, i -> seatAnimationId = i)
|
|
.intValue(SEAT_ENTITY_ID, i -> seatEntityId = i);
|
|
}
|
|
|
|
@Override
|
|
public void checkIfDirtyThenUpdate() {
|
|
if (isDirty() && player instanceof ServerPlayer serverPlayer) {
|
|
NetworkHandler.sendToPlayer(new SyncNBTDataS2CPack(player.getId(), id(), this), serverPlayer);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public @NotNull UUID getPlayerUUID() {
|
|
return player.getUUID();
|
|
}
|
|
|
|
@Override
|
|
public Integer getSeatAnimId() {
|
|
return seatAnimationId;
|
|
}
|
|
|
|
@Override
|
|
public void setSeatAnimId(Integer seatAnimId) {
|
|
this.setSeatEntityId(seatAnimId);
|
|
makeDirty();
|
|
}
|
|
|
|
@Override
|
|
public Integer getSeatEntityId() {
|
|
return seatEntityId;
|
|
}
|
|
|
|
@Override
|
|
public void setSeatEntityId(Integer seatEntityId) {
|
|
seatAnimationId = seatEntityId;
|
|
makeDirty();
|
|
}
|
|
|
|
}
|