Exemplo n.º 1
0
    // Block Placing mechanic
    private bool PlaceBlock(ushort blockCode)
    {
        // Won't happen if not raycasting something or if block is in player's body or head
        if (!current.active || (CastCoord.Eq(lastCoord, playerHead) && loader.blockBook.CheckSolid(blockCode)) || (CastCoord.Eq(lastCoord, playerBody) && loader.blockBook.CheckSolid(blockCode)))
        {
            return(false);
        }

        NetMessage message = new NetMessage(NetCode.DIRECTBLOCKUPDATE);

        message.DirectBlockUpdate(BUDCode.PLACE, lastCoord.GetChunkPos(), lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, blockCode, ushort.MaxValue, ushort.MaxValue);
        this.loader.client.Send(message.GetMessage(), message.size);
        return(true);
    }
Exemplo n.º 2
0
    /*
     * Function to gather the view area containing blocks and states that the mob will have the knowledge of
     */
    public byte RefreshView(CastCoord coord)
    {
        if (this.viewFieldBlocks == null)
        {
            return(0);
        }

        if (coord.Equals(null))
        {
            this.REFRESH_VISION = false;
            this.cl.GetField(coord, viewDistance, ref viewFieldBlocks, ref viewFieldStates);
            return(1);
        }

        if (!CastCoord.Eq(this.coord, coord) || this.REFRESH_VISION)
        {
            this.REFRESH_VISION = false;
            this.cl.GetField(coord, viewDistance, ref viewFieldBlocks, ref viewFieldStates);
            this.coord = coord;
            return(2);
        }

        return(0);
    }
    // Block Placing mechanic
    private void PlaceBlock(ushort blockCode)
    {
        int translatedBlockCode;

        // Encodes for Block Mode
        if (blockCode <= ushort.MaxValue / 2)
        {
            translatedBlockCode = blockCode;

            // Won't happen if not raycasting something or if block is in player's body or head
            if (!current.active || (CastCoord.Eq(lastCoord, playerHead) && loader.blockBook.CheckSolid(blockCode)) || (CastCoord.Eq(lastCoord, playerBody) && loader.blockBook.CheckSolid(blockCode)))
            {
                return;
            }
        }
        // Encodes for Asset Mode
        else
        {
            translatedBlockCode = ushort.MaxValue - blockCode;

            // Won't happen if not raycasting something or if block is in player's body or head
            if (!current.active || (CastCoord.Eq(lastCoord, playerHead) && loader.blockBook.CheckSolid(blockCode)) || (CastCoord.Eq(lastCoord, playerBody) && loader.blockBook.CheckSolid(blockCode)))
            {
                return;
            }
        }

        ChunkPos toUpdate = new ChunkPos(lastCoord.chunkX, lastCoord.chunkZ);

        // Checks if specific block has specific placement rules that may hinder the placement
        if (blockCode <= ushort.MaxValue / 2)
        {
            if (!loader.blockBook.blocks[translatedBlockCode].PlacementRule(toUpdate, lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, loader))
            {
                return;
            }
        }
        else
        {
            if (!loader.blockBook.objects[translatedBlockCode].PlacementRule(toUpdate, lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, loader))
            {
                return;
            }
        }

        // If doesn't have special place handling
        if (!loader.blockBook.CheckCustomPlace(blockCode))
        {
            // Actually places block/asset into terrain
            loader.chunks[toUpdate].data.SetCell(lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, blockCode);
            loader.budscheduler.ScheduleReload(toUpdate, 0);
            EmitBlockUpdate("change", lastCoord.GetWorldX(), lastCoord.GetWorldY(), lastCoord.GetWorldZ(), 0, loader);


            // Applies OnPlace Event
            if (blockCode <= ushort.MaxValue / 2)
            {
                loader.blockBook.blocks[translatedBlockCode].OnPlace(toUpdate, lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, loader);
            }
            else
            {
                loader.blockBook.objects[translatedBlockCode].OnPlace(toUpdate, lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, loader);
            }
        }

        // If has special handling
        else
        {
            // Actually places block/asset into terrain
            loader.chunks[toUpdate].data.SetCell(lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, blockCode);

            if (blockCode <= ushort.MaxValue / 2)
            {
                loader.blockBook.blocks[blockCode].OnPlace(toUpdate, lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, loader);
            }
            else
            {
                loader.blockBook.objects[translatedBlockCode].OnPlace(toUpdate, lastCoord.blockX, lastCoord.blockY, lastCoord.blockZ, facing, loader);
            }
        }
    }