fix: add block entities to .schem files
This commit is contained in:
parent
ade77b7ce6
commit
b5d3d75680
2 changed files with 42 additions and 5 deletions
|
|
@ -29,8 +29,8 @@ function SaveLitematic({ close }: DialogProps) {
|
||||||
// Fill in empty blocks with "air"
|
// Fill in empty blocks with "air"
|
||||||
const filledBlocks: Block[] = [];
|
const filledBlocks: Block[] = [];
|
||||||
|
|
||||||
for (let x = canvasSize.minX; x <= canvasSize.maxX - 1; x++) {
|
for (let x = canvasSize.minX; x < canvasSize.maxX; x++) {
|
||||||
for (let y = canvasSize.minY; y <= canvasSize.maxY - 1; y++) {
|
for (let y = canvasSize.minY; y < canvasSize.maxY; y++) {
|
||||||
const existingBlock = blocks.find((block) => block.x === x && block.y === y);
|
const existingBlock = blocks.find((block) => block.x === x && block.y === y);
|
||||||
if (existingBlock) {
|
if (existingBlock) {
|
||||||
filledBlocks.push(existingBlock);
|
filledBlocks.push(existingBlock);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,33 @@ import { Input } from "@/components/ui/input";
|
||||||
import _blockData from "@/data/blocks/data.json";
|
import _blockData from "@/data/blocks/data.json";
|
||||||
const blockData: BlockData = _blockData;
|
const blockData: BlockData = _blockData;
|
||||||
|
|
||||||
|
interface BlockEntity {
|
||||||
|
Id: string;
|
||||||
|
Pos: Int32Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blockEntitiesWhitelist = [
|
||||||
|
"barrel",
|
||||||
|
"beacon",
|
||||||
|
"bee",
|
||||||
|
"chiseled_bookshelf",
|
||||||
|
"command_block",
|
||||||
|
"crafter",
|
||||||
|
"creaking_heart",
|
||||||
|
"dispenser",
|
||||||
|
"dropper",
|
||||||
|
"furnace",
|
||||||
|
"jigsaw",
|
||||||
|
"spawner",
|
||||||
|
"piston",
|
||||||
|
"sculk",
|
||||||
|
"smoker",
|
||||||
|
"shulker",
|
||||||
|
"structure",
|
||||||
|
"suspicious",
|
||||||
|
"vault",
|
||||||
|
];
|
||||||
|
|
||||||
function SaveLitematic({ close }: DialogProps) {
|
function SaveLitematic({ close }: DialogProps) {
|
||||||
const { canvasSize, blocks } = useContext(CanvasContext);
|
const { canvasSize, blocks } = useContext(CanvasContext);
|
||||||
const { setLoading } = useContext(LoadingContext);
|
const { setLoading } = useContext(LoadingContext);
|
||||||
|
|
@ -26,11 +53,13 @@ function SaveLitematic({ close }: DialogProps) {
|
||||||
const width = canvasSize.maxX - canvasSize.minX;
|
const width = canvasSize.maxX - canvasSize.minX;
|
||||||
const height = canvasSize.maxY - canvasSize.minY;
|
const height = canvasSize.maxY - canvasSize.minY;
|
||||||
|
|
||||||
|
const blockEntities: BlockEntity[] = [];
|
||||||
|
|
||||||
// Fill in empty blocks with "air"
|
// Fill in empty blocks with "air"
|
||||||
const filledBlocks: Block[] = [];
|
const filledBlocks: Block[] = [];
|
||||||
|
|
||||||
for (let x = canvasSize.minX; x <= canvasSize.maxX - 1; x++) {
|
for (let x = canvasSize.minX; x < canvasSize.maxX; x++) {
|
||||||
for (let y = canvasSize.minY; y <= canvasSize.maxY - 1; y++) {
|
for (let y = canvasSize.minY; y < canvasSize.maxY; y++) {
|
||||||
const existingBlock = blocks.find((block) => block.x === x && block.y === y);
|
const existingBlock = blocks.find((block) => block.x === x && block.y === y);
|
||||||
if (existingBlock) {
|
if (existingBlock) {
|
||||||
filledBlocks.push(existingBlock);
|
filledBlocks.push(existingBlock);
|
||||||
|
|
@ -58,6 +87,13 @@ function SaveLitematic({ close }: DialogProps) {
|
||||||
.map(([key, value]) => `${key}=${value}`)
|
.map(([key, value]) => `${key}=${value}`)
|
||||||
.join(",")}]`
|
.join(",")}]`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
|
if (blockEntitiesWhitelist.some((i) => blockInfo.id.includes(i))) {
|
||||||
|
blockEntities.push({
|
||||||
|
Id: `minecraft:${blockInfo.id}`,
|
||||||
|
Pos: new Int32Array([block.x, block.y, 0]),
|
||||||
|
});
|
||||||
|
}
|
||||||
return `minecraft:${blockInfo.id}${properties}`;
|
return `minecraft:${blockInfo.id}${properties}`;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
@ -92,9 +128,10 @@ function SaveLitematic({ close }: DialogProps) {
|
||||||
Height: new nbt.Int16(height),
|
Height: new nbt.Int16(height),
|
||||||
Length: new nbt.Int16(1),
|
Length: new nbt.Int16(1),
|
||||||
Metadata: {
|
Metadata: {
|
||||||
Date: new Date().getTime(),
|
Date: BigInt(new Date().getTime()),
|
||||||
},
|
},
|
||||||
Blocks: {
|
Blocks: {
|
||||||
|
BlockEntities: blockEntities,
|
||||||
Data: blockPlaceData,
|
Data: blockPlaceData,
|
||||||
Palette: blockPalette,
|
Palette: blockPalette,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue