@zardoy/flying-squid 0.0.134 → 0.0.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -223,6 +223,9 @@ const player = function (player, serv, { version }) {
|
|
|
223
223
|
directionVector
|
|
224
224
|
}, async (data) => {
|
|
225
225
|
player.changeBlock(data.position, 0, 0);
|
|
226
|
+
// a tool loses one point per block (swords two), none for blocks that break instantly
|
|
227
|
+
if ((currentlyDugBlock.hardness ?? 1) > 0)
|
|
228
|
+
player.damageHeldItem(/sword$/.test(player.inventory.slots[36 + player.heldItemSlot]?.name ?? '') ? 2 : 1);
|
|
226
229
|
const aboveBlock = await player.world.getBlock(data.position.offset(0, 1, 0));
|
|
227
230
|
if (aboveBlock.material === 'plant') {
|
|
228
231
|
await player.setBlock(data.position.offset(0, 1, 0), 0);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.player = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tool wear: mining blocks and hitting mobs use up the durability of the tool in the hand (survival and adventure only). A tool that is used up is removed and the
|
|
6
|
+
* clients get the "item broke" status (`entity_status` 47 main hand / 48 off hand): the client plays the break sound and shows the particles.
|
|
7
|
+
* No unbreaking / mending; armour does not wear (yet).
|
|
8
|
+
*/
|
|
9
|
+
const TOOL = /(pickaxe|_axe|shovel|hoe|sword|shears|trident|fishing_rod|flint_and_steel|bow|crossbow)$/;
|
|
10
|
+
const player = function (player, serv) {
|
|
11
|
+
const mcData = serv.mcData;
|
|
12
|
+
/** wears the item in the main hand by `amount`; returns true when it broke */
|
|
13
|
+
player.damageHeldItem = (amount = 1) => {
|
|
14
|
+
if (player.gameMode === 1 || player.gameMode === 3)
|
|
15
|
+
return false;
|
|
16
|
+
const slot = 36 + player.heldItemSlot;
|
|
17
|
+
const item = player.inventory.slots[slot];
|
|
18
|
+
if (!item || !TOOL.test(item.name))
|
|
19
|
+
return false;
|
|
20
|
+
const max = item.maxDurability ?? mcData.items[item.type]?.maxDurability;
|
|
21
|
+
if (!max)
|
|
22
|
+
return false;
|
|
23
|
+
const used = (item.durabilityUsed ?? 0) + amount;
|
|
24
|
+
item.durabilityUsed = used;
|
|
25
|
+
if (used >= max) {
|
|
26
|
+
player.inventory.updateSlot(slot, null);
|
|
27
|
+
player._client.write('entity_status', { entityId: player.id, entityStatus: 47 });
|
|
28
|
+
player._writeOthersNearby('entity_status', { entityId: player.id, entityStatus: 47 });
|
|
29
|
+
player.emit('toolBroke', item);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
player.inventory.updateSlot(slot, item);
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.player = player;
|
|
@@ -22,6 +22,7 @@ module.exports = {
|
|
|
22
22
|
'daycycle': require('./daycycle'),
|
|
23
23
|
'digging': require('./digging'),
|
|
24
24
|
'dimensionCodec': require('./dimensionCodec'),
|
|
25
|
+
'durability': require('./durability'),
|
|
25
26
|
'effects': require('./effects'),
|
|
26
27
|
'endFight': require('./endFight'),
|
|
27
28
|
'entities': require('./entities'),
|
package/dist/lib/modules/pvp.js
CHANGED
|
@@ -45,6 +45,8 @@ const player = function (player, serv) {
|
|
|
45
45
|
const critical = !player.onGround && player.gameMode !== 1;
|
|
46
46
|
const damage = (0, mobs_1.weaponDamage)(player.inventory.slots[36 + player.heldItemSlot]?.name) * (critical ? 1.5 : 1);
|
|
47
47
|
player.behavior('attack', { attackedEntity, velocity, damage }, (o) => {
|
|
48
|
+
// swords lose one point per hit, other tools two
|
|
49
|
+
player.damageHeldItem(/sword$/.test(player.inventory.slots[36 + player.heldItemSlot]?.name ?? '') ? 1 : 2);
|
|
48
50
|
attackedMob.attackedBy?.(player, o.damage ?? damage);
|
|
49
51
|
serv.hurt(attackedMob, o.damage ?? damage, { source: player, from: player.position, knockback: 5 });
|
|
50
52
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ import "./lib/modules/database.d.ts"
|
|
|
19
19
|
import "./lib/modules/daycycle.d.ts"
|
|
20
20
|
import "./lib/modules/digging.d.ts"
|
|
21
21
|
import "./lib/modules/dimensionCodec.d.ts"
|
|
22
|
+
import "./lib/modules/durability.d.ts"
|
|
22
23
|
import "./lib/modules/effects.d.ts"
|
|
23
24
|
import "./lib/modules/endFight.d.ts"
|
|
24
25
|
import "./lib/modules/entities.d.ts"
|