Skip to content

Commit 04606d5

Browse files
authored
Upload generated files for scripts (JaylyDev#191)
Upload generated files
1 parent 70b134d commit 04606d5

6 files changed

Lines changed: 1055 additions & 153 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# editor-fullbright
2+
3+
## Description
4+
> This README is auto generated, Edit the README so that users know what this package does.
5+
6+
## Credits
7+
These scripts were written by [Jayly](https://github.com/JaylyDev)

scripts/editor-fullbright/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Script example for ScriptAPI
2+
// Author: Jayly <https://github.com/JaylyDev>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import { ActionTypes, EditorInputContext, InputModifier, KeyboardKey } from "@minecraft/server-editor";
5+
import { MinecraftEffectTypes } from "@minecraft/server";
6+
/**
7+
* Class to enable toggles for full bright in menu in editor mode
8+
*/
9+
export class FullbrightToggle {
10+
constructor(uiSession, menu) {
11+
const player = uiSession.extensionContext.player;
12+
// Set actions
13+
const enableAction = uiSession.actionManager.createAction({
14+
actionType: ActionTypes.NoArgsAction,
15+
onExecute: () => {
16+
player.addEffect(MinecraftEffectTypes.nightVision, 0x7fffffff, 1, false);
17+
},
18+
});
19+
const disableAction = uiSession.actionManager.createAction({
20+
actionType: ActionTypes.NoArgsAction,
21+
onExecute: () => {
22+
player.runCommand("effect @s " + MinecraftEffectTypes.nightVision.getName() + " 0");
23+
},
24+
});
25+
// Add actions to menu
26+
menu.addItem({ name: 'Enable', displayStringLocId: "Enable" }, enableAction);
27+
menu.addItem({ name: 'Disable', displayStringLocId: "Disable" }, disableAction);
28+
// Create key bindings
29+
uiSession.inputManager.registerKeyBinding(EditorInputContext.GlobalEditor, enableAction, KeyboardKey.KEY_Z, InputModifier.Control);
30+
uiSession.inputManager.registerKeyBinding(EditorInputContext.GlobalEditor, disableAction, KeyboardKey.KEY_Y, InputModifier.Control);
31+
}
32+
;
33+
}

scripts/editor-fullbright/tests.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { FullbrightToggle } from "./index";
2+
import { registerEditorExtension } from "@minecraft/server-editor";
3+
export function createMenu(uiSession) {
4+
if (!uiSession.scratchStorage) {
5+
throw new Error('Core UI initialization order incorrect');
6+
}
7+
const edit = uiSession.createMenu({
8+
name: 'FullBright',
9+
displayStringLocId: 'FullBright',
10+
});
11+
edit.show();
12+
return edit;
13+
}
14+
;
15+
registerEditorExtension('nightVision', (uiSession) => {
16+
uiSession.scratchStorage = {};
17+
// Initialize tool rail.
18+
uiSession.toolRail.show();
19+
// Add selection functionality
20+
new FullbrightToggle(uiSession, createMenu(uiSession));
21+
});
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import { Vector } from "@minecraft/server";
2+
import { BlockVolume } from "@minecraft/server-editor";
3+
import { Direction, getRotationCorrectedDirection } from "editor-utilities/index";
4+
/**
5+
* @beta
6+
*/
7+
var AxisPlanes;
8+
(function (AxisPlanes) {
9+
AxisPlanes[AxisPlanes["XZ"] = 0] = "XZ";
10+
AxisPlanes[AxisPlanes["XY"] = 1] = "XY";
11+
AxisPlanes[AxisPlanes["YZ"] = 2] = "YZ";
12+
})(AxisPlanes || (AxisPlanes = {}));
13+
;
14+
/**
15+
* @beta
16+
*/
17+
const axisNormalLookup = {
18+
[AxisPlanes.XZ]: Vector.up,
19+
[AxisPlanes.XY]: Vector.forward,
20+
[AxisPlanes.YZ]: Vector.left,
21+
};
22+
/**
23+
* @beta
24+
*/
25+
export function getRelativeXYAxisAsNormal(rotation) {
26+
const direction = getRotationCorrectedDirection(rotation, Direction.Forward);
27+
switch (direction) {
28+
case Direction.Forward:
29+
case Direction.Back:
30+
return axisNormalLookup[AxisPlanes.XY];
31+
case Direction.Right:
32+
case Direction.Left:
33+
return axisNormalLookup[AxisPlanes.YZ];
34+
default:
35+
throw 'Invalid quadrant';
36+
}
37+
}
38+
/**
39+
* @beta
40+
*/
41+
function VectorDot(a, b) {
42+
return a.x * b.x + a.y * b.y + a.z * b.z;
43+
}
44+
/**
45+
* @beta
46+
*/
47+
function VectorScale(a, s) {
48+
const v = new Vector(a.x, a.y, a.z);
49+
v.x *= s;
50+
v.y *= s;
51+
v.z *= s;
52+
return v;
53+
}
54+
/**
55+
* @beta
56+
*/
57+
export function intersectRayPlane(rayLocation, rayDirection, planeNormal, planeDistance) {
58+
const denominator = VectorDot(rayDirection, planeNormal);
59+
if (denominator !== 0) {
60+
const t = -(VectorDot(rayLocation, planeNormal) + planeDistance) / denominator;
61+
if (t < 0) {
62+
return undefined;
63+
}
64+
const scaledDirection = VectorScale(rayDirection, t);
65+
const result = Vector.add(rayLocation, scaledDirection);
66+
return result;
67+
}
68+
else if (VectorDot(planeNormal, rayLocation) + planeDistance === 0) {
69+
return rayLocation;
70+
}
71+
return undefined;
72+
}
73+
/**
74+
* @beta
75+
*/
76+
export function shrinkVolumeAlongViewAxis(volume, rotationY, direction, amount) {
77+
const relativeDirection = getRotationCorrectedDirection(rotationY, direction);
78+
return shrinkVolumeAlongAbsoluteAxis(volume, relativeDirection, amount);
79+
}
80+
export function growVolumeAlongViewAxis(volume, rotationY, direction, amount) {
81+
const relativeDirection = getRotationCorrectedDirection(rotationY, direction);
82+
return growVolumeAlongAbsoluteAxis(volume, relativeDirection, amount);
83+
}
84+
function growVolumeAlongAbsoluteAxis(volume, direction, amount) {
85+
const maxAxialLength = 32;
86+
if (amount > maxAxialLength) {
87+
amount = maxAxialLength;
88+
}
89+
const bounds = volume.boundingBox;
90+
const min = bounds.min;
91+
const max = bounds.max;
92+
const spanX = bounds.spanX;
93+
const spanY = bounds.spanY;
94+
const spanZ = bounds.spanZ;
95+
switch (direction) {
96+
case Direction.Up: // +Y Axis
97+
if (spanY + amount > maxAxialLength) {
98+
amount = maxAxialLength - spanY;
99+
}
100+
max.y += amount;
101+
break;
102+
case Direction.Down: // -Y Axis
103+
if (spanY + amount > maxAxialLength) {
104+
amount = maxAxialLength - spanY;
105+
}
106+
min.y -= amount;
107+
break;
108+
case Direction.Forward: // +Z Axis
109+
if (spanZ + amount > maxAxialLength) {
110+
amount = maxAxialLength - spanZ;
111+
}
112+
max.z += amount;
113+
break;
114+
case Direction.Back: // -Z Axis
115+
if (spanZ + amount > maxAxialLength) {
116+
amount = maxAxialLength - spanZ;
117+
}
118+
min.z -= amount;
119+
break;
120+
case Direction.Left: // +X Axis
121+
if (spanX + amount > maxAxialLength) {
122+
amount = maxAxialLength - spanX;
123+
}
124+
max.x += amount;
125+
break;
126+
case Direction.Right: // -X Axis
127+
if (spanX + amount > maxAxialLength) {
128+
amount = maxAxialLength - spanX;
129+
}
130+
min.x -= amount;
131+
break;
132+
}
133+
const newVolume = new BlockVolume(min, max);
134+
return newVolume;
135+
}
136+
function shrinkVolumeAlongAbsoluteAxis(volume, direction, amount) {
137+
const bounds = volume.boundingBox;
138+
const min = bounds.min;
139+
const max = bounds.max;
140+
const spanX = bounds.spanX;
141+
const spanY = bounds.spanY;
142+
const spanZ = bounds.spanZ;
143+
switch (direction) {
144+
case Direction.Up: // +Y Axis
145+
if (spanY > amount) {
146+
max.y -= amount;
147+
}
148+
break;
149+
case Direction.Down: // -Y Axis
150+
if (spanY > amount) {
151+
min.y += amount;
152+
}
153+
break;
154+
case Direction.Forward: // +Z Axis
155+
if (spanZ > amount) {
156+
max.z -= amount;
157+
}
158+
break;
159+
case Direction.Back: // -Z Axis
160+
if (spanZ > amount) {
161+
min.z += amount;
162+
}
163+
break;
164+
case Direction.Left: // +X Axis
165+
if (spanX > amount) {
166+
max.x -= amount;
167+
}
168+
break;
169+
case Direction.Right: // -X Axis
170+
if (spanX > amount) {
171+
min.x += amount;
172+
}
173+
break;
174+
}
175+
const newVolume = new BlockVolume(min, max);
176+
return newVolume;
177+
}

0 commit comments

Comments
 (0)