#Reviving the player if they're holding a specific item.

1 messages · Page 1 of 1 (latest)

neon bloom
#

I'm trying to make a script that revives a player if they die if the item they're holding has the lore "phoenix core" in it. How can I do this? This is the current script I've made, it doesn't throw any errors but it doesn't work.

#
import { world } from '@minecraft/server';
import { hasLoreInHeldItem } from '../../../utils/utils.js';

world.afterEvents.entityDie.subscribe((event) => {
    if (event.damageSource.cause !== "entityAttack") return;

    const deadEntity = event.deadEntity;
    if (!deadEntity || !deadEntity.isValid()) return;

    if (!hasLoreInHeldItem(deadEntity, 'phoenix core')) return;
        const deadEntityHealth = deadEntity.getComponent('minecraft:health');

        deadEntityHealth.setCurrentValue(Math.min(20, deadEntityHealth.currentValue + 20));
        deadEntity.onScreenDisplay.setActionBar('§r[§vPhoenix Core§r]');
        
        const dimension = world.getDimension(deadEntity.dimension.id);
        const { x, y, z } = deadEntity.location;
        const offsets = [
            [0, 1.5, 0], [1, 0.5, 0], [-1, 0.5, 0],
            [0, 0.5, 1], [0, 0.5, -1],
            [0.7, 1, 0.7], [-0.7, 1, -0.7],
            [0.7, 1, -0.7], [-0.7, 1, 0.7]
        ];
        for (const [dx, dy, dz] of offsets) {
            dimension.runCommandAsync(`particle minecraft:heart_particle ${x + dx} ${y + dy} ${z + dz}`);
        }
});
light zealot
#
  • You can't revive a player.
  • Setting the dying player's health back to max would result in visual glitches.

Workaround:

  • You could try editing player.json and use the damage sensor to ignore fatal damage once.
    • It will cause incompatibility with third-party addons.
  • You could turn on the immediate-respawn gamerule, then teleport the respawned player back to the death location to mimic a revival.
    • if keepInventory is off, it'll drop the player's inventory.
    • The player technically still died.
burnt lake