Skip to content

Commit

Permalink
Added stack and move tools
Browse files Browse the repository at this point in the history
  • Loading branch information
SIsilicon committed Mar 7, 2024
1 parent f826c11 commit 9e17645
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 9 deletions.
16 changes: 16 additions & 0 deletions BP/items/buttons/selection_move.item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"format_version": "1.20.10",
"minecraft:item": {
"description": {
"identifier": "wedit:selection_move",
"category": "commands"
},
"components": {
"minecraft:icon": {
"texture": "selection_move"
},
"minecraft:max_stack_size": 1,
"minecraft:throwable": {}
}
}
}
16 changes: 16 additions & 0 deletions BP/items/buttons/selection_stack.item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"format_version": "1.20.10",
"minecraft:item": {
"description": {
"identifier": "wedit:selection_stack",
"category": "commands"
},
"components": {
"minecraft:icon": {
"texture": "selection_stack"
},
"minecraft:max_stack_size": 1,
"minecraft:throwable": {}
}
}
}
6 changes: 6 additions & 0 deletions RP/textures/item_texture.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
"selection_outline": {
"textures": "textures/items/selection_outline"
},
"selection_stack": {
"textures": "textures/items/selection_stack"
},
"selection_move": {
"textures": "textures/items/selection_move"
},
"selection_wall": {
"textures": "textures/items/selection_wall"
},
Expand Down
Binary file added RP/textures/items/selection_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RP/textures/items/selection_stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/library/utils/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export class Vector {
static get ONE() {
return new Vector(1, 1, 1);
}
static get UP() {
return new Vector(0, 1, 0);
}
static get DOWN() {
return new Vector(0, -1, 0);
}
static get INF() {
return new Vector(Infinity, Infinity, Infinity);
}
Expand Down
14 changes: 7 additions & 7 deletions src/server/commands/utilities/snow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Jobs } from "@modules/jobs.js";
import { RawText, Vector, sleep } from "@notbeer-api";
import { Block, Vector3, Vector as MCVector, BlockPermutation } from "@minecraft/server";
import { Block, Vector3, BlockPermutation } from "@minecraft/server";
import { getWorldHeightLimits } from "../../util.js";
import { CylinderShape } from "../../shapes/cylinder.js";
import { registerCommand } from "../register_commands.js";
Expand Down Expand Up @@ -37,11 +37,11 @@ function canSnowOn(block: Block) {

const dimension = block.dimension;
const location = Vector.from(block.location).add([0.5, 1.99, 0.5]);
let isBlocked = !!dimension.getBlockFromRay(location, MCVector.down, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([-0.49, 0, 0]), MCVector.down, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([0.49, 0, 0]), MCVector.down, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([0, 0, -0.49]), MCVector.down, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([0, 0, 0.49]), MCVector.down, solidTest);
let isBlocked = !!dimension.getBlockFromRay(location, Vector.DOWN, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([-0.49, 0, 0]), Vector.DOWN, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([0.49, 0, 0]), Vector.DOWN, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([0, 0, -0.49]), Vector.DOWN, solidTest);
if (isBlocked) isBlocked &&= !!dimension.getBlockFromRay(location.add([0, 0, 0.49]), Vector.DOWN, solidTest);
return isBlocked;
}

Expand Down Expand Up @@ -82,7 +82,7 @@ registerCommand(registerInformation, function* (session, builder, args) {

const loc = new Vector(x + 0.5, range[1].y + 1.01, z + 0.5);
try {
const block = dimension.getBlockFromRay(loc, MCVector.down, rayTraceOptions)?.block;
const block = dimension.getBlockFromRay(loc, Vector.DOWN, rayTraceOptions)?.block;
if (block) {
blocks.push(block);
blockLocs.push(block.location);
Expand Down
4 changes: 2 additions & 2 deletions src/server/commands/utilities/thaw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Jobs } from "@modules/jobs.js";
import { RawText, Vector, sleep } from "@notbeer-api";
import { Block, Vector3, Vector as MCVector, BlockPermutation } from "@minecraft/server";
import { Block, Vector3, BlockPermutation } from "@minecraft/server";
import { getWorldHeightLimits } from "../../util.js";
import { CylinderShape } from "../../shapes/cylinder.js";
import { registerCommand } from "../register_commands.js";
Expand Down Expand Up @@ -61,7 +61,7 @@ registerCommand(registerInformation, function* (session, builder, args) {

const loc = new Vector(x + 0.5, range[1].y + 1.01, z + 0.5);
try {
const block = dimension.getBlockFromRay(loc, MCVector.down, rayTraceOptions)?.block;
const block = dimension.getBlockFromRay(loc, Vector.DOWN, rayTraceOptions)?.block;
if (block) {
blocks.push(block);
blockLocs.push(block.location);
Expand Down
26 changes: 26 additions & 0 deletions src/server/tools/region_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,29 @@ class SelectionHollowTool extends Tool {
};
}
Tools.register(SelectionHollowTool, "selection_hollow", "wedit:selection_hollow");

class SelectionStackTool extends Tool {
permission = "worldedit.region.stack";

use = function (self: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Server.uiForms.show("$stackAmount", player);
}
};
}
Tools.register(SelectionStackTool, "selection_stack", "wedit:selection_stack");

class SelectionMoveTool extends Tool {
permission = "worldedit.region.move";

use = function (self: Tool, player: Player) {
if (player.isSneaking) {
Server.uiForms.show("$selectRegionMode", player);
} else {
Server.uiForms.show("$moveAmount", player);
}
};
}
Tools.register(SelectionMoveTool, "selection_move", "wedit:selection_move");
48 changes: 48 additions & 0 deletions src/server/ui/select_region_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ Server.uiForms.register("$selectRegionMode", {
},
icon: "textures/items/selection_wall",
},
{
text: "%worldedit.regionMode.stack",
action: (_, player) => {
Server.player.getEquipment(player).setEquipment(EquipmentSlot.Mainhand, new ItemStack("wedit:selection_stack"));
},
icon: "textures/items/selection_stack",
},
{
text: "%worldedit.regionMode.move",
action: (_, player) => {
Server.player.getEquipment(player).setEquipment(EquipmentSlot.Mainhand, new ItemStack("wedit:selection_move"));
},
icon: "textures/items/selection_move",
},
{
text: "%worldedit.regionMode.hollow",
action: (_, player) => {
Expand All @@ -34,3 +48,37 @@ Server.uiForms.register("$selectRegionMode", {
},
],
});

Server.uiForms.register("$stackAmount", {
title: "%worldedit.stack.title",
inputs: {
$amount: {
name: "%worldedit.config.amount",
type: "slider",
min: 1,
max: 64,
default: (_, player) => <number>player.getDynamicProperty("toolLastStackAmount") ?? 2,
},
},
submit: (_, player, input) => {
player.setDynamicProperty("toolLastStackAmount", input.$amount);
Server.command.callCommand(player, "stack", [input.$amount.toString(), "-s"]);
},
});

Server.uiForms.register("$moveAmount", {
title: "%worldedit.move.title",
inputs: {
$amount: {
name: "%worldedit.config.amount",
type: "slider",
min: 1,
max: 64,
default: (_, player) => <number>player.getDynamicProperty("toolLastMoveAmount") ?? 2,
},
},
submit: (_, player, input) => {
player.setDynamicProperty("toolLastMoveAmount", input.$amount);
Server.command.callCommand(player, "move", [input.$amount.toString(), "-s"]);
},
});
15 changes: 15 additions & 0 deletions texts/en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ msgid "item.wedit:selection_outline"
msgstr "Outline Selection"
msgid "item.wedit:selection_hollow"
msgstr "Hollow Selection"
msgid "item.wedit:selection_stack"
msgstr "Stack Selection"
msgid "item.wedit:selection_move"
msgstr "Move Selection"
msgid "item.wedit:draw_line"
msgstr "Draw Line"
msgid "item.wedit:draw_line"
Expand Down Expand Up @@ -135,6 +139,10 @@ msgid "worldedit.regionMode.wall"
msgstr "Wall Mode"
msgid "worldedit.regionMode.hollow"
msgstr "Hollow Mode"
msgid "worldedit.regionMode.stack"
msgstr "Stack Mode"
msgid "worldedit.regionMode.move"
msgstr "Move Mode"

msgid "worldedit.genMode.selectOp"
msgstr "Select Shape to Generate"
Expand All @@ -147,6 +155,11 @@ msgstr "Cylinder"
msgid "worldedit.genMode.pyramid"
msgstr "Pyramid"

msgid "worldedit.stack.title"
msgstr "Select stack amount"
msgid "worldedit.move.title"
msgstr "Select move amount"

msgid "worldedit.config.tool.noProps"
msgstr "No Tool Properties"
msgid "worldedit.config.tool.noProps.detail"
Expand Down Expand Up @@ -223,6 +236,8 @@ msgid "worldedit.config.smooth"
msgstr "Smoothness"
msgid "worldedit.config.range"
msgstr "Range"
msgid "worldedit.config.amount"
msgstr "Amount"
msgid "worldedit.config.pattern"
msgstr "Pattern"
msgid "worldedit.config.pattern.noPattern"
Expand Down

0 comments on commit 9e17645

Please sign in to comment.