Skip to content

Updates for Minecraft release 1.21.80-preview.28 #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ If you don't, then the samples won't be visible to the `Minecraft Bedrock Previe
| Portal Generator | Adds a dialog that allows you to place either Nether or End portals (in various states of completion).<br><br>This extension demonstrates dynamic UI component updates, and block placement.<br><br>**Notes**: Activated using CTRL+SHIFT+P or from tool rail.<br>**Author**: Andrew. |
| Simple Empty | Adds an extension which as a very basic set of barely functional components designed to demonstrate setting up a new Editor tool using the Simple Tool wrapper. The extension demonstrates how to set up the data definitions that will ultimately direct how the tool registers itself with the Editor, and sets up the visual layouts - ready for the creator to fill in the functionality.<br> **Author**: Dave |
| Simple Locate Biome | Adds an extension which demonstrates the use of sub-panes to group together UI controls, and uses the visibility of those sub-panes to create different views of data. The extension also demonstrates the use of the mutually exclusive visibility properties of sub-panes, and some use of the Biome API.<br> **Author**: Dave & Mitch |
| Star Brush Shape | Adds a brush shape 'Star' to the new brush shape manager.<br> **Author**: Gordon |
| Tree Generator | Adds a dialog that allows you to place a selection of randomized trees of certain types wherever you click in the world.<br><br>This extension demonstrates the use of UI components, block placement and mouse input.<br><br>**Notes**: Activated using CTRL+SHIFT+T or through the tool rail.<br>**Author**: Jake || | |


Expand Down
5 changes: 2 additions & 3 deletions camera-grapple/camera-grapple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ export function registerCameraGrapple() {
if (uiSession.scratchStorage?.latestRunId) {
return;
}
const selection = uiSession.extensionContext.selectionManager.selection;
if (selection.isEmpty) {
if (uiSession.extensionContext.selectionManager.volume.isEmpty) {
return;
}

const bounds = selection.getBoundingBox();
const bounds = uiSession.extensionContext.selectionManager.volume.getBoundingBox();
bounds.max = Vector3Utils.add(bounds.max, { x: 1, y: 1, z: 1 });
const halfSize = Vector3Utils.scale(Vector3Utils.subtract(bounds.max, bounds.min), 0.5);
const viewTarget = Vector3Utils.add(bounds.min, halfSize);
Expand Down
146 changes: 129 additions & 17 deletions dye-brush/dye-brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ColorPickerPropertyItemVariant,
CursorProperties,
CursorTargetMode,
IDropdownItem,
IDropdownPropertyItemEntry,
IModalTool,
IObservable,
IPlayerUISession,
Expand All @@ -15,20 +15,24 @@ import {
MouseInputType,
MouseProps,
registerEditorExtension,
Selection,
RelativeVolumeListBlockVolume,
ThemeSettingsColorKey,
Widget,
WidgetComponentVolumeOutline,
WidgetGroup,
} from '@minecraft/server-editor';
import {
BlockVolume,
BoundingBox,
BoundingBoxUtils,
BlockBoundingBox,
BlockBoundingBoxUtils,
RGBA,
CompoundBlockVolumeAction,
Dimension,
Direction,
EntityColorComponent,
Player,
Vector3,
RGB,
BlockLocationIterator,
} from '@minecraft/server';
import { Vector3Utils, VECTOR3_UP } from '@minecraft/math';

Expand Down Expand Up @@ -134,8 +138,8 @@ const colorPalette = new Map<EntityColor, RGB>([
]);

interface DyeBrushStorage {
previewSelection: Selection;
lastVolumePlaced?: BoundingBox;
previewSelection: PreviewVolume;
lastVolumePlaced?: BlockBoundingBox;
currentColor: EntityColor;
brushColor: IObservable<RGBA>;
brushSize: number;
Expand All @@ -144,10 +148,118 @@ interface DyeBrushStorage {

type DyeBrushSession = IPlayerUISession<DyeBrushStorage>;

class PreviewVolume {
private _session: IPlayerUISession;
private _widgetGroup: WidgetGroup;
private _widget: Widget;
private _widgetVolumeComponent: WidgetComponentVolumeOutline;
private _volume: RelativeVolumeListBlockVolume;
private _outlineColor: RGBA;
private _hullColor: RGBA;
private _highlightOutlineColor: RGBA;
private _highlightHullColor: RGBA;

constructor(uiSession: IPlayerUISession) {
this._session = uiSession;

this._outlineColor = this.session.extensionContext.settings.theme.resolveColorKey(
ThemeSettingsColorKey.SelectionVolumeFill
);
this._hullColor = this.session.extensionContext.settings.theme.resolveColorKey(
ThemeSettingsColorKey.SelectionVolumeBorder
);
this._highlightOutlineColor = this.session.extensionContext.settings.theme.resolveColorKey(
ThemeSettingsColorKey.SelectionVolumeOutlineBorder
);
this._highlightHullColor = this.session.extensionContext.settings.theme.resolveColorKey(
ThemeSettingsColorKey.SelectionVolumeOutlineFill
);

const dimensionBounds = this.session.extensionContext.blockUtilities.getDimensionLocationBoundingBox();
const center = BlockBoundingBoxUtils.getCenter(dimensionBounds);

this._volume = new RelativeVolumeListBlockVolume();
this._widgetGroup = this.session.extensionContext.widgetManager.createGroup({ visible: true });
this._widget = this._widgetGroup.createWidget(center, { visible: false, selectable: false });
this._widgetVolumeComponent = this._widget.addVolumeOutline('outline', this._volume, {
outlineColor: this._outlineColor,
hullColor: this._hullColor,
highlightOutlineColor: this._highlightOutlineColor,
highlightHullColor: this._highlightHullColor,
showOutline: false,
showHighlightOutline: true,
visible: true,
});
}

public teardown() {
this._widgetVolumeComponent.delete();
this._widget.delete();
this._widgetGroup.delete();
}

public get session(): IPlayerUISession {
return this._session;
}

public get visible(): boolean {
return this._widget.visible;
}

public set visible(value: boolean) {
this._widget.visible = value;
}

public get location(): Vector3 {
return this._widget.location;
}

public set location(position: Vector3) {
this._widget.location = position;
}

public set outlineColor(value: RGBA) {
this._outlineColor = value;
this._widgetVolumeComponent.outlineColor = value;
}

public set hullColor(value: RGBA) {
this._hullColor = value;
this._widgetVolumeComponent.hullColor = value;
}

public set highlightOutlineColor(value: RGBA) {
this._highlightOutlineColor = value;
this._widgetVolumeComponent.highlightOutlineColor = value;
}

public set highlightHullColor(value: RGBA) {
this._highlightHullColor = value;
this._widgetVolumeComponent.highlightHullColor = value;
}

public addVolume(volume: BlockVolume) {
this._volume.add(volume);
if (this._volume.isEmpty) {
return;
}
const bounds = this._volume.getBoundingBox();
this._widget.location = bounds.min;
}

public clearVolume() {
this._volume.clear();
}

public get locationIterator(): BlockLocationIterator {
return this._volume.getBlockLocationIterator();
}
}

function onColorUpdated(newColor: RGBA, uiSession: DyeBrushSession) {
if (uiSession.scratchStorage) {
uiSession.scratchStorage.previewSelection.setFillColor(newColor);
uiSession.scratchStorage.previewSelection.setOutlineColor({ ...newColor, alpha: 1 });
uiSession.scratchStorage.previewSelection.hullColor = newColor;
uiSession.scratchStorage.previewSelection.outlineColor = { ...newColor, alpha: 1 };
const cursorProps = uiSession.extensionContext.cursor.getProperties();
cursorProps.outlineColor = { ...newColor, alpha: 1 };
cursorProps.targetMode = CursorTargetMode.Face;
Expand All @@ -171,7 +283,7 @@ function addDyeBrushPane(uiSession: DyeBrushSession, tool: IModalTool) {

pane.addDropdown(entityBrush, {
title: 'Brush',
entries: Object.values(EntityColor).reduce<IDropdownItem[]>((list, dye, index) => {
entries: Object.values(EntityColor).reduce<IDropdownPropertyItemEntry[]>((list, dye, index) => {
if (typeof dye === 'string') {
list.push({
label: dye,
Expand Down Expand Up @@ -240,12 +352,12 @@ function addDyeBrushPane(uiSession: DyeBrushSession, tool: IModalTool) {
const blockVolume = new BlockVolume(from, to);
const bounds = blockVolume.getBoundingBox();
if (uiSession.scratchStorage.lastVolumePlaced) {
if (BoundingBoxUtils.equals(uiSession.scratchStorage.lastVolumePlaced, bounds)) {
if (BlockBoundingBoxUtils.equals(uiSession.scratchStorage.lastVolumePlaced, bounds)) {
return;
}
}

previewSelection.pushVolume({ action: CompoundBlockVolumeAction.Add, volume: blockVolume });
previewSelection.addVolume(blockVolume);
uiSession.scratchStorage.lastVolumePlaced = bounds;
};

Expand All @@ -259,12 +371,12 @@ function addDyeBrushPane(uiSession: DyeBrushSession, tool: IModalTool) {

if (mouseProps.mouseAction === MouseActionType.LeftButton) {
if (mouseProps.inputType === MouseInputType.ButtonDown) {
uiSession.scratchStorage.previewSelection.clear();
uiSession.scratchStorage.previewSelection.clearVolume();
onExecuteBrush();
} else if (mouseProps.inputType === MouseInputType.ButtonUp) {
const player: Player = uiSession.extensionContext.player;
const dimension: Dimension = player.dimension;
const iterator = uiSession.scratchStorage.previewSelection.getBlockLocationIterator();
const iterator = uiSession.scratchStorage.previewSelection.locationIterator;
for (const pos of iterator) {
const entities = dimension.getEntities({ location: pos, closest: 1 });
for (const entity of entities) {
Expand All @@ -274,7 +386,7 @@ function addDyeBrushPane(uiSession: DyeBrushSession, tool: IModalTool) {
}
}
}
uiSession.scratchStorage.previewSelection.clear();
uiSession.scratchStorage.previewSelection.clearVolume();
}
}
},
Expand Down Expand Up @@ -323,7 +435,7 @@ function addDyeBrushPane(uiSession: DyeBrushSession, tool: IModalTool) {
uiSession.scratchStorage.backedUpCursorProps = undefined;
}
}
uiSession.scratchStorage?.previewSelection?.clear();
uiSession.scratchStorage?.previewSelection?.clearVolume();
});

pane.hide();
Expand All @@ -346,7 +458,7 @@ export function registerDyeBrushExtension() {
(uiSession: IPlayerUISession<DyeBrushStorage>) => {
uiSession.log.debug(`Initializing extension [${uiSession.extensionContext.extensionInfo.name}]`);

const previewSelection = uiSession.extensionContext.selectionManager.create();
const previewSelection = new PreviewVolume(uiSession as unknown as IPlayerUISession);
previewSelection.visible = true;

const storage: DyeBrushStorage = {
Expand Down
Binary file modified editor-samples.mceditoraddon
Binary file not shown.
8 changes: 4 additions & 4 deletions goto-mark/goto-mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
ActionTypes,
IButtonPropertyItem,
IDropdownItem,
IDropdownPropertyItemEntry,
IDropdownPropertyItem,
IModalTool,
IObservable,
Expand Down Expand Up @@ -75,9 +75,9 @@ function vector3Truncate(vec: Vector3): Vector3 {
return blockLocation;
}

function mapDropdownItems(storage: ExtensionStorage): IDropdownItem[] {
return storage.storedLocations.map((v, index): IDropdownItem => {
const item: IDropdownItem = {
function mapDropdownItems(storage: ExtensionStorage): IDropdownPropertyItemEntry[] {
return storage.storedLocations.map((v, index): IDropdownPropertyItemEntry => {
const item: IDropdownPropertyItemEntry = {
label: `${index + 1}: ${v.name} (${vector3ToString(v.location)})`,
value: index,
};
Expand Down
4 changes: 2 additions & 2 deletions simple-locate/SimpleLocateBiome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { VECTOR3_ZERO, Vector3Utils } from '@minecraft/math';
import {
ActionTypes,
IDropdownItem,
IDropdownPropertyItemEntry,
IObservable,
IPlayerUISession,
ISimpleToolOptions,
Expand Down Expand Up @@ -138,7 +138,7 @@ export class SimpleLocate extends SimpleToolWrapper {

const listOfBiomes = BiomeTypes.getAll().map((v, i) => {
const names = v.id;
const item: IDropdownItem = {
const item: IDropdownPropertyItemEntry = {
label: names.replace('minecraft:', '').replace('_', ' '),
value: i,
};
Expand Down