Skip to content
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

Updates for Minecraft release 1.21.20-preview.24 #58

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
Binary file modified editor-samples.mceditoraddon
Binary file not shown.
1 change: 1 addition & 0 deletions farm-generator/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sample.farmgenerator.pane.length=Length
sample.farmgenerator.pane.width=Width
sample.farmgenerator.pane.fence=Fence
sample.farmgenerator.pane.irrigation=Add Irrigation
sample.farmgenerator.pane.irrigation.tooltip=Adds water blocks in the farm to irrigate crops.
sample.farmgenerator.pane.crops.title=Crops
sample.farmgenerator.pane.crops.wheat=Wheat
sample.farmgenerator.pane.crops.potato=Potato
Expand Down
94 changes: 52 additions & 42 deletions farm-generator/farm-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ActionTypes,
EditorInputContext,
IModalTool,
IObservable,
IPlayerUISession,
InputModifier,
KeyboardKey,
Expand All @@ -13,6 +14,7 @@ import {
MouseProps,
Ray,
bindDataSource,
makeObservable,
registerEditorExtension,
} from '@minecraft/server-editor';
import { Player, Vector3 } from '@minecraft/server';
Expand All @@ -22,21 +24,24 @@ type SettingsType = {
farmWidth: number;
farmLength: number;
fenceType: number;
irrigation: boolean;
};

type CommonSettingsType = {
irrigation: IObservable<boolean>;
};

type CropSettingsType = {
wheat: boolean;
pumpkin: boolean;
potato: boolean;
carrot: boolean;
beetroot: boolean;
wheat: IObservable<boolean>;
pumpkin: IObservable<boolean>;
potato: IObservable<boolean>;
carrot: IObservable<boolean>;
beetroot: IObservable<boolean>;
};

type AnimalSettingsType = {
pig: boolean;
sheep: boolean;
cow: boolean;
pig: IObservable<boolean>;
sheep: IObservable<boolean>;
cow: IObservable<boolean>;
};

function getRandomInt(upper: number) {
Expand Down Expand Up @@ -77,7 +82,8 @@ const buildFarm = (
possibleAnimals: MinecraftEntityTypes[],
possibleCrops: string[],
player: Player,
settings: SettingsType
settings: SettingsType,
commonSettings: CommonSettingsType
) => {
let didPlaceAnimal = false;
for (let i = 0; i < width; i++) {
Expand All @@ -93,7 +99,7 @@ const buildFarm = (
const block = player.dimension.getBlock(location);
const blockAbove = player.dimension.getBlock(locationAbove);
const isBorder = i === 0 || i === width - 1 || j === 0 || j === length - 1;
if (xOffset % 3 === 0 && !isBorder && settings.irrigation) {
if (xOffset % 3 === 0 && !isBorder && commonSettings.irrigation.value) {
block?.setType(MinecraftBlockTypes.Water);
} else {
block?.setType(MinecraftBlockTypes.Farmland);
Expand Down Expand Up @@ -144,22 +150,25 @@ function addFarmGeneratorSettingsPane(uiSession: IPlayerUISession, tool: IModalT
farmWidth: 10,
farmLength: 10,
fenceType: 0, // oak fence
irrigation: false,
});

const cropSettings: CropSettingsType = bindDataSource(cropPane, {
wheat: false,
pumpkin: false,
potato: false,
carrot: false,
beetroot: false,
});
const commonSettings: CommonSettingsType = {
irrigation: makeObservable(false),
};

const animalSettings: AnimalSettingsType = bindDataSource(animalPane, {
pig: false,
sheep: false,
cow: false,
});
const cropSettings: CropSettingsType = {
wheat: makeObservable(false),
pumpkin: makeObservable(false),
potato: makeObservable(false),
carrot: makeObservable(false),
beetroot: makeObservable(false),
};

const animalSettings: AnimalSettingsType = {
pig: makeObservable(false),
sheep: makeObservable(false),
cow: makeObservable(false),
};

const onExecuteGenerator = (ray?: Ray) => {
const player: Player = uiSession.extensionContext.player;
Expand All @@ -178,29 +187,29 @@ function addFarmGeneratorSettingsPane(uiSession: IPlayerUISession, tool: IModalT

let targetCorner: Vector3 = { x: targetBlock.location.x, y: targetBlock.location.y, z: targetBlock.location.z };
const possibleCrops: string[] = [];
if (cropSettings.beetroot) {
if (cropSettings.beetroot.value) {
possibleCrops.push(MinecraftBlockTypes.Beetroot);
}
if (cropSettings.carrot) {
if (cropSettings.carrot.value) {
possibleCrops.push(MinecraftBlockTypes.Carrots);
}
if (cropSettings.pumpkin) {
if (cropSettings.pumpkin.value) {
possibleCrops.push(MinecraftBlockTypes.Pumpkin);
}
if (cropSettings.wheat) {
if (cropSettings.wheat.value) {
possibleCrops.push(MinecraftBlockTypes.Wheat);
}
if (cropSettings.potato) {
if (cropSettings.potato.value) {
possibleCrops.push(MinecraftBlockTypes.Potatoes);
}
const possibleAnimals: MinecraftEntityTypes[] = [];
if (animalSettings.sheep) {
if (animalSettings.sheep.value) {
possibleAnimals.push(MinecraftEntityTypes.Sheep);
}
if (animalSettings.cow) {
if (animalSettings.cow.value) {
possibleAnimals.push(MinecraftEntityTypes.Cow);
}
if (animalSettings.pig) {
if (animalSettings.pig.value) {
possibleAnimals.push(MinecraftEntityTypes.Pig);
}
let x = 1;
Expand Down Expand Up @@ -245,7 +254,7 @@ function addFarmGeneratorSettingsPane(uiSession: IPlayerUISession, tool: IModalT
length = settings.farmWidth;
width = settings.farmLength;
}
buildFarm(targetCorner, x, z, length, width, possibleAnimals, possibleCrops, player, settings);
buildFarm(targetCorner, x, z, length, width, possibleAnimals, possibleCrops, player, settings, commonSettings);
};

// Create an action that will be executed on left mouse click
Expand Down Expand Up @@ -335,31 +344,32 @@ function addFarmGeneratorSettingsPane(uiSession: IPlayerUISession, tool: IModalT
],
});

windowPane.addBool(settings, 'irrigation', {
windowPane.addBool(commonSettings.irrigation, {
title: 'sample.farmgenerator.pane.irrigation',
tooltip: 'sample.farmgenerator.pane.irrigation.tooltip',
});
cropPane.addBool(cropSettings, 'wheat', {
cropPane.addBool(cropSettings.wheat, {
title: 'sample.farmgenerator.pane.crops.wheat',
});
cropPane.addBool(cropSettings, 'potato', {
cropPane.addBool(cropSettings.potato, {
title: 'sample.farmgenerator.pane.crops.potato',
});
cropPane.addBool(cropSettings, 'beetroot', {
cropPane.addBool(cropSettings.beetroot, {
title: 'sample.farmgenerator.pane.crops.beets',
});
cropPane.addBool(cropSettings, 'pumpkin', {
cropPane.addBool(cropSettings.pumpkin, {
title: 'sample.farmgenerator.pane.crops.pumpkin',
});
cropPane.addBool(cropSettings, 'carrot', {
cropPane.addBool(cropSettings.carrot, {
title: 'sample.farmgenerator.pane.crops.carrot',
});
animalPane.addBool(animalSettings, 'cow', {
animalPane.addBool(animalSettings.cow, {
title: 'sample.farmgenerator.pane.animals.cow',
});
animalPane.addBool(animalSettings, 'sheep', {
animalPane.addBool(animalSettings.sheep, {
title: 'sample.farmgenerator.pane.animals.sheep',
});
animalPane.addBool(animalSettings, 'pig', {
animalPane.addBool(animalSettings.pig, {
title: 'sample.farmgenerator.pane.animals.pig',
});

Expand Down
2 changes: 1 addition & 1 deletion goto-mark/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sample.gotomark.pane.button.teleport=Teleport to location
sample.gotomark.pane.button.setspawn=Set Spawn Point to current
sample.gotomark.pane.button.gotospawn=Goto Spawn Point
sample.gotomark.pane.locationpane.title=Stored Locations
sample.gotomark.pane.locationpane.button.teleport=Teleport to Stored Location
sample.gotomark.pane.locationpane.button.teleport=Teleport to Stored Location %1$s
sample.gotomark.pane.locationpane.button.delete=Delete Stored Location
sample.gotomark.pane.locationpane.input.name=New Name
sample.gotomark.pane.locationpane.button.store=Store Current Location As...
Expand Down
26 changes: 22 additions & 4 deletions goto-mark/goto-mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
ActionTypes,
IButtonPropertyItem,
IDropdownItem,
IDropdownPropertyItem,
IModalTool,
Expand Down Expand Up @@ -58,6 +59,8 @@ type ExtensionStorage = {
storedLocations: LocationData[]; // The list of stored locations

transactionHandler: UserDefinedTransactionHandle<GotoTeleportTransactionPayload>; // The transaction handler for the extension

teleportButton?: IButtonPropertyItem;
};

// Handy helper to turn a Vector3 into a pretty string
Expand Down Expand Up @@ -132,7 +135,7 @@ function buildParentPane(uiSession: IPlayerUISession<ExtensionStorage>, storage:
storage.parentPaneDataSource = bindDataSource(parentPane, initialPaneData);
storage.previousLocation = currentLocation;

parentPane.addVector3(storage.parentPaneDataSource, 'playerLocation', {
parentPane.addVector3_deprecated(storage.parentPaneDataSource, 'playerLocation', {
title: 'sample.gotomark.pane.location',
});

Expand Down Expand Up @@ -253,13 +256,20 @@ function buildLocationPane(
storage.dropdownMenu = locationPane.addDropdown(storage.locationPaneDataSource, 'currentSelection', {
title: 'sample.gotomark.pane.locationpane.dropdownLabel',
dropdownItems: dropdownItems,
onChange: (_obj: object, _property: string, _oldValue: object, _newValue: object) => {},
onChange: (_obj: object, _property: string, _oldValue: object, _newValue: object) => {
if (storage.teleportButton) {
storage.teleportButton.setTitle({
id: 'sample.gotomark.pane.locationpane.button.teleport',
props: [`${(_newValue as unknown as number) + 1}`],
});
}
},
});

locationPane.addDivider();

// Jump to the stored location selected in the dropdown
locationPane.addButton(
storage.teleportButton = locationPane.addButton(
uiSession.actionManager.createAction({
actionType: ActionTypes.NoArgsAction,
onExecute: () => {
Expand All @@ -279,7 +289,10 @@ function buildLocationPane(
},
}),
{
title: 'sample.gotomark.pane.locationpane.button.teleport',
title: {
id: 'sample.gotomark.pane.locationpane.button.teleport',
props: [dropdownItems.length > 0 ? `${storage.locationPaneDataSource.currentSelection + 1}` : ''],
},
visible: true,
}
);
Expand Down Expand Up @@ -311,6 +324,11 @@ function buildLocationPane(
dropdownItems,
storage.locationPaneDataSource.currentSelection
);

storage.teleportButton?.setTitle({
id: 'sample.gotomark.pane.locationpane.button.teleport',
props: [dropdownItems.length > 0 ? `${storage.locationPaneDataSource.currentSelection + 1}` : ''],
});
},
}),
{
Expand Down
1 change: 1 addition & 0 deletions portal-generator/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sample.portalgenerator.pane.nether.pane.orientation.y=Y-Axis
sample.portalgenerator.pane.nether.pane.width=Block Width
sample.portalgenerator.pane.nether.pane.height=Block Height
sample.portalgenerator.pane.nether.pane.corners=Corners
sample.portalgenerator.pane.nether.pane.corners.tooltip=Adds corner blocks to the portal.
sample.portalgenerator.pane.nether.pane.percentage=Percentage Complete
sample.portalgenerator.pane.end.pane.title=End Portal
sample.portalgenerator.pane.end.pane.filledcount=Filled 'Eye of Ender' count
Expand Down
30 changes: 20 additions & 10 deletions portal-generator/portal-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// Copyright (c) Mojang AB. All rights reserved.

import { CursorTargetMode, IDisposable, Ray } from '@minecraft/server-editor';
import {
BoolPropertyItemVariant,
CursorTargetMode,
IDisposable,
IObservable,
makeObservable,
Ray,
} from '@minecraft/server-editor';
import {
bindDataSource,
IPlayerUISession,
Expand Down Expand Up @@ -35,15 +42,13 @@ type ExtensionStorage = {
type PortalGeneratorSession = IPlayerUISession<ExtensionStorage>;

type PaneDataSourceType = {
replaceFloor: boolean;
portalType: PortalType;
};

type NetherDataSourceType = {
sizeX: number;
sizeY: number;
orientation: PortalOrientation;
corners: boolean;
percentComplete: number;
};

Expand All @@ -69,9 +74,11 @@ class PortalGenerator implements IDisposable {

private _pane?: IPropertyPane;
private _settings: PaneDataSourceType = {
replaceFloor: true,
portalType: PortalType.Nether,
};

private _shouldReplaceFloor: IObservable<boolean> = makeObservable(true);

private _dataSource?: PaneDataSourceType;

constructor() {
Expand Down Expand Up @@ -152,12 +159,13 @@ class PortalGenerator implements IDisposable {

this._dataSource = bindDataSource(pane, this._settings);

pane.addBool(this._dataSource, 'replaceFloor', {
pane.addBool(this._shouldReplaceFloor, {
title: 'sample.portalgenerator.pane.replacefloor',
onChange: (_obj: object, _property: string, _oldValue: object, _newValue: object) => {
const targetMode = this._dataSource?.replaceFloor ? CursorTargetMode.Block : CursorTargetMode.Face;
onChange: (current: boolean) => {
const targetMode = current ? CursorTargetMode.Block : CursorTargetMode.Face;
uiSession.extensionContext.cursor.setProperties({ targetMode });
},
variant: BoolPropertyItemVariant.ToggleSwitch,
});

pane.addDropdown(this._dataSource, 'portalType', {
Expand Down Expand Up @@ -210,11 +218,12 @@ class NetherPortal implements IPortalGenerator {
sizeX: 4,
sizeY: 5,
orientation: PortalOrientation.X,
corners: true,
percentComplete: 100,
};
private _dataSource?: NetherDataSourceType;

private _hasCorners: IObservable<boolean> = makeObservable(true);

constructor() {}

public subPane(uiSession: PortalGeneratorSession): IPropertyPane | undefined {
Expand Down Expand Up @@ -296,8 +305,9 @@ class NetherPortal implements IPortalGenerator {
showSlider: false,
});

subPane.addBool(this._dataSource, 'corners', {
subPane.addBool(this._hasCorners, {
title: 'sample.portalgenerator.pane.nether.pane.corners',
tooltip: 'sample.portalgenerator.pane.nether.pane.corners.tooltip',
});

subPane.addNumber(this._dataSource, 'percentComplete', {
Expand Down Expand Up @@ -369,7 +379,7 @@ class NetherPortal implements IPortalGenerator {

// Set as obsidian for bottom, top, and edges of portal
if (
!this._dataSource.corners &&
!this._hasCorners.value &&
((y === 0 && x === 0) ||
(y === 0 && x === xEnd) ||
(y === yEnd && x === xEnd) ||
Expand Down
Loading