コード例 #1
0
        public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
        {        //收集掉落物
            ++ll; if (ll >= 2)
            {
                ll = 0; return;
            }
            int value  = subsystemTerrain.Terrain.GetCellValueFast(cellFace.Point.X, cellFace.Point.Y, cellFace.Point.Z);
            int level  = ILibrary.getItemId(value);
            int maxcnt = (int)Math.Pow((double)2, (double)level) * 128;        //计算最大容量

            if (Terrain.ExtractContents(value) == HandledBlocks[0])
            {
                try {
                    ComponentBlockEntity componentBlockEntity = subsystemBlockEntities.GetBlockEntity(cellFace.X, cellFace.Y, cellFace.Z);
                    if (componentBlockEntity == null)
                    {
                        toast("没有找到Blockentity"); return;
                    }
                    ComponentSingleChest singleChestData = componentBlockEntity.Entity.FindComponent <ComponentSingleChest>(true);
                    if (singleChestData == null)
                    {
                        toast("没有找到componentchest"); return;
                    }
                    if (worldItem.ToRemove)
                    {
                        return;
                    }
                    Pickable pickable = worldItem as Pickable;
                    int      num      = pickable?.Count ?? 1;
                    int      num2     = saveInventory(singleChestData, worldItem.Value, num, maxcnt);
                    if (num2 < num)
                    {
                        subsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, autoDelay: true);
                    }
                    if (num2 <= 0)
                    {
                        worldItem.ToRemove = true;
                    }
                    else if (pickable != null)
                    {
                        pickable.Count = num2;
                    }
                }
                catch (Exception e) {
                    toast(e.ToString());
                }
            }
        }