Skip to content

[Bug]: onPistonTryPush 活塞推不动的方块数量越多时导致服务器tps越低 #313

@zmsgsb

Description

@zmsgsb

Describe the bug

  1. onPistonTryPush 活塞推不动的方块数量越多时导致服务器tps越低
  2. onPistonPush 在未推动任何方块时无法触发(这个修不修都行,主要时第一条)

To Reproduce

// 墓碑防推
mc.listen("onPistonTryPush", (pistonPos, block) => {
    let obj = JSON.parse(playerTombstoneData.read());
    if (block != null && block.type === "minecraft:chest" && block.hasContainer() && block.hasBlockEntity()) {
        const x = block.pos.x;
        const y = block.pos.y;
        const z = block.pos.z;
        const dimid = block.pos.dimid;

        // 遍历对象中的每一个key
        for (let key of Object.keys(obj)) {
            // 获取当前key对应的tombstonePos数组
            let tombstoneArray = obj[key];

            // 遍历tombstonePos数组
            for (let tombstone of tombstoneArray) {
                // 获取当前tombstonePos的位置信息
                let tombstonePos = tombstone.tombstonePos;

                // 检查位置信息是否匹配
                if (tombstonePos.X === x && tombstonePos.Y - 1 === y && tombstonePos.Z === z && tombstonePos.Dimid === dimid) {
                    // 如果找到匹配的位置,返回false阻止活塞推动
                    //return false; // 直接拦截会卡服:https://github.com/LiteLDev/LegacyScriptEngine/issues/313
                    //block.destroy(true);
                }
            }
        }
    }
});

在代码中,在满足条件时无论是仅 return false 还是 仅 block.destroy(true) 还是 什么都不做,都会导致卡服
已知 let obj = JSON.parse(playerTombstoneData.read()); 获取的是一份墓碑箱json数据,其内容量有点庞大(145kb,52份玩家墓碑箱数据)

Expected behavior

onPistonTryPush 拦截时不会卡服(不会降低服务器tps)

Screenshots

1

Platform

win10

BDS Version

1.21.93

LeviLamina Version

1.4.1

LegacyScriptEngine Version

0.13.1

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions