Exemple #1
0
    public override void OnDestroyBlock(Vector3Int globalPos, byte blockData)
    {
        bool isUpper = (blockData & 0b1000) > 0;

        if (isUpper)
        {
            NBTHelper.SetBlockByteNoUpdate(globalPos - Vector3Int.up, 0);
        }
        else
        {
            NBTHelper.SetBlockByteNoUpdate(globalPos + Vector3Int.up, 0);
        }
    }
    void BreakBlock(Vector3Int pos)
    {
        if (Time.time - lastBreakTime < 0.1f)
        {
            return;
        }
        lastBreakTime = Time.time;

        breakingTime = 0;

        HideBreakingEffect();
        //DeleteBlockReq(WireFrameHelper.pos);

        NBTBlock generator = WireFrameHelper.generator;

        if (generator.hasDropItem)
        {
            try
            {
                string id   = generator.GetDropItemByData(WireFrameHelper.data);
                byte   data = generator.GetDropItemData(WireFrameHelper.data);
                Item.CreateBlockDropItem(id, data, pos);
            }
            catch (System.Exception e)
            {
                Debug.LogError("create item error, id=" + generator.GetDropItemByData(WireFrameHelper.data) + ",generator=" + generator);
            }
        }
        generator.OnDestroyBlock(WireFrameHelper.pos, WireFrameHelper.data);

        if (generator.isTileEntity)
        {
            NBTChunk chunk = NBTHelper.GetChunk(WireFrameHelper.pos);
            chunk.RemoveTileEntity(WireFrameHelper.pos);
            NBTHelper.SetBlockByteNoUpdate(WireFrameHelper.pos, 0);
        }
        else
        {
            NBTHelper.SetBlockByte(WireFrameHelper.pos, 0);
        }


        //Item.CreateBlockDropItem(type, WireFrameHelper.pos);
        BreakBlockEffect.Create(WireFrameHelper.type, WireFrameHelper.data, WireFrameHelper.pos);
        SoundManager.PlayBreakSound(WireFrameHelper.type, instance.gameObject);
    }