start flexible movement
This commit is contained in:
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user