示例#1
0
 public static void ShowBlock(NBTObject generator, short data)
 {
     instance.handMeshRenderer.enabled   = false;
     instance.blockMeshFilter.sharedMesh = generator.GetItemMesh(NBTHelper.GetChunk(GetCurrentBlock()), (byte)data);
     instance.blockMeshRenderer.GetComponent <MeshRenderer>().sharedMaterial = generator.GetItemMaterial((byte)data);
     instance.blockMeshFilter.transform.gameObject.SetActive(true);
 }
示例#2
0
    public override void OnRightClick()
    {
        bool isUpper = (WireFrameHelper.data & 0b1000) > 0;

        int  direction = 0;
        bool isOpen    = false;

        if (isUpper)
        {
            NBTHelper.GetBlockData(WireFrameHelper.pos.x, WireFrameHelper.pos.y - 1, WireFrameHelper.pos.z, out byte belowType, out byte belowData);
            if (belowType == 64)
            {
                isOpen    = (belowData & 0b0100) > 0;
                direction = belowData & 0b0011;
            }

            byte newData = (byte)(belowData ^ 0b0100);
            NBTHelper.SetBlockData(WireFrameHelper.pos + Vector3Int.down, WireFrameHelper.type, newData);
        }
        else
        {
            isOpen = (WireFrameHelper.data & 0b0100) > 0;

            byte newData = (byte)(WireFrameHelper.data ^ 0b0100);
            NBTHelper.SetBlockData(WireFrameHelper.pos, WireFrameHelper.type, newData);
        }
        SoundManager.Play2DSound(isOpen ? "Player_Door_Close" : "Player_Door_Open");

        NBTChunk chunk = NBTHelper.GetChunk(WireFrameHelper.pos);

        chunk.RebuildMesh(UpdateFlags.Collidable);
    }
示例#3
0
    public void GetLightsByte(int xInChunk, int yInChunk, int zInChunk, out byte skyLight, out byte blockLight, bool extends = false)
    {
        skyLight   = 15;
        blockLight = 0;
        if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15)
        {
            if (extends)
            {
                int xOffset = 0;
                int zOffset = 0;

                if (xInChunk < 0)
                {
                    xOffset = -1;
                }
                else if (xInChunk > 15)
                {
                    xOffset = 1;
                }

                if (zInChunk < 0)
                {
                    zOffset = -1;
                }
                else if (zInChunk > 15)
                {
                    zOffset = 1;
                }

                NBTChunk chunk = NBTHelper.GetChunk(x + xOffset, z + zOffset);
                if (chunk != null)
                {
                    chunk.GetLightsByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16, out skyLight, out blockLight);
                }
            }
            return;
        }

        int sectionIndex = yInChunk / 16;

        if (sectionIndex >= Sections.Count || yInChunk < 0 || yInChunk > 255)
        {
            return;
        }

        int yInSection = yInChunk % 16;
        int blockPos   = yInSection * 16 * 16 + zInChunk * 16 + xInChunk;

        TagNodeCompound  Section  = Sections[sectionIndex] as TagNodeCompound;
        TagNodeByteArray SkyLight = Section["SkyLight"] as TagNodeByteArray;

        skyLight = NBTHelper.GetNibble(SkyLight.Data, blockPos);
        TagNodeByteArray BlockLight = Section["BlockLight"] as TagNodeByteArray;

        blockLight = NBTHelper.GetNibble(BlockLight.Data, blockPos);
    }
示例#4
0
 public static void ShowBlock(NBTObject generator, short data)
 {
     instance.handMeshRenderer.enabled = false;
     try
     {
         instance.blockMeshFilter.sharedMesh = generator.GetItemMesh(NBTHelper.GetChunk(GetCurrentBlock()), Vector3Int.RoundToInt(instance.position), (byte)data);
     }
     catch (System.Exception e)
     {
         Debug.LogError("showblock error, generator=" + generator + ",message=\n" + e.Message);
     }
     instance.blockMeshRenderer.GetComponent <MeshRenderer>().sharedMaterial = generator.GetItemMaterial((byte)data);
     instance.blockMeshFilter.transform.gameObject.SetActive(true);
 }
示例#5
0
    protected void InitData()
    {
        NBTChunk chunk = NBTHelper.GetChunk(pos);

        if (chunk != null && chunk.tileEntityDict.ContainsKey(pos))
        {
            Items = (TagNodeList)chunk.tileEntityDict[pos]["Items"];
            foreach (TagNodeCompound item in Items)
            {
                byte slot = item["Slot"] as TagNodeByte;
                InventorySystem.items[slot + 46].id     = item["id"] as TagNodeString;
                InventorySystem.items[slot + 46].damage = item["Damage"] as TagNodeShort;
                InventorySystem.items[slot + 46].count  = item["Count"] as TagNodeByte;
            }
        }
    }
示例#6
0
    // Start is called before the first frame update
    void Start()
    {
        shadowTrans = transform.Find("shadow");
        shadow      = shadowTrans.GetComponent <Renderer>().material;

        meshTrans = transform.Find("mesh_parent/mesh");
        MeshFilter meshFilter = meshTrans.GetComponent <MeshFilter>();

        Vector3Int pos = Vector3Int.RoundToInt(transform.position);

        meshFilter.sharedMesh           = generator.GetItemMesh(NBTHelper.GetChunk(PlayerController.GetCurrentBlock()), pos, blockData);
        meshFilter.transform.localScale = generator.itemSize;

        meshTrans.GetComponent <MeshRenderer>().sharedMaterial = generator.GetItemMaterial(blockData);

        RefreshMesh();
    }
示例#7
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);
    }
示例#8
0
    // Start is called before the first frame update
    void Start()
    {
        shadowTrans = transform.Find("shadow");
        shadow      = shadowTrans.GetComponent <Renderer>().material;

        meshTrans = transform.Find("mesh_parent/mesh");
        MeshFilter meshFilter = meshTrans.GetComponent <MeshFilter>();

        meshFilter.sharedMesh = generator.GetItemMesh(NBTHelper.GetChunk(PlayerController.GetCurrentBlock()), blockData);
        if (generator is NBTBlock && !(generator is NBTPlant))
        {
            meshFilter.transform.localScale = Vector3.one / 2;
        }

        meshTrans.GetComponent <MeshRenderer>().sharedMaterial = generator.GetItemMaterial(blockData);

        RefreshMesh();
    }
示例#9
0
    public static void Create(byte type, byte data, Vector3 pos)
    {
        GameObject prefab = Resources.Load("Prefabs/BreakBlockEffect") as GameObject;
        GameObject go     = Instantiate(prefab);

        go.transform.localPosition = pos;
        Destroy(go, 1);

        int      chunkX = Mathf.FloorToInt(pos.x / 16f);
        int      chunkZ = Mathf.FloorToInt(pos.z / 16f);
        NBTChunk chunk  = NBTHelper.GetChunk(chunkX, chunkZ);

        BreakBlockEffect effect = go.AddComponent <BreakBlockEffect>();
        NBTBlock         block  = NBTGeneratorManager.GetMeshGenerator(type);

        effect.texturePath = block.GetBreakEffectTexture(chunk, data);
        effect.tintColor   = block.GetFrontTintColorByData(chunk, data);
    }
示例#10
0
    void CheckBorder()
    {
        NBTChunk leftChunk  = NBTHelper.GetChunk(x - 1, z);
        NBTChunk rightChunk = NBTHelper.GetChunk(x - 1, z);
        NBTChunk frontChunk = NBTHelper.GetChunk(x, z + 1);
        NBTChunk backChunk  = NBTHelper.GetChunk(x, z - 1);

        if (leftChunk == null || rightChunk == null || frontChunk == null || backChunk == null)
        {
            isBorderChunk = true;
        }
        else
        {
            if (isBorderChunk)
            {
                RebuildMeshAsync(false);
            }
            isBorderChunk = false;
        }
    }
示例#11
0
    void InitData()
    {
        NBTChunk chunk = NBTHelper.GetChunk(pos);

        if (chunk != null && chunk.tileEntityDict.ContainsKey(pos))
        {
            TagNodeCompound furnace = chunk.tileEntityDict[pos];

            burnTime      = (TagNodeShort)furnace["BurnTime"];
            cookTime      = (TagNodeShort)furnace["CookTime"];
            cookTimeTotal = (TagNodeShort)furnace["CookTimeTotal"];

            TagNodeList Items = (TagNodeList)furnace["Items"];
            foreach (TagNodeCompound item in Items)
            {
                int  index = -1;
                byte slot  = (TagNodeByte)item["Slot"];
                switch (slot)
                {
                case 0:
                    index = oreIndex;
                    break;

                case 1:
                    index = fuelIndex;
                    break;

                case 2:
                    index = resultIndex;
                    break;
                }
                if (index != -1)
                {
                    InventorySystem.items[index].id     = item["id"] as TagNodeString;
                    InventorySystem.items[index].damage = item["Damage"] as TagNodeShort;
                    InventorySystem.items[index].count  = item["Count"] as TagNodeByte;
                }
            }
        }
    }
示例#12
0
    void CheckNearbyChunks()
    {
        NBTChunk leftChunk  = NBTHelper.GetChunk(x - 1, z);
        NBTChunk rightChunk = NBTHelper.GetChunk(x - 1, z);
        NBTChunk frontChunk = NBTHelper.GetChunk(x, z + 1);
        NBTChunk backChunk  = NBTHelper.GetChunk(x, z - 1);

        if (leftChunk != null)
        {
            leftChunk.CheckBorder();
        }
        if (rightChunk != null)
        {
            rightChunk.CheckBorder();
        }
        if (frontChunk != null)
        {
            frontChunk.CheckBorder();
        }
        if (backChunk != null)
        {
            backChunk.CheckBorder();
        }
    }
示例#13
0
    void UpdateBreakingEffect(NBTBlock generator, Vector3Int pos, int stage)
    {
        if (breakingEffect == null)
        {
            GameObject prefab = Resources.Load <GameObject>("Prefabs/BreakingEffect");
            GameObject go     = Instantiate(prefab);
            breakingEffect     = go.GetComponent <MeshRenderer>();
            breakingEffectMesh = go.GetComponent <MeshFilter>();
            go.SetActive(false);
        }

        if (stage == 0)
        {
            breakingEffect.gameObject.SetActive(false);
        }
        else
        {
            breakingEffect.gameObject.SetActive(true);
            breakingEffect.transform.position = pos;
            breakingEffectMesh.sharedMesh     = generator.GetBreakingEffectMesh(NBTHelper.GetChunk(GetCurrentChunkPos()), pos, WireFrameHelper.data);

            breakingEffect.material.mainTexture = Resources.Load <Texture2D>("GUI/block/destroy_stage_" + (stage - 1));
        }
    }
示例#14
0
    public byte GetLightByte(int xInChunk, int yInChunk, int zInChunk, bool extends = false)
    {
        if (xInChunk < 0 || xInChunk > 15 || zInChunk < 0 || zInChunk > 15)
        {
            if (extends)
            {
                int xOffset = 0;
                int zOffset = 0;

                if (xInChunk < 0)
                {
                    xOffset = -1;
                }
                else if (xInChunk > 15)
                {
                    xOffset = 1;
                }

                if (zInChunk < 0)
                {
                    zOffset = -1;
                }
                else if (zInChunk > 15)
                {
                    zOffset = 1;
                }

                NBTChunk chunk = NBTHelper.GetChunk(x + xOffset, z + zOffset);
                if (chunk != null)
                {
                    return(chunk.GetLightByte(xInChunk - xOffset * 16, yInChunk, zInChunk - zOffset * 16));
                }
                else
                {
                    return(15);
                }
            }
            else
            {
                return(15);
            }
        }

        int sectionIndex = yInChunk / 16;

        if (sectionIndex >= Sections.Count || yInChunk < 0 || yInChunk > 255)
        {
            return(15);
        }

        int yInSection = yInChunk % 16;
        int blockPos   = yInSection * 16 * 16 + zInChunk * 16 + xInChunk;

        TagNodeCompound  Section    = Sections[sectionIndex] as TagNodeCompound;
        TagNodeByteArray SkyLight   = Section["SkyLight"] as TagNodeByteArray;
        byte             skyLight   = NBTHelper.GetNibble(SkyLight.Data, blockPos);
        TagNodeByteArray BlockLight = Section["BlockLight"] as TagNodeByteArray;
        byte             blockLight = NBTHelper.GetNibble(BlockLight.Data, blockPos);

        //Debug.Log("y=" + x + "," + z + ",section=" + sectionIndex);

        return(skyLight > blockLight ? skyLight : blockLight);
    }