Skip to content

Commit

Permalink
eslint and hit action fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackedMatter committed Jan 13, 2024
1 parent 8de0240 commit 963224c
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/server/modules/biome_data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dimension, Vector3, world, Entity, DataDrivenEntityTriggerBeforeEvent, DataDrivenEntityTriggerAfterEvent } from "@minecraft/server";
import { Dimension, Vector3, world, Entity } from "@minecraft/server";
import { commandSyntaxError, contentLog, CustomArgType, Database, Vector } from "@notbeer-api";
import { EventEmitter } from "library/classes/eventEmitter.js";
import { locToString, wrap } from "../util.js";
Expand Down Expand Up @@ -158,7 +158,7 @@ class BiomeDetector extends EventEmitter implements PooledResource {
reject(err);
}

const onEvent = (ev: DataDrivenEntityTriggerAfterEvent) => {
const onEvent = () => {
try {
const biomeId = biomeScores.getScore(this.entity.scoreboardIdentity);
this.entity.triggerEvent("wedit:despawn");
Expand Down
2 changes: 1 addition & 1 deletion src/server/modules/selection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { regionBounds, regionVolume, Vector } from "@notbeer-api";
import { MolangVariableMap, Player, system } from "@minecraft/server";
import { Player, system } from "@minecraft/server";
import { Shape, shapeGenOptions } from "../shapes/base_shape.js";
import { SphereShape } from "../shapes/sphere.js";
import { CuboidShape } from "../shapes/cuboid.js";
Expand Down
6 changes: 3 additions & 3 deletions src/server/shapes/base_shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export abstract class Shape {
* @return True if a block should be generated; false otherwise
*/
protected abstract inShape(relLoc: Vector, genVars: shapeGenVars): boolean;

/**
* Generates a list of particles that when displayed, shows the shape.
*/
Expand Down Expand Up @@ -112,8 +112,8 @@ export abstract class Shape {
protected drawCircle(center: Vector, radius: number, axis: "x"|"y"|"z"): [string, Vector][] {
const [rotate, vec]: [typeof Vector.prototype.rotateX, Vector] =
axis === "x" ? [Vector.prototype.rotateX, new Vector(0, 1, 0)] :
axis === "y" ? [Vector.prototype.rotateY, new Vector(1, 0, 0)] :
[Vector.prototype.rotateZ, new Vector(0, 1, 0)];
axis === "y" ? [Vector.prototype.rotateY, new Vector(1, 0, 0)] :
[Vector.prototype.rotateZ, new Vector(0, 1, 0)];
const resolution = snap(Math.min(radius * 2*Math.PI, 36), 4);

const points: [string, Vector][] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/server/shapes/cuboid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class CuboidShape extends Shape {
public getYRange() {
return <[number, number]>[0, this.size[1] - 1];
}

public getOutline(loc: Vector) {
const min = loc;
const max = loc.add(this.size);
Expand Down
2 changes: 1 addition & 1 deletion src/server/shapes/cylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CylinderShape extends Shape {
locWithOffset.add([maxRadius, 0, 0]), locWithOffset.add([maxRadius, this.height, 0]),
locWithOffset.add([0, 0, -maxRadius]), locWithOffset.add([0, this.height, -maxRadius]),
locWithOffset.add([0, 0, maxRadius]), locWithOffset.add([0, this.height, maxRadius]),
]
];
const edges: [number, number][] = [[0, 1], [2, 3], [4, 5], [6, 7]];
return [
...this.drawCircle(loc.sub([0, 0.5, 0]), maxRadius, "y"),
Expand Down
2 changes: 1 addition & 1 deletion src/server/shapes/pyramid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class PyramidShape extends Shape {
throw new Error("getYRange not implemented!");
return null;
}

public getOutline(loc: Vector) {
const vertices = [
loc.add([-this.size + 1, 0, -this.size + 1]),
Expand Down
12 changes: 6 additions & 6 deletions src/server/tools/base_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export abstract class Tool {
*/
readonly drop: (self: Tool, player: Player, session: PlayerSession) => void | Generator<unknown, void>;
/**
* The function that's called every tick the tool is held.
*/
readonly tick: (self: Tool, player: Player, session: PlayerSession, tick: number) => Generator<unknown>;
/**
* The function that's called when the tool stops being held.
*/
* The function that's called when the tool stops being held.
*/
readonly stopHold: (self: Tool, player: Player, session: PlayerSession) => void | Generator<unknown, void>;
/**
* The function that's called every tick the tool is held.
*/
readonly tick: (self: Tool, player: Player, session: PlayerSession, tick: number) => void | Generator<unknown, void>;
/**
* The permission required for the tool to be used.
*/
Expand Down
33 changes: 16 additions & 17 deletions src/server/tools/generation_tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dimension, Player, Vector3, system } from "@minecraft/server";
import { Player, Vector3, system } from "@minecraft/server";
import { PlayerUtil } from "@modules/player_util";
import { RawText, Server, Vector, regionBounds } from "@notbeer-api";
import { generateLine } from "server/commands/region/line";
Expand All @@ -10,12 +10,11 @@ import { Jobs } from "@modules/jobs";
import { SphereShape } from "server/shapes/sphere";
import { CylinderShape } from "server/shapes/cylinder";
import { PyramidShape } from "server/shapes/pyramid";
import { Shape } from "server/shapes/base_shape";

function trySpawnParticle(player: Player, type: string, location: Vector3) {
try {
player.spawnParticle(type, location);
} catch {}
} catch { /* pass */ }
}

abstract class GeneratorTool extends Tool {
Expand All @@ -33,7 +32,7 @@ abstract class GeneratorTool extends Tool {
return true;
}
return false;
};
}

protected baseTick(player: Player, session: PlayerSession) {
if (system.currentTick % 5 !== 0 || !this.posStart.has(session) || !session.drawOutlines || this.posStart.get(session)[1] !== player.dimension.id) {
Expand Down Expand Up @@ -62,7 +61,7 @@ abstract class GeneratorTool extends Tool {
stopHold = function (self: GeneratorTool, _: Player, session: PlayerSession) {
self.posStart.delete(session);
};

drop = function (self: GeneratorTool, _: Player, session: PlayerSession) {
self.posStart.delete(session);
};
Expand All @@ -73,7 +72,7 @@ class DrawLineTool extends GeneratorTool {

commonUse = function* (self: DrawLineTool, player: Player, session: PlayerSession, loc?: Vector) {
if (self.baseUse(player, session, loc)) return;

const pos1 = self.getFirstPos(session);
const pos2 = self.traceForPos(player);
const [start, end] = regionBounds([pos1, pos2]);
Expand Down Expand Up @@ -109,7 +108,7 @@ class DrawLineTool extends GeneratorTool {
print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawLineTool, player: Player, session: PlayerSession) {
tick = function (self: DrawLineTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

let lineStart = self.getFirstPos(session);
Expand All @@ -135,7 +134,7 @@ class DrawLineTool extends GeneratorTool {
trySpawnParticle(player, "wedit:selection_draw", Vector.add(p, [1, 1, 1]));
});
};

useOn = this.commonUse;
use = this.commonUse;
}
Expand All @@ -157,11 +156,11 @@ class DrawSphereTool extends GeneratorTool {
const job = Jobs.startJob(session, 2, sphereShape.getRegion(center));
const count = yield* Jobs.perform(job, sphereShape.generate(center, pattern, null, session));
Jobs.finishJob(job);

print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawSphereTool, player: Player, session: PlayerSession) {
tick = function (self: DrawSphereTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

const center = self.getFirstPos(session);
Expand All @@ -182,7 +181,7 @@ class DrawSphereTool extends GeneratorTool {
}
}
};

useOn = this.commonUse;
use = this.commonUse;
}
Expand All @@ -202,19 +201,19 @@ class DrawCylinderTool extends GeneratorTool {
const job = Jobs.startJob(session, 2, shape.getRegion(center));
const count = yield* Jobs.perform(job, shape.generate(center, pattern, null, session));
Jobs.finishJob(job);

print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawCylinderTool, player: Player, session: PlayerSession) {
tick = function (self: DrawCylinderTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

const [shape, loc] = self.getShape(player, session);
for (const particle of shape.getOutline(loc)) {
trySpawnParticle(player, ...particle);
}
};

getShape(player: Player, session: PlayerSession): [CylinderShape, Vector] {
const center = this.getFirstPos(session).clone();
const pos2 = this.traceForPos(player);
Expand Down Expand Up @@ -246,19 +245,19 @@ class DrawPyramidTool extends GeneratorTool {
const job = Jobs.startJob(session, 2, shape.getRegion(center));
const count = yield* Jobs.perform(job, shape.generate(center, pattern, null, session));
Jobs.finishJob(job);

print(RawText.translate("commands.blocks.wedit:created").with(`${count}`), player, true);
};

tick = function* (self: DrawPyramidTool, player: Player, session: PlayerSession) {
tick = function (self: DrawPyramidTool, player: Player, session: PlayerSession) {
if (self.baseTick(player, session)) return;

const [shape, loc] = self.getShape(player, session);
for (const particle of shape.getOutline(loc)) {
trySpawnParticle(player, ...particle);
}
};

getShape(player: Player, session: PlayerSession): [PyramidShape, Vector] {
const center = this.getFirstPos(session).clone();
const pos2 = this.traceForPos(player);
Expand Down
8 changes: 4 additions & 4 deletions src/server/tools/region_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class SelectionFillTool extends Tool {
};
}
Tools.register(SelectionFillTool, "selection_fill", "wedit:selection_fill");

class SelectionWallTool extends Tool {
permission = "worldedit.region.walls";

use = function (_t: Tool, player: Player, _s: PlayerSession) {
use = function (_t: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand All @@ -37,7 +37,7 @@ Tools.register(SelectionWallTool, "selection_wall", "wedit:selection_wall");
class SelectionOutlineTool extends Tool {
permission = "worldedit.region.faces";

use = function (_t: Tool, player: Player, _s: PlayerSession) {
use = function (_t: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand All @@ -50,7 +50,7 @@ Tools.register(SelectionOutlineTool, "selection_outline", "wedit:selection_outli
class SelectionHollowTool extends Tool {
permission = "worldedit.region.hollow";

use = function (_t: Tool, player: Player, _s: PlayerSession) {
use = function (self: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/server/tools/selection_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SelectionTool extends Tool {
break = function (self: Tool, player: Player, session: PlayerSession, loc: Vector3) {
Server.command.callCommand(player, "pos1", [`${loc.x}`, `${loc.y}`, `${loc.z}`]);
};
drop = function (self: Tool, player: Player, session: PlayerSession) {
drop = function (self: Tool, player: Player) {
Server.command.callCommand(player, "desel");
};
}
Expand All @@ -26,7 +26,7 @@ class FarSelectionTool extends Tool {
break = function (self: Tool, player: Player) {
Server.command.callCommand(player, "hpos1");
};
drop = function (self: Tool, player: Player, session: PlayerSession) {
drop = function (self: Tool, player: Player) {
Server.command.callCommand(player, "desel");
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/server/tools/tool_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ToolBuilder {
const player = entity.dimension.getPlayers({ closest: 1, location: entity.location, maxDistance: 2 })[0];
if (player) this.onItemDrop(entity.getComponent("item").itemStack, player);
});

Server.on("blockBreak", ev => {
if (!ev.itemStack) return;
this.onBlockBreak(ev.itemStack, ev.player, ev, Vector.from(ev.block));
Expand Down Expand Up @@ -258,9 +258,9 @@ class ToolBuilder {
} else {
return;
}
tool.process(getSession(player), ToolAction.DROP);
tool.process(getSession(player), ToolAction.HIT, loc);
}

private onItemDrop(item: ItemStack, player: Player) {
if (this.disabled.includes(player.id) || !hasSession(player.id)) {
return;
Expand Down Expand Up @@ -298,11 +298,11 @@ class ToolBuilder {
}
}
}

private stopHolding(player: Player) {
if (this.prevHeldTool.has(player)) {
this.prevHeldTool.get(player)?.process(getSession(player), ToolAction.STOP_HOLD);
this.prevHeldTool.delete(player);
this.prevHeldTool.get(player)?.process(getSession(player), ToolAction.STOP_HOLD);
this.prevHeldTool.delete(player);
}
}
}
Expand Down

0 comments on commit 963224c

Please sign in to comment.