diff --git a/README.md b/README.md index 882993b..39bfd18 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Need help, want to discuss technical Minecraft, or follow future updates? [**Joi - [x] Correct block placement checking - [x] Automatic material gathering from inventories - [x] Material list +- [ ] Flexible structure movement - [ ] Block texture display ## Issues & Suggestions diff --git a/packs/BP/scripts/classes/Enums/InstanceButtons.js b/packs/BP/scripts/classes/Enums/InstanceButtons.js index d72087e..ed8af25 100644 --- a/packs/BP/scripts/classes/Enums/InstanceButtons.js +++ b/packs/BP/scripts/classes/Enums/InstanceButtons.js @@ -9,6 +9,7 @@ export const InstanceButtons = Object.freeze({ NextLayer: 'Increase Layer', PreviousLayer: 'Decrease Layer', Move: 'Move Here', + FlexibleMove: 'Flexible Move', Statistics: 'Statistics', Settings: 'Settings', Materials: 'Material List' diff --git a/packs/BP/scripts/classes/Instance/FlexibleInstanceMove.js b/packs/BP/scripts/classes/Instance/FlexibleInstanceMove.js new file mode 100644 index 0000000..4ca638a --- /dev/null +++ b/packs/BP/scripts/classes/Instance/FlexibleInstanceMove.js @@ -0,0 +1,35 @@ +export class FlexibleInstanceMove { + player; + instance; + + constructor(instance, player) { + this.instance = instance; + this.player = player; + this.tryBeginFlexibleMove(); + } + + tryBeginFlexibleMove() { + if (this.instance.isFlexMoving) { + this.feedback('§cThis instance is already being moved.'); + return; + } + this.beginFlexibleMove(); + } + + beginFlexibleMove() { + // place structure in movement mode + this.instance.startFlexibleMove(this.player); + // lock player controls + // start handling player movement controls + } + + endFlexibleMove() { + this.instance.stopFlexibleMove(); + } + + feedback(str) { + this.player.sendMessage(str); + } +} + +// if the player logs out, stop the move \ No newline at end of file diff --git a/packs/BP/scripts/classes/Instance/InstanceForm.js b/packs/BP/scripts/classes/Instance/InstanceForm.js index f9729c3..392b84d 100644 --- a/packs/BP/scripts/classes/Instance/InstanceForm.js +++ b/packs/BP/scripts/classes/Instance/InstanceForm.js @@ -4,6 +4,7 @@ import { forceShow } from '../../utils'; import { InstanceButtons } from '../Enums/InstanceButtons'; import { InstanceFormBuilder } from './InstanceFormBuilder'; import { FormCancelationReason } from '@minecraft/server-ui'; +import { FlexibleInstanceMove } from './FlexibleInstanceMove'; export class InstanceForm { instanceName; @@ -94,6 +95,9 @@ export class InstanceForm { case InstanceButtons.Move: this.instance.move(this.player.dimension.id, this.player.location); break; + case InstanceButtons.FlexibleMove: + new FlexibleInstanceMove(this.instance, this.player); + break; case InstanceButtons.Settings: this.settingsForm(); break; diff --git a/packs/BP/scripts/classes/Instance/StructureInstance.js b/packs/BP/scripts/classes/Instance/StructureInstance.js index 08c4144..4410dce 100644 --- a/packs/BP/scripts/classes/Instance/StructureInstance.js +++ b/packs/BP/scripts/classes/Instance/StructureInstance.js @@ -15,6 +15,7 @@ export class StructureInstance { verifier = void 0; verificationRenderer = void 0; materials = void 0; + flexMovingPlayerId = void 0; constructor(instanceName, structureId) { this.structure = new Structure(structureId); @@ -245,6 +246,23 @@ export class StructureInstance { this.setLayer(this.options.currentLayer - 1); } + startFlexibleMove(player) { + this.flexMovingPlayerId = player.id; + this.disable(); + // create flex movement outliner + } + + stopFlexibleMove(finalLocation) { + // disable flex movement outliner + this.move(this.getDimension(), finalLocation); + this.enable(); + this.flexMovingPlayerId = void 0; + } + + isFlexibleMoving() { + return this.flexMovingPlayerId !== void 0; + } + disableInstanceWhenNoPlayersOnline() { // This prevents a memory leak when no players are online. world.beforeEvents.playerLeave.subscribe(event => {