-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v1.7.6] Merge pull request #270 from bridge-core/dev
- Loading branch information
Showing
2,018 changed files
with
13,446 additions
and
1,387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
declare module 'prismarine-nbt' { | ||
export interface Packet { | ||
type: string | ||
name: string | ||
value: Packet | Packet[] | string | number | boolean | ||
} | ||
export function parse( | ||
data: Buffer, | ||
littleEndian: boolean, | ||
callback: (error: Error, data: Packet) => void | ||
): void | ||
export function writeUncompressed( | ||
data: Packet, | ||
littleEndian: boolean | ||
): Buffer | ||
export function parseUncompressed( | ||
data: Buffer, | ||
littleEndian: boolean | ||
): Packet | ||
export function simplify(data: Packet): any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
declare module 'tga-js' { | ||
export default class TGALoader { | ||
load(uint8arr: Uint8Array): void | ||
open(filePath: string, onLoad: () => void): void | ||
getDataURL(mimeType: 'image/png'): string | ||
getImageData(imageData?: ImageData): ImageData | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<template> | ||
<div | ||
v-resize="onResize" | ||
ref="container" | ||
style="width: 100%;" | ||
class="canvas-container" | ||
> | ||
<canvas | ||
:height="availableHeight" | ||
:width="availableWidth" | ||
ref="canvas" | ||
/> | ||
|
||
<Hotbar class="canvas-overlay" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { loadStructure } from './load' | ||
import Hotbar from '../Voxel/Inventory/Hotbar.vue' | ||
let editor | ||
export default { | ||
name: 'StructureEditor', | ||
props: { | ||
availableHeight: Number, | ||
filePath: String, | ||
}, | ||
components: { | ||
Hotbar, | ||
}, | ||
async mounted() { | ||
editor = await loadStructure(this.filePath, this.$refs.canvas) | ||
this.onResize() | ||
editor.startRendering() | ||
}, | ||
data: () => ({ availableWidth: 0 }), | ||
activated() { | ||
editor.startRendering() | ||
}, | ||
deactivated() { | ||
editor.stopRendering() | ||
}, | ||
destroyed() { | ||
editor.stopRendering() | ||
}, | ||
methods: { | ||
onResize() { | ||
this.availableWidth = this.$refs.container.getBoundingClientRect().width | ||
if (editor !== undefined) | ||
editor.resize(this.availableWidth, this.availableHeight) | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
canvas:focus { | ||
outline: none; | ||
} | ||
.canvas-container { | ||
position: relative; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
.canvas-container canvas, | ||
.canvas-overlay { | ||
position: absolute; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { promises as fs } from 'fs' | ||
import nbt from 'prismarine-nbt' | ||
import { createErrorNotification } from '../../../AppCycle/Errors' | ||
import { createNotification } from '../../Footer/create' | ||
import { createInformationWindow } from '../../Windows/Common/CommonDefinitions' | ||
import { BlockLibrary } from '../Voxel/BlockLibrary/main' | ||
import { createVoxelEditor } from '../Voxel/create' | ||
|
||
export async function loadStructure( | ||
filePath: string, | ||
canvas: HTMLCanvasElement | ||
) { | ||
const rawStructure = await fs.readFile(filePath) | ||
const nbtStructure = nbt.parseUncompressed(rawStructure, true) | ||
const { | ||
format_version, | ||
size, | ||
structure, | ||
structure_world_origin, | ||
} = nbt.simplify(nbtStructure) | ||
const { entities, block_indices, palette } = structure | ||
const currentPalette = palette.default.block_palette | ||
|
||
//Warning notification - should be removed when this is fixed | ||
if (size[0] > 32 || size[2] > 32) { | ||
let structureWarning = createNotification({ | ||
icon: 'mdi-alert-circle-outline', | ||
message: 'Warning', | ||
color: 'error', | ||
textColor: 'white', | ||
onClick: () => { | ||
structureWarning.dispose() | ||
createInformationWindow( | ||
'Warning', | ||
'There is currentlty a bug in minecraft where large structures can be cut off when generated with features and feature rules. The limit seems to be 32x32 on the x and z axis, however this value is inconsistent and can sometimes be lower.' | ||
) | ||
}, | ||
}) | ||
} | ||
|
||
if (format_version !== 1) | ||
return createErrorNotification( | ||
new Error(`Unknown structure format version: ${format_version}`) | ||
) | ||
|
||
const editor = await createVoxelEditor(canvas, { | ||
chunkSize: Math.max(...(size as number[])), | ||
tileSize: 16, | ||
renderDistance: 12, | ||
limitedSize: true, | ||
}) | ||
const world = editor.getWorld() | ||
console.log(currentPalette) | ||
|
||
const layer1 = block_indices[0] | ||
for (let i = 0; i < layer1.length; i++) { | ||
if (layer1[i] === -1) continue | ||
|
||
const blockData = currentPalette[layer1[i]] | ||
world.setVoxel( | ||
Math.floor(i / (size[2] * size[1])), | ||
Math.floor(i / size[2]) % size[1], | ||
i % size[2], | ||
BlockLibrary.getRuntimeID(blockData.name) | ||
) | ||
} | ||
return editor | ||
} |
Oops, something went wrong.