-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from MrCrayfish/group-exporter
Group Exporter
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 MrCrayfish | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,12 @@ | ||
Group Exporter is a simple plugin that allows you to export groups from the outliner as a model. Only the cubes that are contained within the group will be exported. This plugin is only for the Java Block/Item format, and supporting custom formats. | ||
|
||
## How to use Group Exporter | ||
|
||
- **Step 1:** Select a group in the outliner | ||
- **Step 2:** Right click the group and hover the option "Export" | ||
- **Step 3:** Click the format you want to export as | ||
- **Step 4:** Follow the steps as you would normally when exporting | ||
|
||
## License | ||
|
||
Group Exporter is available under MIT |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,2 @@ | ||
maintainers: | ||
- MrCrayfish |
83 changes: 83 additions & 0 deletions
83
plugins/outliner_group_exporter/outliner_group_exporter.js
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,83 @@ | ||
(function() { | ||
var separator; | ||
var actionExportGroup; | ||
var originalExportFunction; | ||
BBPlugin.register('outliner_group_exporter', { | ||
title: 'Group Exporter', | ||
author: 'MrCrayfish', | ||
icon: 'icon.png', | ||
description: 'A simple plugin to allow you to export a group from the outliner as a model. Only cubes inside the group will be exported.', | ||
tags: ['Minecraft Java Edition'], | ||
version: '0.0.1', | ||
min_version: '4.10.1', | ||
variant: 'both', | ||
onload() { | ||
// Setup action and separator | ||
separator = new MenuSeparator('export'); | ||
actionExportGroup = { | ||
name: "Export", | ||
id: 'export_outliner_group', | ||
icon: 'insert_drive_file', | ||
category: 'export', | ||
// Only allow on java_block format or custom formats that can support it (e.g. ones that use Cubes) | ||
condition: () => Format.id === 'java_block' || Format.allowOutlinerGroupExporting, | ||
children() { | ||
return MenuBar.menus.file.structure.find(menu => menu.id === 'export')?.children; | ||
} | ||
}; | ||
|
||
// Append the separator and action to group menu | ||
Group.prototype.menu.addAction(separator); | ||
Group.prototype.menu.addAction(actionExportGroup); | ||
|
||
let restrictCubes = (restrict) => { | ||
if(!restrict) | ||
return; | ||
|
||
// Get the top parent group | ||
let group = getCurrentGroup(); | ||
|
||
// If none selected, just return | ||
if(!group) { | ||
return; | ||
} | ||
|
||
// Find children cubes in the group | ||
let selectedCubes = []; | ||
group.forEachChild(cube => { | ||
selectedCubes.push(cube); | ||
}, Cube, false); | ||
|
||
// Update export flag on all cubes | ||
Cube.all.forEach(cube => { | ||
cube.export = selectedCubes.includes(cube); | ||
}); | ||
} | ||
|
||
// Resets the export flag on all cubes | ||
let resetCubes = (restrict) => { | ||
if(!restrict) | ||
return; | ||
Cube.all.forEach(cube => { | ||
cube.export = true; | ||
}); | ||
} | ||
|
||
// Override export function | ||
originalExportFunction = Codec.prototype.export; | ||
Codec.prototype.export = async function () { | ||
// Check if the menu is open. Is this okay for web/mobile app? | ||
let restrict = Group.prototype.menu == Menu.open; | ||
restrictCubes(restrict); | ||
originalExportFunction.call(this); | ||
resetCubes(restrict); | ||
}; | ||
}, | ||
onunload() { | ||
// Clean up | ||
Codec.prototype.export = originalExportFunction; | ||
Group.prototype.menu.removeAction(separator); | ||
Group.prototype.menu.removeAction('export_outliner_group'); | ||
} | ||
}); | ||
})() |