Skip to content

Commit 3b5bde2

Browse files
committed
enchantments and itemstack
1 parent 3ab4099 commit 3b5bde2

14 files changed

+430
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ If one of the variables does not have definitions, create an issue or read Micro
6565
- [EffectAddEvent (v1.17.10.22)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EffectAddEvent.md)
6666
- [EffectAddEventSignal (v1.17.10.22)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EffectAddEvent.md)
6767
- [EffectType](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EffectType.md)
68-
- [Enchantment (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/Enchantment.md)
69-
- [EnchantmentList (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EnchantmentList.md)
70-
- [EnchantmentSlot (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EnchantmentSlot.md)
71-
- [EnchantmentType (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EnchantmentType.md)
68+
- [Enchantment (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/Enchantments.md)
69+
- [EnchantmentList (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/Enchantments.md)
70+
- [EnchantmentSlot (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/Enchantments.md)
71+
- [EnchantmentType (v1.18.20.21)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/Enchantments.md)
7272
- [Entity (v1.16.220.51)](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/Entity.md)
7373
- [EntityAddRiderComponent](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EntityAddRiderComponent.md)
7474
- [EntityAgeableComponent](https://github.com/jaylydev/gametest-example/tree/main/mojang-minecraft/classes/EntityAgeableComponent.md)

miscellaneous/getEntities.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://github.com/jaylydev
2+
3+
import { world } from "mojang-minecraft";
4+
5+
try {
6+
let Entities = world.getDimension("overworld").getEntities();
7+
for (let entity of Entities) {
8+
world.getDimension("overworld").runCommand(`say "${entity}" `);
9+
}
10+
} catch (error) {
11+
world.getDimension("overworld").runCommand(`say "${error}" `);
12+
}

miscellaneous/getHighestBlock.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://github.com/ReallyFatYoshi
2+
3+
import { world, BlockLocation } from "mojang-minecraft";
4+
5+
function getHighestBlock(x, z, dimension) {
6+
let highest = null;
7+
for (let i = 0; i < 260; ++i) {
8+
const block = world
9+
.getDimension(dimension ?? "overworld")
10+
.getBlock(new BlockLocation(x, i, z));
11+
if (!block.isEmpty) {
12+
highest = i;
13+
}
14+
}
15+
return highest;
16+
}

miscellaneous/illegalBlocks.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// By Aex66
2+
3+
import { world, MinecraftBlockTypes, BlockLocation } from "mojang-minecraft";
4+
5+
world.events.blockPlace.subscribe((ev) => {
6+
const { block, player, dimension } = ev;
7+
const { x, y, z } = block.location;
8+
9+
let ilegalBlocks = [
10+
"minecraft:movingBlock",
11+
"minecraft:movingblock",
12+
"minecraft:glowingobsidian",
13+
"minecraft:glowingObsidian",
14+
"minecraft:reserved6",
15+
"minecraft:reserved2",
16+
"minecraft:reserved3",
17+
"minecraft:info_update",
18+
"minecraft:info_update2",
19+
];
20+
21+
if (ilegalBlocks.includes(block.id)) {
22+
dimension.runCommand(
23+
`say §cAlert! §7${player.nameTag} §cplaced ilegalBlock: §e${block?.id} in §c${x} ${y} ${z} §acoordinates`
24+
);
25+
dimension
26+
.getBlock(new BlockLocation(x, y, z))
27+
.setType(MinecraftBlockTypes.air);
28+
}
29+
});

miscellaneous/itemDetect.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// By WavePlayz
2+
3+
import { world } from "mojang-minecraft";
4+
5+
world.events.tick.subscribe(() => {
6+
for (let player of world.getPlayers()) {
7+
let con = player.getComponent("inventory").container;
8+
let items = [];
9+
for (let i = 0; i < con.size; i++) items.push(con.getItem(i.id));
10+
11+
items.includes("minecraft:stick");
12+
}
13+
});

miscellaneous/playerDimension.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// JaylyDev
2+
3+
import { world } from "mojang-minecraft";
4+
5+
world.events.beforeChat.subscribe((eventData) => {
6+
let { message } = eventData;
7+
8+
if (message == "!list") {
9+
for (let player of world.getPlayers()) {
10+
player.runCommand(`say ${player.dimension.id}`);
11+
12+
// returns "[Player] minecraft:overworld"
13+
}
14+
}
15+
});

miscellaneous/playerScore.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// mrpatches123
2+
3+
import { world } from "mojang-minecraft";
4+
5+
world.events.beforeChat.subscribe((eventData) => {
6+
const { sender, message } = eventData;
7+
8+
if (message == "score")
9+
sender.runCommand(
10+
"say " +
11+
Number(
12+
sender
13+
.runCommand(`scoreboard players test @s Bool *`)
14+
.statusMessage.match(/-?\d+/)
15+
)
16+
);
17+
});

mojang-minecraft-ui/classes/ActionFormData.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ world.events.beforeItemUse.subscribe((eventData) => {
100100
});
101101
});
102102
```
103+
104+
### MinecraftClassesUI.js
105+
106+
by Discord user `Aex66#0202`
107+
108+
https://cdn.discordapp.com/attachments/854033525546942464/940447564598214667/MinecraftClassesUI.js

mojang-minecraft-ui/classes/MessageFormData.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,9 @@ world.events.beforeItemUse.subscribe((eventData) => {
9999
});
100100
});
101101
```
102+
103+
### MinecraftClassesUI.js
104+
105+
by Discord user `Aex66#0202`
106+
107+
https://cdn.discordapp.com/attachments/854033525546942464/940447564598214667/MinecraftClassesUI.js

mojang-minecraft-ui/classes/ModalFormData.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,9 @@ world.events.beforeItemUse.subscribe((eventData) => {
161161
});
162162
});
163163
```
164+
165+
### MinecraftClassesUI.js
166+
167+
by Discord user `Aex66#0202`
168+
169+
https://cdn.discordapp.com/attachments/854033525546942464/940447564598214667/MinecraftClassesUI.js
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Enchantments
2+
3+
Description:
4+
5+
- Enchantment: https://docs.microsoft.com/en-us/minecraft/creator/scriptapi/mojang-minecraft/Enchantment
6+
- EnchantmentList: https://docs.microsoft.com/en-us/minecraft/creator/scriptapi/mojang-minecraft/EnchantmentList
7+
- EnchantmentSlot: https://docs.microsoft.com/en-us/minecraft/creator/scriptapi/mojang-minecraft/EnchantmentSlot
8+
- EnchantmentType: https://docs.microsoft.com/en-us/minecraft/creator/scriptapi/mojang-minecraft/EnchantmentType
9+
10+
Versions available: 1.18.20+
11+
12+
## Code structure
13+
14+
### Class Enchantments
15+
16+
```ts
17+
/**
18+
* This class represents a specific leveled enchantment that is
19+
* applied to an item.
20+
*/
21+
export class Enchantment {
22+
"level": number;
23+
24+
readonly "type": EnchantmentType;
25+
26+
constructor(enchantmentType: EnchantmentType, level?: number);
27+
}
28+
```
29+
30+
### Class EnchantmentList
31+
32+
```ts
33+
/**
34+
* This class represents a collection of enchantments that can
35+
* be applied to an item.
36+
*/
37+
export class EnchantmentList implements Iterable<Enchantment> {
38+
readonly "slot": number;
39+
40+
[Symbol.iterator](): Iterator<Enchantment>;
41+
42+
addEnchantment(enchantment: Enchantment): boolean;
43+
44+
canAddEnchantment(enchantment: Enchantment): boolean;
45+
46+
constructor(enchantmentSlot: number);
47+
48+
getEnchantment(enchantmentType: EnchantmentType): Enchantment;
49+
50+
hasEnchantment(enchantmentType: EnchantmentType): number;
51+
52+
next(): IteratorResult<Enchantment>;
53+
54+
removeEnchantment(enchantmentType: EnchantmentType): void;
55+
}
56+
```
57+
58+
### EnchantmentSlot
59+
60+
```ts
61+
/**
62+
* This enum represents the item slot or type that an
63+
* enchantment can be applied to.
64+
*/
65+
// tslint:disable-next-line:no-unnecessary-class
66+
export class EnchantmentSlot {
67+
static readonly "all" = -1;
68+
static readonly "armorFeet" = 4;
69+
static readonly "armorHead" = 1;
70+
static readonly "armorLegs" = 8;
71+
static readonly "armorTorso" = 2;
72+
static readonly "axe" = 512;
73+
static readonly "bow" = 32;
74+
static readonly "carrotStick" = 8192;
75+
static readonly "cosmeticHead" = 262144;
76+
static readonly "crossbow" = 65536;
77+
static readonly "elytra" = 16384;
78+
static readonly "fishingRod" = 4096;
79+
static readonly "flintsteel" = 256;
80+
static readonly "gArmor" = 15;
81+
static readonly "gDigging" = 3648;
82+
static readonly "gTool" = 131520;
83+
static readonly "hoe" = 64;
84+
static readonly "none" = 0;
85+
static readonly "pickaxe" = 1024;
86+
static readonly "shears" = 128;
87+
static readonly "shield" = 131072;
88+
static readonly "shovel" = 2048;
89+
static readonly "spear" = 32768;
90+
static readonly "sword" = 16;
91+
}
92+
```
93+
94+
### EnchantmentType
95+
96+
```ts
97+
/**
98+
* Contains information on a type of enchantment.
99+
*/
100+
export class EnchantmentType {
101+
readonly "id": string;
102+
103+
readonly "maxLevel": number;
104+
}
105+
```
106+
107+
> Credit: [@types/mojang-minecraft/index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mojang-minecraft/index.d.ts);
108+
109+
## Code examples:
110+
111+
### Anti-32k.js
112+
113+
Created by Discord user [`Tendou`](https://www.tendou.xyz/)
114+
115+
```js
116+
import { world } from "mojang-minecraft";
117+
118+
function anti32K(player) {
119+
for (let x = 1; x <= 8; x++) {
120+
const inv = player.getComponent("inventory");
121+
const invc = inv.container;
122+
const invslot = invc.getItem(x);
123+
const item = invslot.getComponent("enchants");
124+
var enchs = [
125+
"aqua_affinity",
126+
"bane_of_arthropods",
127+
"blast_protection",
128+
"binding",
129+
"vanishing",
130+
"depth_strider",
131+
"efficiency",
132+
"feather_falling",
133+
"fire_aspect",
134+
"fire_protection",
135+
"flame",
136+
"fortune",
137+
"frost_walker",
138+
"impaling",
139+
"infinity",
140+
"knockback",
141+
"loyalty",
142+
"luck_of_the_sea",
143+
"lure",
144+
"mending",
145+
"multishot",
146+
"piercing",
147+
"power",
148+
"projectile_protection",
149+
"protection",
150+
"punch",
151+
"quick_charge",
152+
"respiration",
153+
"riptide",
154+
"sharpness",
155+
"silk_touch",
156+
"smite",
157+
"soul_speed",
158+
"thorns",
159+
"unbreaking",
160+
];
161+
for (let i = 0; enchs.length > i; i++) {
162+
if (item.enchantments.hasEnchantment(enchs[i])) {
163+
const ieg = item.enchantments.getEnchantment(enchs[i]);
164+
if (ieg.level >= 6) {
165+
player.runCommand(`tag @s add banned`);
166+
player.runComamnd(`clear @s`);
167+
} else console.log("not 32k");
168+
} else console.log("not ench");
169+
}
170+
}
171+
}
172+
173+
world.events.tick.subscribe(() => {
174+
// loop every tick
175+
for (let player of world.getPlayers()) {
176+
anti32K(player);
177+
}
178+
});
179+
```

0 commit comments

Comments
 (0)