minecraft-src/net/minecraft/world/level/saveddata/maps/MapFrame.java
2025-07-04 01:41:11 +03:00

59 lines
1.4 KiB
Java

package net.minecraft.world.level.saveddata.maps;
import java.util.Optional;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import org.jetbrains.annotations.Nullable;
public class MapFrame {
private final BlockPos pos;
private final int rotation;
private final int entityId;
public MapFrame(BlockPos pos, int rotation, int entityId) {
this.pos = pos;
this.rotation = rotation;
this.entityId = entityId;
}
@Nullable
public static MapFrame load(CompoundTag compoundTag) {
Optional<BlockPos> optional = NbtUtils.readBlockPos(compoundTag, "pos");
if (optional.isEmpty()) {
return null;
} else {
int i = compoundTag.getInt("rotation");
int j = compoundTag.getInt("entity_id");
return new MapFrame((BlockPos)optional.get(), i, j);
}
}
public CompoundTag save() {
CompoundTag compoundTag = new CompoundTag();
compoundTag.put("pos", NbtUtils.writeBlockPos(this.pos));
compoundTag.putInt("rotation", this.rotation);
compoundTag.putInt("entity_id", this.entityId);
return compoundTag;
}
public BlockPos getPos() {
return this.pos;
}
public int getRotation() {
return this.rotation;
}
public int getEntityId() {
return this.entityId;
}
public String getId() {
return frameId(this.pos);
}
public static String frameId(BlockPos pos) {
return "frame-" + pos.getX() + "," + pos.getY() + "," + pos.getZ();
}
}